سؤال

I have a question about Papervision3D, or perhaps bitmapData, I am unsure where the problem is. I have constructed a program that takes 4 banners and splits them into pieces and then applies those pieces to cubes so that I can make a banner rotator. So after I run my program I have 10 cubes with a piece of a banner on 4 faces(front, top, back, bottom) of each cube. The problem is that some of the faces are oriented incorrectly(spun 180 degrees). Is there a way in Papervision3D to spin a cube face? The other place I think the problem may be is when I create the bitmapData that will be applied to the cube faces. Is there some way to explicitly define orientation during bitmapData creation? Any help or ideas would be greatly appreciated. Thanks!

-------Edit----------

Here is the code for my CubeMaker.as class. This is the class that takes the image pieces and applies them to the cubes.

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;
    }
}   

}

هل كانت مفيدة؟

المحلول

Preface: Papervision3D is close to unsupported / closed as a library, so I highly recommend using Away3D or another actionscript 3D library. Though the work done on PV3D was groundbreaking and incredible from a flash perspective so if you're looking to build a 3D experience with it, it's quite good. Just know from the get-go that future dev + support are unlikely.

Preface aside, take a look at the "Cube" primitive class in the library. You can create Materials and attach them to the MaterialsList instance that will be added to the cube instance. Assuming you're using BitmapMaterial, it has a "rotation" property, that you can set. Just determine which materials are upside-down and make their rotation = 180. Pros: quick; Cons: hard-coded.

The other option is to hit the problem on the "asset" end and flip your images. Pros: quick; Cons: non-scalable or puts the issue on the designer.

The best option, when loading the data / assets, is to have a "rotate" property that you can use to set which images should be flipped. It's a cube, so like Ender says, up is relative.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top