[Papervision3D] MovieAssetMaterial, something wrong?
joesatriani
info at dennistenhove.nl
Wed May 13 12:21:59 PDT 2009
Ralph Hauwert wrote:
>
> I think it can't load the bitmapfilematerial.
>
I know it doesn't load the BitmapFileMaterial, but how come?
This is the complete source for that file, a little change of simplecubes.as
that comes with flarmanager:
package exampleSupport {
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.utils.FLARPVGeomUtils;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Dictionary;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class SimpleCubes extends Sprite {
private static const CUBE_SIZE:Number = 100;
private static const CUBE_W:Number = 6;
private var viewport3D:Viewport3D;
private var camera3D:FLARCamera3D;
private var scene3D:Scene3D;
private var renderEngine:LazyRenderEngine;
private var pointLight3D:PointLight3D;
private var markersByPatternId:Vector.<Vector.<FLARMarker>>; //
FLARMarkers, arranged by patternId
private var containersByMarker:Dictionary; // Cube containers, hashed
by corresponding FLARMarker
public function SimpleCubes (numPatterns:uint, cameraParams:FLARParam,
viewportWidth:Number, viewportHeight:Number) {
this.init(numPatterns);
this.initPapervisionEnvironment(cameraParams, viewportWidth,
viewportHeight);
}
public function addMarker (marker:FLARMarker) :void {
// store marker
var markerList:Vector.<FLARMarker> =
this.markersByPatternId[marker.patternId];
markerList.push(marker);
// create a new Cube, and place it inside a container (DisplayObject3D)
for manipulation
var container:DisplayObject3D = new DisplayObject3D();
var materialsList:MaterialsList = new MaterialsList({all:
this.getMaterialByPatternId(marker.patternId)});
var cube:Cube = new Cube(BitmapFileMaterial, CUBE_SIZE, CUBE_SIZE,
CUBE_SIZE);
cube.z = 20;
container.addChild(cube);
this.scene3D.addChild(container);
// associate container with corresponding marker
this.containersByMarker[marker] = container;
}
public function removeMarker (marker:FLARMarker) :void {
// find and remove marker
var markerList:Vector.<FLARMarker> =
this.markersByPatternId[marker.patternId];
var markerIndex:uint = markerList.indexOf(marker);
if (markerIndex != -1) {
markerList.splice(markerIndex, 1);
}
// find and remove corresponding container
var container:DisplayObject3D = this.containersByMarker[marker];
if (container) {
this.scene3D.removeChild(container);
}
delete this.containersByMarker[marker]
}
private function init (numPatterns:uint) :void {
// set up lists (Vectors) of FLARMarkers, arranged by patternId
this.markersByPatternId = new Vector.<Vector.<FLARMarker>>(numPatterns,
true);
while (numPatterns--) {
this.markersByPatternId[numPatterns] = new Vector.<FLARMarker>();
}
// prepare hashtable for associating Cube containers with FLARMarkers
this.containersByMarker = new Dictionary(true);
}
private function initPapervisionEnvironment (cameraParams:FLARParam,
viewportWidth:Number, viewportHeight:Number) :void {
this.scene3D = new Scene3D();
this.camera3D = new FLARCamera3D(cameraParams);
this.viewport3D = new Viewport3D(viewportWidth, viewportHeight);
this.addChild(this.viewport3D);
this.renderEngine = new LazyRenderEngine(this.scene3D, this.camera3D,
this.viewport3D);
this.pointLight3D = new PointLight3D();
this.pointLight3D.x = 1000;
this.pointLight3D.y = 1000;
this.pointLight3D.z = -1000;
this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}
private function onEnterFrame (evt:Event) :void {
this.updateCubes();
this.renderEngine.render();
}
private function updateCubes () :void {
// update all Cube containers according to the transformation matrix in
their associated FLARMarkers
var i:int = this.markersByPatternId.length;
var markerList:Vector.<FLARMarker>;
var marker:FLARMarker;
var container:DisplayObject3D;
var j:int;
while (i--) {
markerList = this.markersByPatternId[i];
j = markerList.length;
while (j--) {
marker = markerList[j];
container = this.containersByMarker[marker];
container.transform =
FLARPVGeomUtils.convertFLARMatrixToPVMatrix(marker.transformMatrix);
}
}
}
private function getMaterialByPatternId (patternId:int)
:BitmapFileMaterial {
var colorId:int = patternId % 5;
switch (colorId) {
case 0:
return new BitmapFileMaterial("front.jpg");
case 1:
return new BitmapFileMaterial("bottom.jpg");
case 2:
return new BitmapFileMaterial("left.jpg");
case 3:
return new BitmapFileMaterial("right.jpg");
case 4:
default:
return new BitmapFileMaterial("back.jpg");
}
}
}
}
--
View this message in context: http://www.nabble.com/MovieAssetMaterial%2C-something-wrong--tp23508827p23528296.html
Sent from the Papervision3D mailing list archive at Nabble.com.
More information about the Papervision3D
mailing list