将平面映射到基元

时间:2009-12-10 18:17:18

标签: actionscript-3 3d papervision3d

我已遍历顶点并将平面映射到每个顶点。我在正确定位飞机时遇到了问题。我可以使用球体,但是当我对基元进行任何改动时 - 位置是正确的但是它们不会正确地倾斜/倾斜。

编辑:注意 - 球体的更改是在创建球体之前完成的。我更新了Sphere类以创建一个细长的球体。

我用来放置飞机的代码如下:

pivotDO3D = new DisplayObject3D();
scene.addChild(pivotDO3D);
var bigSphere:Sphere = new Sphere(null, 500, 20, 20);

for each (var v:Vertex3D in bigSphere.geometry.vertices)
{
 var __seatmaterial:ColorMaterial = new ColorMaterial(0x000000);
 __seatmaterial.doubleSided = true;
 var p:Plane = new Plane(__seatmaterial, 20, 20, 2, 2);
 pivotDO3D.addChild(p);
 p.position = v.toNumber3D();
 p.lookAt(bigSphere);
}

1 个答案:

答案 0 :(得分:1)

以下演示说明如何最小化问题。我将乘法因子0.6改为2.0以及球体大小,以夸大效果,以便您可以轻松地看到它。确保在Sphere.as中更改为0.6到2.0。

关键是改变目标点的z位置和球体上点的z位置。

要进行比较,按原样运行以查看“修复”版本,并将lookAt目标从pivotDO3D2更改为bigSphere以查看旧版本。

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import org.papervision3d.cameras.*;
    import org.papervision3d.core.geom.renderables.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.render.*;
    import org.papervision3d.scenes.*;
    import org.papervision3d.view.*;

    [SWF(width='400', height='400', backgroundColor='0x000000', frameRate='30')]

    public class PlaneOrientationDemo extends Sprite
    {
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var renderer:BasicRenderEngine;
        private var viewport:Viewport3D;
        private var pivotDO3D:DisplayObject3D;

        public function PlaneOrientationDemo()
        {
            viewport = new Viewport3D(0, 0, true, true);
            addChild( viewport );

            renderer = new BasicRenderEngine();                         
            scene = new Scene3D( );

            camera = new Camera3D();
            camera.z = -700;
            camera.zoom = 50;

            pivotDO3D = new DisplayObject3D();
            scene.addChild(pivotDO3D);

            var pivotDO3D2:DisplayObject3D = new DisplayObject3D();

            var bigSphere:Sphere = new Sphere(null, 150, 20, 20);

            for each (var v:Vertex3D in bigSphere.geometry.vertices)
            {
                 var __seatmaterial:ColorMaterial = new ColorMaterial(0x00FF00);
                 __seatmaterial.doubleSided = true;
                 var p:Plane = new Plane(__seatmaterial, 20, 20, 2, 2);
                 pivotDO3D.addChild(p);
                 p.position = v.toNumber3D();

                 // This number should match the fx multiplication factor in Sphere.as.
                 var xFactor:Number = 2.0;

                 pivotDO3D2.z = v.z / (Math.PI / xFactor);
                 p.lookAt(pivotDO3D2);
            }

            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        private function onEnterFrame(event: Event): void
        {
            pivotDO3D.rotationX += 1;
            pivotDO3D.rotationY += 1;
            renderer.renderScene(scene, camera, viewport);
        }
    }
}