feisishui / papervision3d

Automatically exported from code.google.com/p/papervision3d
0 stars 0 forks source link

Max3DS parser materialsList bug - WITH SOLUTION !!!!! Please update parser !!!!! #208

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load a Max3DS model without assigning a materialsList in the constructor
2. once the file is loaded, try to retrieve the materialsList or numMaterials

What is the expected output? What do you see instead?
It should return a materialsList of the wireframe materials that were
created to render the model. Instead, you get nothing and the numMaterials=0

What version of the product are you using? On what operating system?
latest SVN on Windows XP

Please provide any additional information below.
================== SOLUTION HERE: =========================
The problem is in the Max3DS parser - in the buildMesh() function:

The way it works is this: if you have sent a materialsList to the Max3DS
constructor, it looks for the material name and assigns that material to
the mesh if it is found. If the mesh material does not match up to a name
in the provided materialsList, it creates a wireframe material instead.
But... AND HERE IS THE PROBLEM... It does NOT add that wireframe material
to the Max3DS object's materialsList! 

You can fix it by replacing the following lines of code (line 120, more or
less):

var mat:MaterialData = meshData.materials[i];
var material:MaterialObject3D = this.materials.getMaterialByName(mat.name)
|| MaterialObject3D.DEFAULT;

with this:

var mat:MaterialData = meshData.materials[i];
var material:MaterialObject3D 
if (this.materials.getMaterialByName(mat.name)) {
    material = this.materials.getMaterialByName(mat.name)
}
else {
    material = MaterialObject3D.DEFAULT;
    this.materials.addMaterial(material, mat.name);
}

Then, after the file is completely loaded, you can get an accurate
materialsList from the Max3DS object (allowing you to replace the materials
by name). There is probably a more efficient way to code this, but it gets
the job done. The sweet thing is that it only adds a wireframe material to
the list if a material by that name doesn't exist yet.

Original issue reported on code.google.com by andy.wat...@gtempaccount.com on 7 Jul 2009 at 2:36

GoogleCodeExporter commented 9 years ago
Thanks Andy!

Original comment by tim.k...@gmail.com on 3 Oct 2009 at 8:08

GoogleCodeExporter commented 9 years ago
For some reason obj.materialsList() throws null reference now, but 
obj.numMaterials works just fine. I have to use obj.materials.toString() to get 
material names.

Original comment by Maksim.V...@gmail.com on 7 Sep 2010 at 11:44