Using Animated Models In Jme

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Using Animated Models In Jme as PDF for free.

More details

  • Words: 2,790
  • Pages: 11
Using Animated MD5 Models in jME 1.0 by Simon Cooper This guide will help you create an animated model in 3ds Max and load it into your jME game. It includes some basic information on texturing your objects, creating bones, skinning and keyframe animation in max and then getting the finished animated model into your jME game. I will also mention some tips for other modelling tools, but the main focus will be on 3ds Max. For an MD5 Blender Tutorial Click here You will need: - 3ds Max (I'm using version 7) or another similar 3d modelling tool, for example Blender/Maya. http://www.autodesk.co.uk/ (3ds Max/Maya) http://www.blender.org/ (open source) - MD5 exporter plug-in or script. der-ton's MD5 exporter script for 3ds Max der-ton's MD5 exporter script for Blender BeRSeRKeR's Md5 exporter script for 3ds Max hyperion-5's exporter script for Maya (more info here) Other MD5 exporters can be found here - Image Editing Software Adobe Photoshop Gimp (open source) - jME MD5 Importer MD5 Importer Google Code We will download and set this up later using the Eclipse CVS Repository View. - Your jME game setup in a suitable IDE (I'm using Eclipse) jME Homepage Eclipse Homepage Setting Up jME in Eclipse Tutorial - MD5 Model Viewer (Optional) MD5Viewer - v1.2.0 Win32 MD5Viewer - v1.2.0 Mac

- Other Useful Links MD5 File Format Wiki

Part 1 - Creating Your MD5 Model in 3DS Max 7 If you are using Blender click here for a different tutorial. For other versions of Max some steps or button layouts may be a little different.

1. First download der-ton's MD5 exporter script for 3ds Max or BeRSeRKeR's Md5 exporter script for 3ds Max. 2. Unzip the file and copy the "md5export.ms" or "MD5.MAX.Exporter.For.Skin.Modifier.mzp" file into the scripts folder of your 3ds Max installation (mine is: C:\3dsmax7\scripts). 3. Open up 3ds Max. 4. If you already have a model mesh, load it into max and follow step 5, then jump to "Part 2 - Bones and Skinning". 5. If your starting from a blank scene, create your mesh (For more help here's a free character modelling tutorial I found) making sure that when it's finished it is in the Editable Mesh format, by right clicking on the object and selecting "Convert To: > Convert To Editable Mesh". 6. When you have finished press the "M" key to open up the material editor. 7. For simple texturing set the materials diffuse colour by expanding "maps" and clicking the "None" box next to diffuse colour. Click "Bitmap" in the new window and choose your texture file. For MD5 models with transparent textures, the texture file must be in Targa (.tga) format, with no RLE Compression or .png format (which I prefer and now works with MD5 Importer). 8. For more complex textures/models dropping a texture image of checkered or numbered squares as the material's diffuse colour can help when unwrapping the mesh for texturing later on. You can download one here. 9. It can help the model loading process in jME later if you name your new material with the same name as the texture file. 10. Drag and drop the new material onto your model. 11. In the "Modify" tab on the right, click on the drop down "Modify List" tab and choose "UVW Map" to add it to the stack above your Editable Mesh. 12. Click on the new "UVW Map" modifier. 13. If your object/textures are simple you can click on the different mapping tabs (e.g. Box or

14.

15. 16. 17.

18.

19.

20. 21.

22. 23.

24. 25. 26.

27. 28.

Cylindrical) to fit the texture to the model and jump to step 27. For more complicated texturing using unwrapping, first set the length and width values in the "UVW Map" to match your intended texture size (remember to keep texture pixel sizes to a power of two e.g. 512 x 512). In the "Modify" tab on the right, click on the drop down "Modify List" tab again and choose "Unwrap UVW" to add it to the stack above your UVW Map. In the "Unwrap UVW" modifier click the big "Edit" button in the parameters section. In the new window's menu bar select "Mapping > Flatten Mapping.." then set the "Face Value Threshold" parameter to about "66" and click "OK". This should show an unfolded wire-frame of your model with the texture behind it. Arrange the wire-frame to fit neatly in the thick blue bordered square. You can use the move/scale/rotate/flip tools to help. For parts of the model that are mirrored and/or use the same texture move them so that they overlap, highlight the shared vertices and press "CTRL" and "W" to weld them together. This is where the numbers texture comes in handy to see if the different faces are aligned. When the UVW Map is unwrapped you can export it to your image editing program to create the final texture, either by using print screen on the Edit UVW window or by installing a UVW map exporter plug-in like Texporter. To use Texporter unzip it into the max plugins folder (mine is C:\3dsmax7\plugins). To install Texporter click on the top menu bar in max and choose "Customize > Plug-in Manager....". Right click in the new "Plug-in Manager" window and choose "Load New Plug-in...". Browse to the plugins folder where you unzipped Texporter and select the "Texporter.dlu" file. To run Texporter click on the "Utilities" tab that's four tabs along from the modify tab, then click on the "More.." button. Scroll down the list and select "Texporter". To export the texture UVW map set the image width and height to match the one you entered earlier, click on the "Pick Object" button and select the object you wanted to export. Click on the "save" disk icon and choose a file name and save location. To create your texture open up the new image file in Adobe Photoshop or your other image editing program. Create a new layer above the UVW image and start to fill in the sections with the appropriate colours and detail. Save your finished texture (remember if using tga it needs to be uncompressed and all format image sizes need to be a power of two square). If you want transparencies I recommend using .png format and deleting the default background layer in Photoshop so the checker-board appears, which signifies transparent areas. Replace the numbers texture with your new image as in step 7. Repeat the texturing process for each object in your scene, then make sure you collapse the modifier stack down to an Editable Mesh by right clicking a modifier and choosing

"Collapse All" or right clicking the object itself and choosing "Convert To: > Convert To Editable Mesh" again. 29. If you have multiple objects they will all need to be attached to the same mesh using the "Attach" or "Attach List" button under the "Edit Geometry "section of the "Modify" tab on the right. Make sure you check "Match Material IDs To Material" when it asks to keep your set textures. This is because the MD5 exporter can only export one object.

Part 2 - Bones and Skinning Now you have your textured mesh you need to create some bones to control it. Even if there is no animation in your object MD5 Models in jME require every point to be attached to a root bone. 1. To make things easier first we will lock the mesh and make it see-through. Right click on the object and choose "properties" from the menu. Put a tick in the "Freeze" and "See-Through" boxes. I also like to change the view to "Smooth and Highlights" with "Edged Faces" to see the model better by selecting them from the menu that appears when you right click on the view name that is on the top left of every view partition (they can say Front/Back/Left/Right/Top/Bottom/Perspective depending on which view you have set). It is also usually easier to work from the front view of your model when creating bones (depending on what it is). 2. From the top menu select "Create > Systems > Bones IK Chain". 3. Now use the mouse to draw your bones. Left click to create a new bone and drag out the size and position. Right clicking ends bone creation. Start with on main root bone in the centre and build up the rest from here. Your bones don't have to all be created in one chain as small bone sections can be linked together later. Everywhere you want the model to twist or bend needs a bone joint. 4. You will probably have to use the move and rotate tools to position the bones so they are lined up correctly with your mesh.

5. When you have created and aligned your bones you need to make sure that they are all connected together by a single bone. Click on the "Schematic View (open)" icon on the main toolbar. 6. Use the "Connect Tool" to join any stray bone groups together and close the window when you are finished (see image below to get an idea of bone structure).

7. 8. 9. 10. 11. 12. 13.

14. 15. 16.

Next we will add the bones to the mesh using the skin modifier. Select your mesh and click on the "Modify" tab again. Open the drop down "Modifier List" and select the "Skin" modifier. Click on the new "Skin" modifier and in the parameters rollout click "Add" and select/add all the bones for the mesh. The next part can be annoying, click on the first bone in the list and click the "Edit Envelopes" button. You should see an envelope gizmo that controls which vertices are affected by the current bone. Play around with the size of these so that every vertex is affected by at least one bone (usually shown by turning red or orange), depending on the complexity of your mesh and how you want it to bend/crease/deform with the bones it can take some time to get right. To see if everything is attached correctly try bending some bones and see if the mesh moves along with it. To help you can click on the "Weight Table" button in the "Skin" modifier in the weight properties section. In the weight table check that each vertex has a weight total of 1, this view can help find stray points with a dissimilar number that the others near it.

Now your mesh is fully attached to the bones and bends correctly you can start to animate.

Part 4 - Keyframe Animation To keyframe your bone movement we will focus on the time-line at the bottom of the screen. 1. Check that the head tracker slider is all the way to the left on frame zero. 2. Click on the "Auto Key" button (it should turn red for record). 3. Click on & select the bone you wish to animate. 4. Next click the big key button left of "Auto Key" to make sure it has the start frame recorded. 5. Move the slider along to a later time frame depending on how fast you want the bone to move. 6. Use the "Select and Move" tool to change the position of your bone and the new position should be recorded. 7. When you rewind and play the animation the software will calculate the in-between frames for you.

Part 5 - Exporting to MD5 Once your model is rigged and animated it is ready to export. 1. In Max's top menu bar select "MAXScript > Run Script..." then browse to your plugins folder, select "md5export.ms" that you unzipped earlier and click "open". 2. In the new window check that the start/end frames are correct if you are using animation, then select your model and click the "Export" button. Choose the location and file name of your md5mesh and md5anim files and put them in the same folder along with the textures you used earlier. 3. Open the md5mesh file using a text editor (notepad, notepad++, or the Eclipse text editor should be fine). 4. If you have not named your materials in the 3ds Max material editor it will probably say shader "01 - Default". For every sub mesh in your model with a different texture material it should have a shader section in the file. Go through and find and replace each 'shader "01 - Default" with your textures file name. Mine is:

shader "texture1.png"

where texture1.png is the name of the image file. My jME game file setup is: MyGame > src > data > model.md5mesh, model.md5anim MyGame > src > data > textures > texture1.png MyGame > src > MD5Test.java

Part 6 - Test your MD5 (optional) 1. If you downloaded the MD5 Model Viewer (MD5Viewer - v1.2.0 Win32, MD5Viewer v1.2.0 Mac), you can now test your exported model. Unzip the folder to your hard drive and double click the "MD5Viewer_v1.2.0.jar" file. It should open a browser window where you can locate and open your model ".md5mesh" file. Next if you included animation select and open your ".md5anim" file. Choose you display settings in the next window and press "OK". 2. If you have any texture images they also need to be in the same folder as your model and animation files. 3. You should now see a black window with you animated model moving inside it. 4. You can move the camera around and check the frame rate, triangle count and some other debug options using the following keys: Control:

Key:

Speed up Slow down Scale up Scale down Forward Backward Strafe left Strafe right Vertical up Vertical down Toggle lighting Toggle normals Toggle bounding Rotate camera Exit application

1 2 3 4 W S A D Q Z L N B Move Mouse Esc

If your model isn't displaying properly it could be one of these errors: • The texture is not in the right directory. • The .tga texture uses RLE compression (it needs to be uncompressed). • The texture file path in the ".md5mesh" file is not correct (see Part 5.3). • Some vertices are not linked to a bone or their weights don't add up to 1.0 (see Part 2 Bones and Skinning above). • The md5 file is corrupted (try exporting it again). • The modifiers in 3ds Max are not correct (it has to have only "Editable Mesh" and "Skin" in the modifier stack).

Part 7 - JME MD5 Importer Setup in Eclipse To get the MD5 model into your jME game first you will need an MD5 reader/importer. There are a few different teams working on them at the moment, but we will use MD5 Importer Google Code. Depending on which version of jME and Java you are using you will need either: Java 6 http://md5importer.googlecode.com/files/MD5Importer_jME1.0_v1.2.4.jar http://md5importer.googlecode.com/files/MD5Importer_jME2.0_v1.2.4.jar Java 5 http://md5importer.googlecode.com/files/MD5Importer_jME1.0_v1.2.4_Java5.jar http://md5importer.googlecode.com/files/MD5Importer_jME2.0_v1.2.4_Java5.jar If you are using Eclipse I recommend using their google code SVN to grab the whole project rather than just the Jars: For SVN, Eclipse needs a plug-in (such as Subclipse), see this tutorial to get setup: Setup Subclipse in Eclipse. Once you have an SVN Repositories View in Eclipse, right click in the view somewhere to bring up a small menu. Go to "New > Repository Location..." Enter the following Url: http://md5importer.googlecode.com/svn/trunk This should list the projects: - jME Attempt - MD5Importer jME1.0 - MD5Importer jME2.0 - MD5Viewer Right click the one that you want to checkout and choose "Checkout...". Leave the checkout settings on default and click "Finish".

Next make sure that your original jME project is on the build path of the MD5Importer project, or that the jME Jars are added to the Libraries. Right click the top level of the MD5Importer project, and select "Properties (Alt+Enter)". Select "Java Build Path" then either the "Projects" or "Libraries" tabs to add the jME project or just the jars. See the Setting Up jME in Eclipse Tutorial for help. For project - just click add and choose/tick the jME project. For Jars - Click the "Add JARs.." button in the "Libraries" tab and locate your built jars (mine are in the target folder - C:\Eclipse Workspace\jme\target). Now you can open the MD5Importer package in Eclipse and right click TestAnim.java (/MD5Importer jME1.0/test/test/model/md5/TestAnim.java), and choose "Run As > 1 Java Application (Alt + Shift + X, J)" Double click on TestAnim.java to see the source code and how to setup your model in a jME game. For textures that have transparent areas I use this alpha state over the top: // Set alpha transparency for scene model _maxAlpha = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState(); _maxAlpha.setBlendEnabled(false); _maxAlpha.setTestEnabled(true); _maxAlpha.setSrcFunction(AlphaState.SB_SRC_ALPHA); _maxAlpha.setDstFunction(AlphaState.DB_ONE); _maxAlpha.setTestFunction(AlphaState.TF_GREATER); _maxAlpha.setReference(0.5f); _maxAlpha.setEnabled(true); Then set it to the model with: //model is name of model node that you chose model.setRenderState(_maxAlpha);

Related Documents

Using Animated Models In Jme
December 2019 15
Design Using Models
November 2019 25
Reharsed Animated
August 2019 29
Animated Rocket
June 2020 10
Animated Animals
April 2020 11