我对Papervision3D或者bitmapData有疑问,我不确定问题出在哪里。我已经构建了一个程序,它采用4个横幅并将它们分成碎片,然后将这些碎片应用到立方体中,这样我就可以制作横幅旋转器。因此,在我运行程序后,我有10个立方体,每个立方体的4个面(正面,顶部,背面,底部)上有一个横幅。问题是某些面部定位不正确(旋转180度)。 Papervision3D有没有办法旋转立方体面?我认为问题的另一个地方是当我创建将应用于立方体面的bitmapData时。有没有办法在bitmapData创建过程中明确定义方向?任何帮助或想法将不胜感激。谢谢!
-------编辑----------
这是我的CubeMaker.as类的代码。这是获取图像片段并将其应用于立方体的类。
package {
import away3d.events.MaterialEvent;
import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.materials.TransformBitmapMaterial;
import away3d.primitives.Cube;
import away3d.primitives.data.CubeMaterialsData;
import CubeEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
public class CubeMaker extends Sprite {
private var _colorMaterial:ColorMaterial = new ColorMaterial(0x000000);
private var _dcRef;
private var _banners:Array;
private var _cubeArray:Array = [];
private var _cubeCoung:int = 0;
private var _numberOfPieces:int;
private var _width:Number;
private var _depth:Number;
private var _height:Number;
public function CubeMaker(banners:Array, numberOfPieces:int) {
_dcRef = DocumentClass._base;
_banners = banners;
_numberOfPieces = numberOfPieces;
}
public function makeCubes() {
//loop through the cubes
for (var i = 0; i < _numberOfPieces; i++) {
var faceBitmapArray:Array;
//fill array with four faces for current cube
faceBitmapArray = fillFace(i);
//get width and height from a piece instance
var width:Number;
var height:Number;
var tempArray:Array;
tempArray = _banners[0];
_width = tempArray[0].width;
_height = tempArray[0].height;
_depth = tempArray[0].height;
//create four materials from bitmapData
var myFront:TransformBitmapMaterial = new TransformBitmapMaterial(faceBitmapArray[0], {rotation:0} );
var myTop:TransformBitmapMaterial = new TransformBitmapMaterial(faceBitmapArray[1], {rotation:0.5} );
var myBack:TransformBitmapMaterial = new TransformBitmapMaterial(faceBitmapArray[2], {rotation:0} );
var myBottom:TransformBitmapMaterial = new TransformBitmapMaterial(faceBitmapArray[3], {rotation:0} );
//create two materians from color
var myLeft:ColorMaterial = new ColorMaterial(0x000000);
var myRight:ColorMaterial = new ColorMaterial(0x000000);
//create a CubeMatrialsData from the materials created above
var myMaterials:CubeMaterialsData = new CubeMaterialsData( { front:myFront, back:myBack, top:myTop, bottom:myBottom, left:myLeft, right:myRight} );
//listen for material change
myMaterials.addOnMaterialChange(materialChanged);
//create a new cube with the CubeMaterialsData created earlier
var _cube = new Cube({width:_width, height:_height, depth:_depth, cubeMaterials:myMaterials});
//the created cube is put into the _cubeArray
_cubeArray[i] = _cube;
if (i == (_numberOfPieces - 1)) cubesMade();
}
}
private function fillFace(i:int):Array {
var faceBitmapArray:Array = [];
for (var j = 0; j < 4; j++) {
//tempBannerArray filled with one banner in pieces
var tempBannerArray:Array = _banners[j];
//batmapData created and sized to current banner piece
var bitmapData:BitmapData = new BitmapData(tempBannerArray[i].width, tempBannerArray[i].height);
//bitmapData filled with current banner piece bitmap data
bitmapData = tempBannerArray[i].bitmapData;
bitmapData.lock();
//array is filled with bitmap data
faceBitmapArray[j] = bitmapData;
}
return faceBitmapArray;
}
private function cubesMade() {
//dispatch event to notify of cube making completion
dispatchEvent(new CubeEvent(CubeEvent.CUBES_MADE, _cubeArray.length));
}
private function materialChanged(e:MaterialEvent):void {
trace("Warning! Warning! Material changed!");
}
public function get cubes():Array {
return _cubeArray;
}
public function get cubeWidth():Number {
return _width;
}
public function get cubeHeight():Number {
return _height;
}
public function get cubeDepth():Number {
return _depth;
}
}
}
答案 0 :(得分:1)
前言:Papervision3D is close to unsupported / closed as a library,所以我强烈建议您使用Away3D或其他动作脚本3D库。尽管在PV3D上完成的工作从强大的角度来看是非常强大的,但是如果你想用它来构建3D体验,那就非常好了。从一开始就知道未来的dev +支持是不可能的。
除了前言之外,请查看库中的“Cube”原始类。您可以创建材质并将它们附加到将添加到多维数据集实例的MaterialsList实例。假设您正在使用BitmapMaterial,它具有您可以设置的“旋转”属性。只需确定哪些材料倒置并使其旋转= 180.优点:快速;缺点:硬编码。
另一种选择是在“资产”端点击问题并翻转图像。优点:快;缺点:不可扩展或将问题放在设计师身上。
加载数据/资产时,最佳选择是使用“旋转”属性,您可以使用该属性设置应翻转的图像。这是一个立方体,所以像Ender所说,up是相对的。