sir, my awd file look grayscale, i try other awd in PrimitveExamples, like primitives_capsule.awd, they look colourful when fill it in colour, but when it texture it with jpeg file they look grayscale, why ? shall i use png, or 16bit, 24 bit, 32bit jpeg ? or i omit to import some code ?
package {
import away3d.containers.View3D;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.events.AssetEvent;
import away3d.events.LoaderEvent;
import away3d.library.AssetLibrary;
import away3d.library.assets.AssetType;
import away3d.loaders.Loader3D;
import away3d.loaders.misc.AssetLoaderContext;
import away3d.loaders.parsers.AWD1Parser;
import away3d.loaders.parsers.AWD2Parser;
import away3d.loaders.parsers.Parsers;
import away3d.materials.ColorMaterial;
import away3d.materials.TextureMaterial;
import away3d.materials.*;
import away3d.textures.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.net.URLRequest;
[SWF(width=“320”, height=“240”, backgroundColor=“0x2f3032”, frameRate=“30”, quality=“LOW”)]
public class AWDViewer extends Sprite {
private var _view:View3D;
private var awayStats:AwayStats;
public function AWDViewer() {
stage.addEventListener(Event.RESIZE, onResize);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.showDefaultContextMenu = true;
stage.stageFocusRect = false;
_view = new View3D();
_view.backgroundColor = 0x666666;
_view.antiAlias = 2;
addChild(_view);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
[Embed(source=’/../embeds/plancam.awd’, mimeType=“application/octet-stream”)]
var object:Class;
Parsers.enableAllBundled();
AssetLibrary.enableParser(AWD2Parser);
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete);
AssetLibrary.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError);
AssetLibrary.loadData(object, new AssetLoaderContext(false));
awayStats = new AwayStats(_view);
addChild(awayStats);
}
sir, what’s wrong ?
private function onAssetComplete(ev:AssetEvent):void {
if (ev.asset.assetType == AssetType.MESH) {
var mesh : Mesh;
var texMat : TextureMaterial;
mesh = Mesh(ev.asset);
texMat = mesh.material as TextureMaterial;
if (mesh.material == null || (texMat && texMat.texture == null))
mesh.material = new ColorMaterial(Math.random() * 0xffffff);
_view.scene.addChild(mesh);
_view.camera.lookAt(mesh.position);
}
}
private function onLoadError(ev:LoaderEvent):void {
trace(‘Could not find’, ev.url);
}
private function onResourceComplete(ev : LoaderEvent) : void
{
trace(‘onResourceComplete’, ev.url);
}
private function onEnterFrame(ev : Event) : void
{
_view.render();
}
private function onResize(event:Event = null):void {
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
awayStats.x = stage.stageWidth - awayStats.width;
}
}
}