Author Topic: Loading a Collada file with pre-defined animations  (Read 20535 times)

Offline dwightina

  • byte
  • *
  • Posts: 5
    • View Profile
Loading a Collada file with pre-defined animations
« on: December 11, 2017, 11:54:06 am »
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:
Code: [Select]
       

//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

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading a Collada file with pre-defined animations
« Reply #1 on: December 11, 2017, 01:12:06 pm »
try using ColladaSample, it displays the animations in the file and you can run them through the GUI

Offline dwightina

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Loading a Collada file with pre-defined animations
« Reply #2 on: December 13, 2017, 11:42:38 pm »
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!
« Last Edit: December 13, 2017, 11:52:06 pm by dwightina »

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading a Collada file with pre-defined animations
« Reply #3 on: December 14, 2017, 02:57:22 pm »
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

Code: [Select]
skinnedGroup.get(index).setTexture(name);

Offline dwightina

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Loading a Collada file with pre-defined animations
« Reply #4 on: December 14, 2017, 11:39:25 pm »
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)?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading a Collada file with pre-defined animations
« Reply #5 on: December 15, 2017, 12:55:18 am »
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.

Offline dwightina

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Loading a Collada file with pre-defined animations
« Reply #6 on: December 20, 2017, 07:35:24 pm »
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?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading a Collada file with pre-defined animations
« Reply #7 on: December 21, 2017, 07:04:20 am »
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..

Offline dwightina

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Loading a Collada file with pre-defined animations
« Reply #8 on: December 30, 2017, 02:23:32 am »
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 :)