将平面映射到图元上

发布于 2024-08-14 11:11:33 字数 634 浏览 1 评论 0原文

我循环遍历了顶点并为每个顶点映射了一个平面。我在正确定位飞机时遇到问题。我可以让它与球体一起工作,但是当我对基元进行任何更改时 - 位置是正确的,但它们没有以正确的方式面向/倾斜。

编辑:注意 - 球体的交替是在创建球体之前完成的。我已经更新了 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);
}

I've looped through the vertices and mapped a plane to each one. I'm having problems orientating the planes correctly. I can get it working with a sphere but when i make any alterations to the the primitive - positions are correct but they don't face/tilt the right way.

EDIT: Note - the alternation to the sphere was done before the sphere was created. I have updated the Sphere class to create an elongated sphere.

The code I'm using to place the planes are as follows:

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2024-08-21 11:11:34

以下演示展示了如何最大限度地减少该问题。我将倍增系数 0.6 更改为 2.0 以及球体大小,以放大效果,以便您可以轻松看到它。确保将 Sphere 中的 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);
        }
    }
}

The following demo shows how to minimize the problem. I changed the multiplication factor of 0.6 to 2.0 as well as the sphere size in order to exaggerate the effect so you can see it easily. Make sure to change 0.6 to 2.0 in your Sphere.as as well.

The key is in varying the z location of the target point with the z location of the point on the sphere.

To compare, run it as-is to see the "fixed" version, and change the lookAt target from pivotDO3D2 to bigSphere to see the old version.

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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文