Support - Forum aa

« Back to Support
Beginners Area » Replacing mesh

» Replacing mesh

Posted on 11.02.2010 by Alonso, Joseba
Hi,

We are developing a 3d avatar app. I have a 3d model exported to f3d and the i have another f3d with a different hair mesh. Can i load the second hair and replace it in the model?

Thanks in advance

Joseba
|
Share this
 
Reply By Nehmad, Ariel 11.03.2010
hi joseba, 

you can use removeChild and addChild methods or parent property, for example:

myNewHair.parent = myHead;
myOldHair.parent = null;
Reply By Alonso, Joseba 11.03.2010
ok, thanks! That works, but the new hair now doesnt follow the biped animation that were in the model. Any idea why?

thanks
Reply By Nehmad, Ariel 11.03.2010
hi joseba, you should parent the hair to the head, if the head is animated, the hair should be following to the head.
Reply By Alonso, Joseba 11.22.2010
Hi,

Still stuck with this issue. And it is critical for the application im developing. Please help me. Im using the following code:

            private function completeEvent(e:Event):void
            {
                var nuevoPelo : Mesh3D = Mesh3D(pelo.getChildByName("PELO"));
                var viejoPelo : Mesh3D = Mesh3D(biped.getChildByName("PELO"));
                nuevoPelo.animation = viejoPelo.animation;
                biped.removeChild(viejoPelo);
                biped.addChild(nuevoPelo);
               
               
                Pivot3DUtils.replaceAnimations( biped, anim1 );
                scene.camera.animationEnabled = false;
                anim1.dispose();
                biped.play();
                Pivot3DUtils.traceInfo(scene);
            }

Complete source code with the f3d files are here:
http://www.refr3sh.es/temp/animation.zip

Please tell me what can i do for the new mesh follow the animation.

Thank you!!!
Reply By Nehmad, Ariel 11.22.2010
hi Joseba, 

first at all...looks great ;)

it's s little confusing, but the basic problem is with your animation file.

if you look at the ROCK_CHICO.f3d, you´ll see that the pivot "PELO" its apear in blue (because it is animated), but really does not have any movement.

so, when you replace the animacion with the "PELO" animation the result is nothing.

the second problem is that you don´t have a reference pivot to attach the hair because you head (or "CABEZA") it's also skinned...so...

i did a quick fix, but it is not the best solution.
if took the bone reference of the head ( "Bip001 Head" ) and parent the new hair to that.
i needed to rotate and translate a bit because the axis of the hair and the bone are different.

here is the result:

private function completeEvent(e:Event):void 
{
    var nuevoPelo : Mesh3D = Mesh3D(pelo.getChildByName("PELO"));
    var viejoPelo : Mesh3D = Mesh3D(biped.getChildByName("PELO"));
    //nuevoPelo.animation = viejoPelo.animation; // the hair doesn´t have animation.
    biped.removeChild(viejoPelo);
    nuevoPelo.parent = biped.getChildByName( "Bip001 Head" );
    nuevoPelo.setPosition( 15, 0, -7 );
    nuevoPelo.setRotation( 0, 0, 90 );
    nuevoPelo.setPriority( 10 ); // it may help to correct render ;)
    
    Pivot3DUtils.replaceAnimations( biped, anim1 );
    scene.camera.animationEnabled = false;
    anim1.dispose();
}
Reply By Alonso, Joseba 11.22.2010
ok thank you! that will do the trick.

But this will be a long living application, so i prefer to do the things the right way. I dont mind to rework the model or the animations. Please can you tell me how is the way to go?

I need a model that the user can customize (i.e. replace the "hair" mesh) and the user can choose from different animations so the animations must be in different files. What is the procedure to achieve this? If you can point me to the right way so i can tell to the 3D guy you will save my life!

Thanks a lot for your help
Reply By Alonso, Joseba 11.22.2010
mmm BTW seeing your MAX presentation its a bit hard to understand why we speak english if our natural language is spanish xDD

So if you want we can continue this conversation in the spanish forum (what i missed at first).
Reply By Nehmad, Ariel 11.23.2010
oh!, I know, I need to improve my terrible english jeje...but this way we can also help to other users ;)

i found another easy way using setGlobalParent() method :P
so, you don´t need to worry for the position and rotation.

private function completeEvent(e:Event):void 
{
    var nuevoPelo : Mesh3D = Mesh3D(pelo.getChildByName("PELO"));
    var viejoPelo : Mesh3D = Mesh3D(biped.getChildByName("PELO"));
    biped.removeChild(viejoPelo);
biped.gotoAndPlay(0);

    Pivot3DUtils.setGlobalParent( nuevoPelo, biped.getChildByName( "Bip001 Head" ) );    Pivot3DUtils.replaceAnimations( biped, anim1 );        scene.camera.animationEnabled = false;    anim1.dispose();}
in the future, you can use the "Spanish forum" XD



Reply By Alonso, Joseba 11.24.2010
Great!!

Muchas gracias ;)
Reply By Alonso, Joseba 11.30.2010
Sorry for coming with this again, but i still have a problem. The Pivot3DUtils.setGlobalParent trick works nice the first time, but when the model is animating it doesn't put the mesh in the right place. I think because "Bip001 Head" has moved from its original position. Any idea of how to workaround this?

Thanks
12Next»Showing 10 of 15