views:

199

answers:

1

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);
}
+1  A: 

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);
     }
    }
}
Andy West
that is correct it isn't a sphere - what should i be looking at then?
Josh
Are the plane orientations off dramatically or just a little bit? If it's not a sphere, what type of mesh is it and how was it created? I need some more info. Also, please see the new suggestion in my answer.
Andy West
i tried your other suggestion and the planes just all face the same way - ie doesn't work! what i've done is taken the standard sphere primitive and changed the fX value in the loop as follows: var fX:Number = fRds * Math.sin(fRad2 * Math.PI) * .6; which elongates the sphere into a rugby ball shape.
Josh
Ok, I replaced my old answer completely, since it looks like I was on the wrong track before. See if the new answer helps.
Andy West
YES!!! perfect thank you sooo much :)
Josh
You're welcome. I'm glad this worked for you. :-)
Andy West