Menu

General Question about handling Pointers

Help
2010-06-02
2013-04-25
  • Thomas Trocha

    Thomas Trocha - 2010-06-02

    Hola,

    at the moment I try to port the FacialAnimation-Demo to ogre4j. The behaviour is that I first have to load the mesh and then
    create a manual vertex-animation. Problem is, to create the vertex-anim I have to access the mesh but the load-method of MeshManager
    only returns a MeshPtr. I searched the other samples about handling Pointers and did analogous.

    Here my try:

            IMeshManager meshManager = MeshManager.getSingleton();
            mHeadMesh = new MeshPtr();
            meshManager.load(mHeadMesh,"facial.mesh", ResourceGroupManager.getDEFAULT_RESOURCE_GROUP_NAME(),Usage.HBU_STATIC_WRITE_ONLY,Usage.HBU_STATIC_WRITE_ONLY,true,true);
            IMesh headMesh = new Mesh(mHeadMesh.getInstancePointer());
    
            IAnimation iAnim = headMesh.createAnimation("Manual", 1);
            System.out.println("iAnim:"+iAnim);
            System.out.println("Submeshes:"+headMesh.getNumSubMeshes());
            System.out.println("Name:"+headMesh.getName());
    

    I create a Mesh with the InstancePointer and this seems to work (or let's say it does not crash)
    . e.g. I can create an IAnimation. At least there is a ref-id. Nevertheless if I use getNumSubMeshes()
    it puts out an unrealstic number (which does not change if I change the mesh-file). Well, if I use
    getName() it crashes. For sure the StringMapping is not working as I am at the wrong memory-location
    or something like this!?

    Here a part of the error-log(I post the complete log in a reply to this Topic):

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j  org.ogre4j.Root.__createRoot__StringRStringRStringR(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J+0
    j  org.ogre4j.Root.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V+8
    j  org.ogre4j.demos.swt.exampleapp.ExampleApplication.setup()Z+13
    j  org.ogre4j.demos.swt.exampleapp.ExampleApplication.go()V+1
    j  org.ogre4j.demos.swt.EmptyScene.main([Ljava/lang/String;)V+9
    v  ~StubRoutines::call_stub
    

    My question is how I access Instances for that I only have a pointer
    and MeshPtr in particular.

    cu, ToM

     
  • Thomas Trocha

    Thomas Trocha - 2010-06-02

    Ah, ok! I finally got it work.

    My problem was that I used IMeshPtr for _mHeadMesh _ which don't have the magical :D .get() Method. So switching
    to MeshPtr instead solved the problem for me. Now everything works as it should be.

     
  • Christoph Nenning

    MeshPtr is in fact a C++ Ogre::SharedPtr<Mesh>. Mapping these to Java is not that easy.

    To map C++ multiple inheritance to Java ogre4j generates a Java Interface for each C++ class. Usually that interfaces declare all the methods of their correspondig C++ class. But ogre4j does not do this for templates because it causes problems when type parameters are used as parameters or return types of methods.

    So what you did is just right. Cast IMeshPtr to MeshPtr and use it's get() method.

     

Log in to post a comment.