md2 file problem

Software: Prefab3D

mkfui, Jr. Member
Posted: 09 September 2016 05:00 AM   Total Posts: 31

sir, i modify the Basic_LoadMD2 example with my md2 file, but it nothing, why ? what’s wrong with this code ? it show no bug in prefab3d, i just import texture, but it show nothing in swf, what’s wrong ? i try both exporter for 3ds max, md2tagExport & 3dsmax-md2-exporter-2011

package
{
//import away3d.materials.methods.FilteredShadowMapMethod;
import away3d.animators.*;
import away3d.containers.*;
import away3d.controllers.*;
import away3d.debug.*;
import away3d.entities.*;
import away3d.events.*;
import away3d.library.*;
import away3d.library.assets.*;
import away3d.lights.*;
import away3d.loaders.misc.*;
import away3d.loaders.parsers.*;
import away3d.materials.*;
import away3d.materials.lightpickers.*;
import away3d.primitives.*;
import away3d.utils.Cast;

import flash.display.*;
import flash.events.*;

[SWF(width=“320”, height=“240”, backgroundColor=“0x2f3032”, frameRate=“30”, quality=“LOW”)]
public class Basic_LoadMD2 extends Sprite
{
 
 
  [Embed(source=”/../embeds/ogre/material.jpg”)]
  public static var OgreDiffuse:Class;
 
 
  [Embed(source=”/../embeds/ogre/box5.md2”,mimeType=“application/octet-stream”)]
  public static var OgreModel:Class;
 
  //engine variables
  private var _view:View3D;
  private var _cameraController:HoverController;
   
  //scene objects
  private var _mesh:Mesh;
 
  //navigation variables
  private var _move:Boolean = false;
  private var _lastPanAngle:Number;
  private var _lastTiltAngle:Number;
  private var _lastMouseX:Number;
  private var _lastMouseY:Number;
  private var _animationSet:VertexAnimationSet;
 
  /**
  * Constructor
  */
  public function Basic_LoadMD2()
  {
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
 
  //setup the view
  _view = new View3D();
  addChild(_view);
 
  //setup controller to be used on the camera
  _cameraController = new HoverController(_view.camera, null, 45, 20, 1000, -90);
 
  //setup the url map for textures in the 3ds file
  var assetLoaderContext:AssetLoaderContext = new AssetLoaderContext();
  assetLoaderContext.mapUrlToData(“material.jpg”, new OgreDiffuse());
 
  //setup parser to be used on AssetLibrary
  AssetLibrary.loadData(new OgreModel(), assetLoaderContext, null, new MD2Parser());
  AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
 
  //add stats panel
  addChild(new AwayStats(_view));
 
  //add listeners
  addEventListener(Event.ENTER_FRAME, onEnterFrame);
  stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
  stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
  stage.addEventListener(Event.RESIZE, onResize);
  onResize();
  }
 
  /**
  * Navigation and render loop
  */
  private function onEnterFrame(event:Event):void
  {
  if (_move) {
  _cameraController.panAngle = 0.3*(stage.mouseX - _lastMouseX) + _lastPanAngle;
  _cameraController.tiltAngle = 0.3*(stage.mouseY - _lastMouseY) + _lastTiltAngle;
  }
 
  _view.render();
  }
 
  /**
  * Listener function for asset complete event on loader
  */
  private function onAssetComplete(event:AssetEvent):void
  {
  if (event.asset.assetType == AssetType.MESH) {
  _mesh = event.asset as Mesh;
 
  //adjust the ogre material
  var material:TextureMaterial = _mesh.material as TextureMaterial;
 
 
  //adjust the ogre mesh
  _mesh.y = 120;
  _mesh.scale(5);
  _view.scene.addChild(_mesh);
 
 
  } else if (event.asset.assetType == AssetType.ANIMATION_SET) {
  _animationSet = event.asset as VertexAnimationSet;
  }
  }
 
  /**
  * Mouse down listener for navigation
  */
  private function onMouseDown(event:MouseEvent):void
  {
  _lastPanAngle = _cameraController.panAngle;
  _lastTiltAngle = _cameraController.tiltAngle;
  _lastMouseX = stage.mouseX;
  _lastMouseY = stage.mouseY;
  _move = true;
  stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
  }
 
  /**
  * Mouse up listener for navigation
  */
  private function onMouseUp(event:MouseEvent):void
  {
  _move = false;
  stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
  }
 
  /**
  * Mouse stage leave listener for navigation
  */
  private function onStageMouseLeave(event:Event):void
  {
  _move = false;
  stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouse

 

File Attachments
b5.rar  (File Size: 4KB - Downloads: 0)
   

mkfui, Jr. Member
Posted: 09 September 2016 05:04 AM   Total Posts: 31   [ # 1 ]

complete code here

 

File Attachments
Basic_LoadMD2.as  (File Size: 7KB - Downloads: 268)
   

Avatar
Fabrice Closier, Administrator
Posted: 09 September 2016 09:16 AM   Total Posts: 1265   [ # 2 ]

There is a difference between loading a file that holds some animation data and actually animating this data.
The code above loads the md2, even declares an animationSet, but there is no VertexAnimator…

Look in examples, there are many vertex animation cases in there.

 

   
   
‹‹ jiglib

X

Away3D Forum

Member Login

Username

Password

Remember_me



X