Following AFTC’s code for loading an OBJ model I was able to load my own model but couldn’t get the texture on him, and subsequently got the the error: Property bitmapData not found. Tried to intertwine some code from these two posts 1 & 2, but couldn’t figure it out.
Tried uploading the project to the web with ‘View Source’ enabled but got an error, so here is all the code (figured it’s best to not omitt anything, as I’m still very green with Away3D):
package{
import away3d.core.base.SubMesh;
import away3d.entities.Mesh;
import away3d.events.AssetEvent;
import away3d.lights.DirectionalLight;
import away3d.loaders.Loader3D;
import away3d.loaders.misc.AssetLoaderContext;
import away3d.loaders.parsers.Parsers;
import away3d.materials.TextureMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.textures.BitmapTexture;
import com.darcey.debug.Ttrace;
import com.darcey.ui.FullScreenButton;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class RictorRotateTextured extends Sprite{
//Embedded assets
[Embed(source="/assets/Rictor_Textured06.obj", mimeType="application/octet-stream")]
private var RictorModel:Class;
[Embed(source="/assets/Rictor_Diffuse_map_1.jpg", mimeType="application/octet-stream")]
private var assetTexture:Class;
private var t:Ttrace;
private var away3DScene:Away3DScene;
private var fullScreenButton:FullScreenButton;
private var staticLightPicker:StaticLightPicker;
private var directionalLight:DirectionalLight;
private var rictorMaterial:TextureMaterial;
private var loader:Loader3D;
private var rictorMesh:Mesh;
public function RictorRotateTextured(){
t = new Ttrace(true);
t.ttrace("RictorRotateTextured()");
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
away3DScene = Away3DScene.getInstance();
away3DScene.init(true, true);
addChild(away3DScene);
initScene();
}
private function initScene():void{
t.ttrace("RictorRotateTextured.initScene()");
fullScreenButton = new FullScreenButton();
addChild(fullScreenButton);
initLights();
initMaterials();
init3DObjects();
stage.addEventListener(Event.RESIZE, resizeHandler);
resizeHandler();
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function initLights():void{
directionalLight = new DirectionalLight();
staticLightPicker = new StaticLightPicker([directionalLight]);
away3DScene.scene.addChild(directionalLight);
}
private function initMaterials():void{
rictorMaterial = new TextureMaterial(new BitmapTexture(new assetTexture().bitmapData));
/*var assetLoaderContext:AssetLoaderContext = new AssetLoaderContext();
assetLoaderContext.mapUrlToData("assets/Rictor_Diffuse_map_1.jpg", new myTexture());*/
}
private function init3DObjects():void{
Parsers.enableAllBundled();
loader = new Loader3D();
loader.scale(300);
loader.y = -400;
loader.addEventListener(AssetEvent.ASSET_COMPLETE, onModelParseComplete);
loader.loadData(new RictorModel());
away3DScene.scene.addChild(loader);
}
private function onModelParseComplete(e:AssetEvent):void{
loader.removeEventListener(AssetEvent.ASSET_COMPLETE, onModelParseComplete);
switch (String(e.asset.assetType)){
case "mesh":
rictorMesh = e.asset as Mesh;
for each (var m:SubMesh in rictorMesh.subMeshes){
m.material = rictorMaterial;
}
break;
case "material":
var textureMaterial:TextureMaterial = e.asset as TextureMaterial;
textureMaterial.lightPicker = staticLightPicker;
break;
default:
trace("UNHANDLED ASSET TYPE: " + e.asset.assetType);
break;
}
}
private function resizeHandler(e:Event=null):void{
fullScreenButton.x = stage.stageWidth - fullScreenButton.width - 5;
fullScreenButton.y = 5;
}
private function enterFrameHandler(e:Event):void{
if (rictorMesh){
rictorMesh.rotationY += 1;
}
}
}
}