Some M3G questions for skinned Meshes and so on.

Forum for discussion on 3D games for mobile platform and doubts related to M3G, Mascot capsule and other rendering engines.

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Thu Oct 02, 2008 9:17 am

Thx i manged this problem. I´m not sure what it solved.

I deleted some bones of my char, which were quite a lot (54 Bones before Optimizing), but i also changed my scene hierarchy in Maya with all objects are being in root before the export. And it works.


But there is another question:

I made a idle cycle and a walkcycle. Know i want to choose by keypress (UP) a forward movement with the animationclip played as loop from a specific startframe to endframe. By no keypress the animation should cycle through the idle cycle. But i has no idea how i should implement this........... I can´t find any tutorial for this......But this is one major aspect in nearly every game. Or not?
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Thu Oct 02, 2008 9:35 am

Somehow this way, but i need to get my animation Data and write it in these variables? Can you give me a hint?

Code: Select all
private void createAnimation(SkinnedMesh mesh) {
      
       // Create the keyframe sequence.
       KeyframeSequence walkCycle = new KeyframeSequence(.mesh........);
       walkCycle.setRepeatMode(KeyframeSequence.LOOP);
       walkCycle.setDuration(......);
      
       // Attach new animation track.
       AnimationTrack track
           = new AnimationTrack(walkCycle, .mesh.........);
       mesh.addAnimationTrack(track);
       track.setController(new AnimationController());
     }
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Thu Oct 02, 2008 11:02 am

In our case, we will have all the animations in a single frameset and the frame count of start frame of walk sequence and end frame will be fed to the coding, the idle sequence will be used during no keys. So use the same framesequence for all.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Thu Oct 02, 2008 11:03 am

sometimes the counter for frames in maya do not match with the output in the m3g file, in this case you have to display the frame count in the animation in J2ME and see which frame is start and end of walk sequence.

How you are getting me?
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Thu Oct 02, 2008 4:30 pm

Many thanks for your replies.

Yes this is how i want to do it. But i don´t know, how i get exactly on the animation data of my m3g file (per code) and how should i store it as a track so i could play a frame sequence ?

@the moment my code is:

Code: Select all
    try {
      // Load scene graph from M3G binary file.
      Object3D[] objects = Loader.load(M3G_FILE1);
      world = (World) objects[0];

      // Change the camera's properties to match the current device.
      Camera camera = world.getActiveCamera();
      float aspect = (float) getWidth() / (float) getHeight();
      camera.setPerspective(54, aspect, 1, 10000);

     
      // Find mesh in scene graph.
      mesh = (SkinnedMesh) world.find(USER_ID_MESH);
      world.removeChild(mesh);
      position = new Group();
      position.addChild(mesh);
      world.addChild(position);
     
    } catch (Exception e) {
      System.out.println("Error loading " + M3G_FILE1 + ".");
      e.printStackTrace();
    }

    // All tracks have the same animation controller. This code finds
    // the first one, which is used to manage the animation.
    Group parent = mesh.getSkeleton();
    while (parent.getChildCount() != 0) {
      Group bone = (Group) parent.getChild(0);
      if (bone.getAnimationTrackCount() != 0) {
        controller = bone.getAnimationTrack(0).getController();
        break;
      }
      parent = bone;
    }
  }



but this plays all the animation data in a single clip...do you get me ?
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Fri Oct 03, 2008 4:47 am

This is a simple example of how to animate a track.

Before that, keep only one track of animation. And name the animation track. I think you also have to set something while you export to m3g, am not sure what. So make sure, that you have animationsequence in the m3g viewer. Just add this line in your code.

Code: Select all
        graphics.setClip(0, 0, Store.SCREEN_WIDTH, Store.SCREEN_HEIGHT);
        Store.world.animate(animationCount);
        g3D.bindTarget(graphics);


now, world.animate will animate your track with animationCount as the index of the frame. Now you have to experiment which frame to which frame has the walk sequence and which has the idle sequence.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Sun Oct 05, 2008 6:55 pm

@loki could you please post your variable declarations of your code ?
And could you tell me, how i could handle user input ?







EDIT: OK i manged to get the user Input. This was not very difficult.

But now i has to set the position and rotation of my 3D object by this input and also to handle the animation sequences by input.

Any tips about this?







I cancelded the animation stuff at this point for later implementation.
Now to handle the user input.
I manged to get let him rotate by user. But i need some hints about the correct way. At the moment its just for test purposes:

Code: Select all
  public void createMovement() {
     int key = getKeyStates();

     // Rotiert den 3D Charakter nach links
     if ((key & LEFT_PRESSED) != 0)
     {
         System.out.println("Left pressed" + key);
         gameModel.getTransform(transform);
         gameModel.postRotate(5, 0, 1, 0);
     }
   // Rotiert den 3D Charakter nach rechts
     else if ((key & RIGHT_PRESSED) != 0) {
     //mesh.changePosition(actor.getX() + 5, mesh.getY());
        System.out.println("Right pressed" + key);
        gameModel.postRotate(-5, 0, 1, 0);
     }
    
     else if ((key & UP_PRESSED) != 0) {
    
        System.out.println("UP pressed" + key);
        gameModel.getTransform(transform);
        transform.postTranslate(0, 0, 10);
        gameModel.setTransform(transform);
      
     }
     else if ((key & DOWN_PRESSED) != 0) {
     //mesh.changePosition(mesh.getX(), mesh.getY() + 5);
        System.out.println("DOWN pressed" + key);
        gameModel.getTransform(transform);
        transform.postTranslate(0, 0, -10);
        gameModel.setTransform(transform);
     }

As you can see, i just rotate the model. But if i want to movehim in the facing direction this is not possible by this method. So i need some way to store his facing direction and also a way to move him in this direction. At the moment he is always rotateing around the origin. But i have to move its pivot with his position and rotate around this pivot not the origin. How could i achieve this?
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Mon Oct 06, 2008 12:43 am

Ok, i manged it like this way:


Code: Select all
public void createMovement() {
     
      int key = getKeyStates();
      int deltaDirection = 0;

     
      if (key == 0)
      {
          //System.out.println("Keine Taste gedrückt");
          //gameModel.animate(1);
          //Play Idle-Animation
      }

      // Rotiert den 3D Charakter nach links
      if ((key & LEFT_PRESSED) != 0)
      {
          System.out.println("Left pressed" + key);
          direction += 10;
          deltaDirection = 10;
         
      }
    // Rotiert den 3D Charakter nach rechts
      else if ((key & RIGHT_PRESSED) != 0) {
     
          System.out.println("Right pressed" + key);
          direction -= 10;
          deltaDirection = -10;
      }
     
      else if ((key & UP_PRESSED) != 0) {
     
          System.out.println("UP pressed" + key);
          gameModel.getTransform(transform);
            transform.postTranslate(0, 0, 20);
          gameModel.setTransform(transform); 
       
      }
      else if ((key & DOWN_PRESSED) != 0) {
          System.out.println("DOWN pressed" + key);
          gameModel.getTransform(transform);
            transform.postTranslate(0, 0, -20);
          gameModel.setTransform(transform);
      }
     
     
          gameModel.getTransform(transform);
        transform.postRotate(deltaDirection, 0, 1, 0);
        gameModel.setTransform(transform);
     
     
      }


There are two problems remaing:

a) The animationPlayback

I load my model and start the animation of this model by:
Code: Select all
public void run() {
    int worldTime = (int) System.currentTimeMillis();
   
    while(isRunning) {
     
      createMovement();
      [b]gameModel.animate(worldTime);
[/b]      render(graphics);
      flushGraphics();

      try {
        Thread.sleep(20);
      } catch (Exception e) {}

      worldTime = (int) System.currentTimeMillis();
    }
  }


i created an animation controller by this:
Code: Select all
   Group parent = gameModel.getSkeleton();
    while (parent.getChildCount() != 0) {
      Group bone = (Group) parent.getChild(0);
      if (bone.getAnimationTrackCount() != 0) {
        controller = bone.getAnimationTrack(0).getController();
        break;
      }
      parent = bone;
    }


Now i want to playback some specific range of the timeline by keypress. But i always plays the whole animation sequence idle + walkcycle.



b) how i could setup a targetCam, which always targets at my 3D Model.

to b) i tried something like this:
Code: Select all
Camera camera = world.getActiveCamera();
     
      float aspect = (float) getWidth() / (float) getHeight();
      camera.setPerspective(60, aspect, 1, 10000);
      world.removeChild(camera);
      camGroup = new Group();
      camGroup.addChild(camera);
      world.addChild(camGroup);
      camGroup.setAlignment(gameModel, Node.ORIGIN, world, Node.Y_AXIS);
      camGroup.scale(-1, 1, -1);


and i need to call camGroup.align(gameModel); somewhere. I tried it in my keyPress - Method. BUt the effect is very strange.
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Mon Oct 06, 2008 6:55 am

Art1977 wrote:There are two problems remaing:

a) The animationPlayback

I load my model and start the animation of this model by:
Code: Select all
gameModel.animate(worldTime);
worldTime = (int) System.currentTimeMillis();

Now i want to playback some specific range of the timeline by keypress. But i always plays the whole animation sequence idle + walkcycle.


In this case you should not use the worldTime from current time. Just use a counter int which starts from 0 and increases per frame or according to the key press. Now display the number in debug mode using System.Out.print and see this fream has what and according to that you must set the sequence for walking and idle.

Art1977 wrote:b) how i could setup a targetCam, which always targets at my 3D Model.

to b) i tried something like this:
Code: Select all
Camera camera = world.getActiveCamera();
     
      float aspect = (float) getWidth() / (float) getHeight();
      camera.setPerspective(60, aspect, 1, 10000);
      world.removeChild(camera);
      camGroup = new Group();
      camGroup.addChild(camera);
      world.addChild(camGroup);
      camGroup.setAlignment(gameModel, Node.ORIGIN, world, Node.Y_AXIS);
      camGroup.scale(-1, 1, -1);


and i need to call camGroup.align(gameModel); somewhere. I tried it in my keyPress - Method. But the effect is very strange.


Usually we dont create a cam group, but just create a simple camera object and add it directly to the world and set it as active cam. Now we calculate the position of the cam and set it based on the human position. both angle and co-ordinates. This position and anlge has to be set in the main while loop. We store the angle of the cam and human in a variable and change the variable according to the key press. Hope this helps
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Mon Oct 06, 2008 12:39 pm

Thx for your reply.

I get managed to get a working target cam by this:

Code: Select all
Camera camera = world.getActiveCamera();
      float aspect = (float) getWidth() / (float) getHeight();
      camera.setPerspective(60, aspect, 1, 10000);
      camera.setTranslation(0, 250, 200);
      world.removeChild(camera);
      camGroup = new Group();
      camGroup.setTranslation(0, 5, 100);
      camGroup.addChild(camera);
      world.addChild(camGroup);
      camGroup.setAlignment(gameModel, Node.ORIGIN, world, Node.Y_AXIS); //Targetcam
      camGroup.scale(-1, 1, -1);


calling the update of the cam by this in my run method:

Code: Select all
public void run() {
    int worldTime = (int) System.currentTimeMillis();
   
    while(isRunning) {
     
      camGroup.align(gameModel);
      createMovement();
      gameModel.animate(worldTime);
      render(graphics);
      flushGraphics();

      try {
        Thread.sleep(20);
      } catch (Exception e) {}

      worldTime = (int) System.currentTimeMillis();
    }
  }


The next step i will try to get the animation stuff worked. Here is a little screenshot of my both applications:
Image
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Tue Oct 07, 2008 5:00 am

wow, that was really impressive. And thanks for posting your progress. Meanwhile, you must remember one more thing, if you are going to present this program on a mobile phone, then you are suppose to face lot more critical problems like memory and CPU power to render the environment fast. So in that case you must try keeping very low polygons.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Some M3G questions for skinned Meshes and so on.

Postby Art1977 » Tue Oct 07, 2008 5:28 am

Thx, i know that this programm is just running on the emulator. Unfortunately i don´t have the time to model the Object new from scratch. SO i just used an optimized version of my XNA - Model. It´s about 2000 Triangles(I know a that´s a lot).

At the moment i have to write the documentation, but i will come back for some more help, if i try to implement the animation of the charakter fully....

Thx for your great help. At the moment. :-)

Greetz
Daniel
Art1977
 
Posts: 15
Joined: Tue Aug 19, 2008 5:18 pm

Re: Some M3G questions for skinned Meshes and so on.

Postby DevelopmentTeam » Tue Oct 07, 2008 10:37 am

@daniel,
Congrats for having your work done. Meanwhile, feel free to post your doubts. :) Happy coding.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Previous

Return to 3D Mobile Game (M3G)

Who is online

Users browsing this forum: No registered users and 1 guest

cron