フォーラムのこの記事にPlaneのプリミティブオブジェクトのコードがあったので使わせてもらう。
package { import alternativa.engine3d.core.Object3D; import alternativa.engine3d.core.VertexAttributes; import alternativa.engine3d.materials.Material; import alternativa.engine3d.objects.Mesh; import alternativa.engine3d.resources.Geometry; /** * ... * @author */ public class Plane extends Object3D { private var _h:uint; private var _w:uint; private var _material:Material; private var _doubleSided:Boolean; private var _numTriangles:uint; public function Plane(h:uint, w:uint, material:Material, doubleSided:Boolean = false){ this._w = w; this._h = h; this._material = material; this._doubleSided = doubleSided; this._numTriangles = (_doubleSided) ? 4 : 2; setPlane(); } private function setPlane():void { var mesh:Mesh = new Mesh() var attributes:Array = new Array(); attributes[0] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION; attributes[3] = VertexAttributes.TEXCOORDS[0]; attributes[4] = VertexAttributes.TEXCOORDS[0]; var geometry:Geometry = new Geometry(); geometry.addVertexStream(attributes); geometry.numVertices = 4; var vertices:Array = [-(_w / 2), -(_h / 2), 0, -(_w / 2), (_h / 2), 0, (_w / 2), (_h / 2), 0, (_w / 2), -(_h / 2), 0]; var uvt:Array = [0, 1, 0, 1, 0, 1, 0, 1]; geometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>(vertices)); geometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>(uvt)); var arr_indices:Array = (_doubleSided) ? [0, 1, 2, 0, 2, 3, 0, 2, 1, 0, 3, 2] : [0, 1, 2, 0, 2, 3]; geometry.indices = Vector.<uint>(arr_indices); mesh.geometry = geometry; mesh.addSurface(_material, 0, _numTriangles); mesh.calculateBoundBox(); addChild(mesh); } } }
Author:9ballsyn
ActionScriptについて
最近はMolehill