Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBJParser trims material names? #68

Open
ghost opened this issue Jun 28, 2011 · 0 comments
Open

OBJParser trims material names? #68

ghost opened this issue Jun 28, 2011 · 0 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jun 28, 2011

Hi! Noticed that mesh's material name contains only "Obj0" instead of real material name, as "coolSong".
I'm trying to get the materials names with this code:

//...
Loader3D.enableParser(OBJParser);
_loader = new Loader3D();
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete);
_loader.load(new URLRequest('model.obj'));
//...

private function onResourceComplete(ev: LoaderEvent) : void
{
    //...
    var len: uint = _loader.numChildren;
    for (var i: uint = 0; i < len; i++) 
    {
        //...
        mesh = Mesh(_loader.getChildAt(i));
        trace(mesh.material.name); // traces "Obj0", "Obj1", etc
        //...
    }
    //...
}

I debugged names resolving process a bit and figured out some strange behavior in the OBJParser:
In the away3d.loaders.parsers.OBJParser:
https://github.com/away3d/away3d-core-broomstick/blob/master/src/away3d/loaders/parsers/OBJParser.as
In the method translate(), this code:

if(groups[g].materialID != "")
{
    bmMaterial.name = groups[g].materialID+"~"+mesh.name;
}
else
{
    bmMaterial.name = _lastMtlID+"~"+mesh.name;
}

generates material names like "coolSong~Obj1".
And after it, at the applyMaterial() method:

//...
decomposeID = mesh.material.name.split("~");
//...
mesh.material.name = decomposeID[1];

Name replaced with it's second part after a "~" char and looks after it like "Obj1"

So, name after translate() is looks like: "coolSongObj1";
And after applyMaterial() it changes for "Obj1" (because used part after the "
" char - decomposeID[1]);
But in this case material name is erased at all, leaving just the mesh name I guess =(
Why not to use the decomposeID[0] instead of decomposeID[1] to leave the material name only (erasing the mesh name) or leave the whole name "coolSong~Obj1"?

@ghost ghost assigned Fabrice3D Jun 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant