Loading a Collada file with pre-defined animations

Started by dwightina, December 11, 2017, 11:54:06 AM

Previous topic - Next topic

dwightina

Hi there,

I'm working on importing a Collada file that has pre-defined animations in the DAE.  I've gotten the project to the point where I can see my 3D object, but there is no animation. I've taken a look at ProceduralAnimationSample.java, but am not entirely sure which part to add in order to make this work.  I'm new to this and am sure there is some fundamental information that I don't have, so if anyone can point in me in the right direction that'd be appreciated.

Here is what I currently have:
       

//copy the res file to storage
val uri:URI = URI("file://" + outDir.absolutePath)
        val resLocator = SimpleResourceLocator(uri) //URI("android.resource://"+ mActivity.applicationContext.packageName +"/raw/seymour_dae"))
        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, resLocator)

        try {
            val colladaImporter = ColladaImporter()
            colladaImporter.loadTextures(false)
            val colladaStorage = colladaImporter.load("test.dae")

            animatedGroup = BonesImporter.importCollada(colladaStorage, 1f, null)
            animatedGroup!!.isAutoApplyAnimation = false
        } finally {
            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_MODEL, resLocator)
        }

        for (o in animatedGroup!!) {
            o.setTexture("floor2.jpg")
            o.build()
            o.discardMeshData()
        }
       
        animatedGroup!!.addToWorld(world)

        animatedGroup!!.get(0).skeletonPose.updateTransforms()
        animatedGroup!!.applySkeletonPose()
        animatedGroup!!.applyAnimation()


        //point camera to look at the center of the animated group
        var transformedCenter : SimpleVector? = null
        for (o in animatedGroup!!) {
            o.visibility = true
            transformedCenter = o.transformedCenter
        }
        cam.lookAt(transformedCenter!!)
    }


Cheers

raft

try using ColladaSample, it displays the animations in the file and you can run them through the GUI

dwightina

#2
Perfect, thanks! I've gotten it up and running using that sample.  However, I've noticed that there are some objects that are missing from my animation.  The animation is supposed to be a man holding some coins and throwing them into the air, however the coins don't show up at all. Is there anything I should be looking out for when rendering a DAE that isn't just one solid 'object'?
Along with that, the coins also have a different texture than the man, so I will be supporting multiple textures.  How is that handled, if at all? Also sorry if this is the wrong place to ask it/if I should be looking into Ardor3D, instead. Thanks again!

raft

if there are multiple objects in the collada file, they should be listed in the collada sample like in the screenshot below. in this case there are 4 objects. if your coins is not listed, I guess it means they are not exported



the collada sample just sets the same texture to all objects. you can set different textures to different objects like with the code below. but of course you need the index of object in the group

skinnedGroup.get(index).setTexture(name);

dwightina

Thanks for the reply! I believe the coins did get exported... if I open the DAE file I see the node/geometry declarations for each one.  The animation is also appearing properly if I preview the file.

As far as the texture issue,  I guess I'm more curious about whether it's possible to get these texture files and set them programatically, instead of me finding the proper index and setting the texture.  The use case is that I will be scanning various target that will each trigger different 3d objects, so I'd prefer not to have to define these beforehand.  Is there no way to handle textures automatically, even if they are predefined in the DAE (using init_from tag)?

raft

can you see the coins in the list?

for textures, one thing you can do is parse the collada file, create a map of object name -> texture  or object index -> texture and set textures accordingly.

dwightina

Good to know! In general I've just asked the designer to make a single texture for my model and skirted the issue all together. I haven't been able to run the sample yet as I'm not using Eclipse, but I'll take a run at it again. I did notice that it is only the unskinned meshes that do not appear in the animation.  Does that make sense? Will I need to take an extra step to display unskinned + skinned meshes together?

raft

right, Bones ignores unskinned meshes in Collada files. this is by design as it's an animation library not a scene loader. you can make the coins skinned too, if they are not animated this will have a slight overhead or load coins in other means jPCT provides like 3ds or obj format.

for texture, having a single texture sounds like the easiest solution.

with Eclipse it should be quite straightforward. just import the project into workspace and right click on the sample and select run as..

dwightina

Late reply, but just dropping a line to say we're gonna add skins to all meshes and stick with a single texture. Thanks for all the info :)