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 (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
/**
*
* @param e
*/
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
__view = new View3D();
addChild(__view);
addChild(new AwayStats(__view));
_cameraController = new HoverController(__view.camera, null, 45, 20, 1000, -90);
__light = new DirectionalLight(0, -1, 0);
__lightPicker = new StaticLightPicker([__light]);
__view.scene.addChild(__light);
addEventListener(Event.ENTER_FRAME, Framefunc);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
var wrkcontext:AssetLoaderContext = new AssetLoaderContext();
wrkcontext.mapUrl(".jpg", "test.jpg");
var wrkloader:Loader3D = new Loader3D();
wrkloader.addEventListener(AssetEvent.ASSET_COMPLETE, onPartComplete);
wrkloader.loadData(new __model(), wrkcontext, null, 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(200, 200);
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();
}
}
}