In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

PV3DのTriangleMesh3Dの練習02 自分用に分かりやすく修正

/**
 * Copyright siouxcitizen ( http://wonderfl.net/user/siouxcitizen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/a88U
 */

// forked from siouxcitizen's PV3DのTriangleMesh3Dの練習01 三角形の作成
//PV3DのTriangleMesh3Dの練習02 自分用に分かりやすく修正
//前回のソースをもう少し分かりやすくできないかと修正してみました。
//少しTriangleMesh3Dの理解が進みました。。。
//
//↓今回のコードを作成するにあたって以下のサイト&コードを参考にさせて頂きました
//[Papervision3D2.0] TriangleMesh3D
//http://blog.r3c7.net/?p=136
package
{
    import flash.events.Event;

    import org.papervision3d.core.geom.TriangleMesh3D;
    import org.papervision3d.core.geom.renderables.Triangle3D;
    import org.papervision3d.core.geom.renderables.Vertex3D;
    import org.papervision3d.core.math.NumberUV;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.view.BasicView;

    [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
    public class TriangleMesh3DExample extends BasicView
    {
        private var mesh : TriangleMesh3D;
        private var size : int = 200;//オブジェクトの長さ

        public function TriangleMesh3DExample()
        {
            //マテリアル設定
            var material:ColorMaterial = new ColorMaterial(0x006699,1.0);
            material.doubleSided = true;

            //TriangleMesh3Dオブジェクト生成
            mesh = new TriangleMesh3D( material, new Array(), new Array(), null );
            scene.addChild(mesh);

            //頂点定義
            var v0 : Vertex3D = new Vertex3D(size*cos(90), size*sin(90), 0);
            var v1 : Vertex3D = new Vertex3D(size*cos(210), size*sin(210), 0);
            var v2 : Vertex3D = new Vertex3D(size*cos(330), size*sin(330), 0);
            mesh.geometry.vertices.push( v0 );
            mesh.geometry.vertices.push( v1 );
            mesh.geometry.vertices.push( v2 );

            //面定義
            var uvA : NumberUV = new NumberUV( 0, 0 );
            var uvC : NumberUV = new NumberUV( 1, 0 );
            var uvB : NumberUV = new NumberUV( 0, 1 );

            mesh.geometry.faces.push( new Triangle3D( mesh, new Array(v0,v1,v2), null, new Array(uvA,uvC,uvB) ));
            mesh.geometry.ready = true;

            startRendering();
        }

        override protected function onRenderTick(event:Event=null):void
        {
            mesh.rotationX=viewport.mouseX;
            mesh.rotationY=viewport.mouseY;
            super.onRenderTick(event);
        }

        //--------------------------------------------sin
        private function sin(degree:Number):Number{
            return Math.sin(Math.PI * degree / 180);
        }
 
        //--------------------------------------------cos
        private function cos(degree:Number):Number{
            return Math.cos(Math.PI * degree / 180);
        }
    }
}