MD2 Mesh not accepting texture

Software: Away3D 4.x

Kevin, Newbie
Posted: 08 October 2013 10:49 PM   Total Posts: 3

I’m trying to work with the MD2 that is attached.

Everything works, apart from the texture. No matter how I add a texture onto the Mesh, the model stays grey.

Would anyone with some spare time be able to check this for me and see where I am going wrong? It would be greatly appreciated.

package com
{
 import away3d
.animators.data.Skeleton;
 
import away3d.animators.SkeletonAnimationSet;
 
import away3d.animators.SkeletonAnimator;
 
import away3d.animators.transitions.CrossfadeTransition;
 
import away3d.animators.VertexAnimationSet;
 
import away3d.animators.VertexAnimator;
 
import away3d.controllers.HoverController;
 
import away3d.entities.Mesh;
 
import away3d.lights.DirectionalLight;
 
import away3d.loaders.Loader3D;
 
import away3d.loaders.misc.AssetLoaderContext;
 
import away3d.loaders.parsers.MD5AnimParser;
 
import away3d.loaders.parsers.MD5MeshParser;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.lightpickers.StaticLightPicker;
 
import away3d.materials.TextureMaterial;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.textures.BitmapTexture;
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.events.MouseEvent;
 
 
import away3d.containers.View3D;
 
import away3d.loaders.parsers.Parsers;
 
import away3d.events.AssetEvent;
 
import away3d.events.LoaderEvent;
 
import away3d.library.AssetLibrary;
 
import away3d.library.assets.AssetType;
 
import away3d.debug.AwayStats;
 
import away3d.loaders.parsers.MD2Parser;
 
import away3d.utils.Cast;
 
import away3d.tools.commands.Explode;
 
import flash.display.BlendMode;
 
import away3d.materials.methods.LightMapDiffuseMethod
 
 
/**
  * ...
  * @author Kevin McGowan
  */
 
public class Main extends Sprite 
 {
  [Embed 
(source "../../res/123.md2"mimeType "application/octet-stream")]
  
private static const __model :Class;
  
[Embed (source "../../bin/test.jpg")]
  
private static const __image  :Class;
  
  private static var 
__view  :View3D;
  
  private var 
__mesh    :Mesh;
  private var 
__animationSet  :VertexAnimationSet;
  private var 
__stateTransition :CrossfadeTransition = new CrossfadeTransition(0.5);
  
  private var 
__light    :DirectionalLight;
  private var 
__lightPicker  :StaticLightPicker;
  
  private var 
_cameraController :HoverController;
  private var 
_move    :Boolean false;
  private var 
_lastPanAngle  :Number;
  private var 
_lastTiltAngle  :Number;
  private var 
_lastMouseX   :Number;
  private var 
_lastMouseY   :Number;
  
  
/**
   * 
   */
  
public function Main():void {
   
if (stageinit();
   else 
addEventListener(Event.ADDED_TO_STAGEinit);
  
}
  
  
/**
   * 
   * @param e
   */
  
private function init(e:Event null):void {
   removeEventListener
(Event.ADDED_TO_STAGEinit);
   
   
__view = new View3D();
   
addChild(__view);
   
addChild(new AwayStats(__view));
   
   
_cameraController = new HoverController(__view.cameranull45201000, -90);
   
   
__light = new DirectionalLight(0, -10);
   
__lightPicker = new StaticLightPicker([__light]);
   
__view.scene.addChild(__light);
   
   
addEventListener(Event.ENTER_FRAMEFramefunc);
   
stage.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
   var 
wrkcontext:AssetLoaderContext = new AssetLoaderContext();
   
wrkcontext.mapUrl(".jpg""test.jpg");
   var 
wrkloader:Loader3D = new Loader3D();
   
   
wrkloader.addEventListener(AssetEvent.ASSET_COMPLETEonPartComplete);
   
wrkloader.loadData(new __model(), wrkcontextnull, new MD2Parser());
  
}
  
  
/**
   * 
   * @param e
   */
  
private function onPartComplete(e:AssetEvent):void {
   trace
(e.asset.assetType);
   if (
e.asset.assetType == AssetType.MESH{
    __mesh 
e.asset as Mesh;
    
__mesh.scale(7);
    
    
//__mesh.material = new ColorMaterial(0xFF0000, 1);
    
__mesh.material = new TextureMaterial(Cast.bitmapTexture(new __image()));;
    
//__mesh.material.bothSides = true;
    
__mesh.material.lightPicker __lightPicker;
    
    var 
wrkplane:PlaneGeometry = new PlaneGeometry(200200);
    var 
wrkmesh:Mesh = new Mesh(wrkplane, new TextureMaterial(Cast.bitmapTexture(new __image())));
    
__view.scene.addChild(wrkmesh);
    
    
__view.scene.addChild(__mesh);
    
    var 
wrkanimator:VertexAnimator = new VertexAnimator(__animationSet);
    
wrkanimator.play("Run");    
    
__mesh.animator wrkanimator;
   
}
   
else if (e.asset.assetType == AssetType.ANIMATION_SET{
    __animationSet 
e.asset as VertexAnimationSet;
   
}
  }
  
  
/**
   * 
   * @param event
   */
  
private function onMouseDown(e:MouseEvent):void
  {
   _lastPanAngle 
_cameraController.panAngle;
   
_lastTiltAngle _cameraController.tiltAngle;
   
_lastMouseX stage.mouseX;
   
_lastMouseY stage.mouseY;
   
_move true;
  
}
 
  
/**
   * Mouse up listener for navigation
   */
  
private function onMouseUp(e:MouseEvent):void
  {
   _move 
false;
  
}
  
  
/**
   * 
   * @param e
   */
  
private function Framefunc(e:Event):void {
   
if (_move{
    _cameraController
.panAngle 0.3*(stage.mouseX _lastMouseX) + _lastPanAngle;
    
_cameraController.tiltAngle 0.3*(stage.mouseY _lastMouseY) + _lastTiltAngle;
   
}
   
   __view
.render();
  
}
  
 }
 

 

File Attachments
123.md2  (File Size: 515KB - Downloads: 0)
   

Avatar
Fabrice Closier, Administrator
Posted: 09 October 2013 08:15 PM   Total Posts: 1265   [ # 1 ]

Can’t download it, but try load in into Prefab. if it loads and play it, yet show same problem, you always can apply the material in the app, and export as md2, or better as as3.
You can also with the vertexanimation editor eventually correct, add or remove stuff in there…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X