« Return to Thread: Max3DS parser broken? - can't get materials

Re: Max3DS parser broken? - can't get materials

by andysk8er :: Rate this Message:

Reply to Author | View in Thread

After even more investigation, I found a problem 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.

Now, I need to figure out why the ShadeMaterials didn't work.
-Andy
                               
===============================================
Check out my blog for Flash, AS3, and web development stuff:
http://www.wastedpotential.com

 « Return to Thread: Max3DS parser broken? - can't get materials