Hello, I've written a class for a simple box primitive - like so:
http://www.enigma-interactive.co.uk/external/sandbox/peterg/away3d/little_boxes.swf The idea being that i can change the dimensions of the box at runtime without altering the thickness of the box (and vice versa for the thickness). I have yet to write the UV mappings (and so the box throws errors if you alter the dimensions after the constructor is called). My goal is to allow the user to choose their dimensions and thickness and customise the box to their needs (add textures, logos etc). My plan to archive this is thus: - The UV map will be generated at runtime to match the boxes dimensions (in buildPrimitive function). - The user will select two faces to edit (not sure how yet) - The user will upload images and they will be flattened into the texture in the UV location for the appropriate faces - The texture will be re-applied to the box Does this seems sensible or insane? Any comments are greatly welcomed. Thanks package { import away3d.arcane; import away3d.core.base.Face; import away3d.core.base.Vertex; import away3d.primitives.AbstractPrimitive; use namespace arcane; public class SimpleBox extends AbstractPrimitive { private var _width:Number; private var _height:Number; private var _depth:Number; private var _thickness:Number; public function SimpleBox(init:Object = null) { super(init); _width = ini.getNumber("width", 100, { min : 1 } ); _height = ini.getNumber("height", 100, { min : 1 } ); _depth = ini.getNumber("depth", 100, { min : 1 } ); _thickness = ini.getNumber("thickness", 100, { min : 1 } ); buildPrimitive(); } protected override function buildPrimitive():void { super.buildPrimitive(); var hWidth:Number = width / 2; var hWidthNeg:Number = -hWidth; var hHeight:Number = height / 2; var hHeightNeg:Number = -hHeight; var hDepth:Number = depth / 2; var hDepthNeg:Number = -hDepth; // outer vertext // top vertecies var a :Vertex = createVertex( hWidthNeg, hHeight, hDepth); var b :Vertex = createVertex( hWidthNeg, hHeight, hDepthNeg); var c :Vertex = createVertex( hWidth, hHeight, hDepthNeg); var d :Vertex = createVertex( hWidth, hHeight, hDepth); // bottom vertecies var e :Vertex = createVertex( hWidthNeg, hHeightNeg, hDepth); var f :Vertex = createVertex( hWidthNeg, hHeightNeg, hDepthNeg); var g :Vertex = createVertex( hWidth, hHeightNeg, hDepthNeg); var h :Vertex = createVertex( hWidth, hHeightNeg, hDepth); //outer cube addFace(createFace(a, f, b)); addFace(createFace(a, e, f)); addFace(createFace(a, h, e)); addFace(createFace(a, d, h)); addFace(createFace(g, d, c)); addFace(createFace(g, h, d)); addFace(createFace(b, f, g)); addFace(createFace(b, g, c)); addFace(createFace(f, e, h)); addFace(createFace(f, h, g)); // inner vertex // top vertecies var a2 :Vertex = createVertex( hWidthNeg + _thickness, hHeight, hDepth - _thickness); var b2 :Vertex = createVertex( hWidthNeg + _thickness, hHeight, hDepthNeg + _thickness); var c2 :Vertex = createVertex( hWidth - _thickness, hHeight, hDepthNeg + _thickness); var d2 :Vertex = createVertex( hWidth - _thickness, hHeight, hDepth - _thickness); // bottom vertecies var e2 :Vertex = createVertex( hWidthNeg + _thickness, hHeightNeg + _thickness , hDepth- _thickness); var f2 :Vertex = createVertex( hWidthNeg + _thickness, hHeightNeg + _thickness, hDepthNeg + _thickness); var g2 :Vertex = createVertex( hWidth - _thickness, hHeightNeg + _thickness, hDepthNeg + _thickness); var h2 :Vertex = createVertex( hWidth- _thickness, hHeightNeg+ _thickness , hDepth- _thickness); //inner cube addFace(createFace(b2, f2, a2)); addFace(createFace(f2, e2, a2)); addFace(createFace(e2, h2, a2)); addFace(createFace(h2, d2, a2)); addFace(createFace(c2, d2, g2)); addFace(createFace(d2, h2, g2)); addFace(createFace(g2, f2, b2)); addFace(createFace(c2, g2, b2)); addFace(createFace(h2, e2, f2)); addFace(createFace(g2, h2, f2)); //joining addFace(createFace(a, a2, d)); addFace(createFace(a2, d2, d)); addFace(createFace(a, b, a2)); addFace(createFace(a2, b, b2)); addFace(createFace(b2, b, c)); addFace(createFace(b2, c, c2)); addFace(createFace(d2, c, d)); addFace(createFace(d2, c2, c)); } public function get width():Number { return _width; } public function set width(val:Number):void { if (_width == val) return; _width = val; _primitiveDirty = true; } public function get height():Number { return _height; } public function set height(val:Number):void { if (_height == val) return; _height = val; _primitiveDirty = true; } public function get depth():Number { return _depth; } public function set depth(val:Number):void { if (_depth == val) return; _depth = val; _primitiveDirty = true; } public function get thickness():Number { return _thickness; } public function set thickness(val:Number):void { if (_thickness == val) return; _thickness = val; _primitiveDirty = true; } } }
