So I am trying to create a 3D image.  Basically a Barn but the barn needs to
grow as the length and width grows.   So just painting a picture on a square
isnt going to work.  

I found this one example written by Lee Burrows which he offers a Shape3D.as
class where you set points and then with the points, you set indices to
create the triangles to paint whatever image you wish onto the sides of your
3D image.  And then there is a uvt Array which you tell where on the texture
image each point is plotted.  If I draw my entire image as one image only,
then I minimize the number of points I have.  Which evidently is a good
thing hence why they use this triangle idea.  To minimize Points.   However,
if I do the entire barn as one piece, then I have a set of three attributes
for every point for every flat surface.  So lets say its just a cube, You
have six flat surfaces.  So the array of uvt's will contain six uvt's but
each uvt has to have something for every single point.  If nothing is done
for that point then the entry is NaN, NaN, NaN.

So for six sides, you only need four points for the image 0,0, NaN 0,1,NaN,
1,0, NaN, and 1,1,NaN.  But the remaining points all have NaN, NaN, NaN. 
The third parameter is for perspective which the matrix program fills in
later.  Now, in a cube, you only have 8 points.  So you have six uvts and
each uvt has 3 parameters per point so that is 24 parameters.  Thats no big
deal.  However if I have a point for every foot on a barn.  and one wall is
120 foot.  Then that is two points for every foot so 242 Points.  Thats 120
squares to fill.  So my uvt array would have 120 sets of points parameters
or 242*3.  so each set would contain 726 entries of which only four sets are
for the mapping of the image itself and the rest pretty much NaN.  And that
is only one wall.  Add in another wall, the front and back of the barn and
then add in two more wall sizes for the roof and you are talking about a
whole lot of NaNs.  That is huge.  

However, I also can just create an object for just one panel.  1 foot by the
height.  Yes, I would save on the NaNs.  Each object only has one side to
fill and only needs four sets for the one uvt.  However, I would now double
the number of points.  When its one object, I can reuse points,  When its
one panel, each panel must use four points.  so 120 panels will use 480
points.   

So the question is, which is more expensive, the points that the matrix must
do the math on or the amount of memory being used to store all those uvt
parameters which are pretty much the majority will never be used?

or does someone know of a better way?

Here is a link to the triangle part.  I cant find the example I used and so
I am posting some of the code for the cube.

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS84753F1C-5ABE-40b1-A2E4-07D7349976C4.html

package objects
{
        import flash.display.BitmapData;
        import flash.geom.Point;
        import flash.geom.Vector3D;
        import objects.Shape3D;
        
        public class Cube extends Shape3D
        {
                private var wPpF:int = 9;
                private var hPpF:int = 9;
                private var lPpF:int = 9;
                private var wdth:int = 10;
                private var length:int = 10;
                private var hight:int = 10;

                public function Cube(width:int, length:int, height:Number)
                {
                        super();
                        this.wdth = width * wPpF;
                        this.length = length * lPpF;
                        this.hight = height * hPpF;
                        createFramePoints();
                        createIndicies();
                        createuvt();
                        createTexture();
                        createColors();
                }
                
                public function setTexture(texture:Array):void
                {
                        this.texture = texture;
                }
                
                private function createFramePoints():void
                {
                        // set of points which makes up the Frame of the object 
(Cube) from
center (0,0,0).
                        // in this case the first point is (-50, -50, -50) 50 
pixels to the left,
50 pixels up and 50 pixels forward
                        // in this case, each side of the cube is 100 pixels in 
length.
                        points = new Vector.<Vector3D>();                       
                                                                                
// placing points
                        points.push(new Vector3D(-1*length, -1*hight, 
-1*wdth));        // left up
forward
                        points.push(new Vector3D(length, -1*hight, -1*wdth));   
        // right up
forward
                        points.push(new Vector3D(length, hight, -1*wdth));      
                // right down
forward
                        points.push(new Vector3D(-1*length, hight, -1*wdth));   
        // left down
forward
                        points.push(new Vector3D(-1*length, -1*hight, wdth));   
        // left up back
                        points.push(new Vector3D(length, -1*hight, wdth));      
                // right up back
                        points.push(new Vector3D(length, hight, wdth));         
                // right down back
                        points.push(new Vector3D(-1*length, hight, wdth));      
                // left down back
                }
                
                private function createIndicies():void
                {
                        // Two sets of Triangles. Hence six indicies.  
                        // index for each point.
                        // two points make an explicit line.  First point to 
the second point
                        // third point makes two explicit lines.  First to the 
second, second to
the third.
                        // The third line is implied line.
                        // Three points makes a triangle.
                        // Both Triangles Can not share an explicit line.  
                        // For instance 0,1,3, 1,3,2 is unacceptable.
                        // 0,1,3  1,2,3 is acceptable
                        var indicesFront:Vector.<int> = new Vector.<int>();
                        indicesFront.push(0, 1, 3, 1, 2, 3);
                        var indicesBack:Vector.<int> = new Vector.<int>();
                        indicesBack.push(5, 4, 7, 6, 5, 7);
                        var indicesLeft:Vector.<int> = new Vector.<int>();
                        indicesLeft.push(1, 5, 2, 5, 6, 2);
                        var indicesRight:Vector.<int> = new Vector.<int>();
                        indicesRight.push(4, 0, 3, 4, 3, 7);
                        var indicesTop:Vector.<int> = new Vector.<int>();
                        indicesTop.push(4, 5, 0, 5, 1, 0);
                        var indicesBottom:Vector.<int> = new Vector.<int>();
                        indicesBottom.push(3, 2, 7, 2, 6, 7);
                        indices = [indicesFront, indicesBack, indicesLeft, 
indicesRight,
indicesTop, indicesBottom];
                        
                }
                
                private function createuvt():void
                {
                        // bitmap image. (x,y) upperleft (0,0) upperright (1,0) 
lowerleft (0,1)
lower right (1,1)
                        // (u,v,t) is (x,y, perspective)  perspective init to 
NaN.  Filled in
later.
                        // if a point is not used then (NaN,NaN,NaN)
                        var uvtFront:Vector.<Number> = new Vector.<Number>();
                        uvtFront.push(0, 0, NaN, 1, 0, NaN, 1, 1, NaN, 0, 1, 
NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN);
                        var uvtBack:Vector.<Number> = new Vector.<Number>();
                        uvtBack.push(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN, NaN,
1, 0, NaN, 0, 0, NaN, 0, 1, NaN, 1, 1, NaN);
                        var uvtLeft:Vector.<Number> = new Vector.<Number>();
                        uvtLeft.push(NaN, NaN, NaN, 0, 0, NaN, 0, 1, NaN, NaN, 
NaN, NaN, NaN,
NaN, NaN, 1, 0, NaN, 1, 1, NaN, NaN, NaN, NaN);
                        var uvtRight:Vector.<Number> = new Vector.<Number>();
                        uvtRight.push(1, 0, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
1, 1, NaN, 0, 0,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 1, NaN);
                        var uvtTop:Vector.<Number> = new Vector.<Number>();
                        uvtTop.push(0, 1, NaN, 1, 1, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, 0, 0,
NaN, 1, 0, NaN, NaN, NaN, NaN, NaN, NaN, NaN);
                        var uvtBottom:Vector.<Number> = new Vector.<Number>();
                        uvtBottom.push(NaN, NaN, NaN, NaN, NaN, NaN, 1, 0, NaN, 
0, 0, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, 1, 1, NaN, 0, 1, NaN);
                        uvt = [uvtFront, uvtBack, uvtLeft, uvtRight, uvtTop, 
uvtBottom];
                }
                
                private function createTexture():void
                {
                        // Width, Height, Color
                        var bitmaps:Array = new Array(6);
                        bitmaps[0] = new BitmapData(500,500,false,0x990000);
                        bitmaps[1] = new BitmapData(500,500,false,0x009900);
                        bitmaps[2] = new BitmapData(500,500,false,0x000099);
                        bitmaps[3] = new BitmapData(500,500,false,0x999900);
                        bitmaps[4] = new BitmapData(500,500,false,0x009999);
                        bitmaps[5] = new BitmapData(500,500,false,0x990099);
                        texture = bitmaps;
                }
                
                private function createColors():void
                {
                        // Random set of colors
                        colors = [0x990000, 0x009900, 0x000099, 0x999900, 
0x009999, 0x990099];
                }
                
        }
}





--
View this message in context: 
http://apache-flex-users.2333346.n4.nabble.com/3D-which-is-more-expensive-Points-Or-a-whole-lot-of-NaNs-tp13368.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Reply via email to