Need help with Shape3D.SORT_CUSTOM_BSP

All the technical questions concerning the AS3 3.x versions of Sandy.

Need help with Shape3D.SORT_CUSTOM_BSP

Postby echeese » Tue Dec 08, 2009 10:59 pm

Hi there, I'm working on a game and I'd like to use BSP sorting. I already have everything all cut up for the bsp tree and so I was wondering how I can implement it. i've set the sortingMode and added the root to the shape, and i'm getting this error:
Code: Select all
  1.  
  2. TypeError: Error #1009: Cannot access a property or method of a null object reference.
  3.     at sandy.core::Renderer/render()[/sandy/core/Renderer.hx:200]
  4.     at sandy.core::Scene3D/render()[/sandy/core/Scene3D.hx:150]
  5.     at Main$/main()[/src/Main.hx:39]
  6.     at MethodInfo-352()[<null>:1]
  7.     at flash::Boot()[/haxe/std/flash9/Boot.hx:86]
  8.  
echeese
 
Posts: 4
Joined: Mon Aug 18, 2008 2:30 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby makc » Wed Dec 09, 2009 1:05 am

...on the 2nd thought, if you say
added the root to the shape
I have no idea :( maybe leave a sample?
User avatar
makc
Development Team Member
Development Team Member
 
Posts: 1643
Joined: Tue Sep 18, 2007 5:48 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby echeese » Wed Dec 09, 2009 1:16 am

This is what I have so far.
Code: Select all
  1. //haXe
  2.         var scene:Scene3D = new Scene3D( "myScene", Lib.current, new Camera3D( 550, 400 ), new Group("root") );
  3.         var level:Shape3D = new Shape3D("level");
  4.         level.sortingMode = Shape3D.SORT_CUSTOM_BSP;
  5.         level.bsp = new BSPNode();
  6.         level.bsp.plane = new Plane(1, 0, 0, 0);
  7.         level.bsp.positive = new BSPNode();
  8.         var box:Box = new Box();
  9.         level.bsp.positive.faces = box.aPolygons;
  10.         scene.root.addChild(level);
  11.         scene.render();
echeese
 
Posts: 4
Joined: Mon Aug 18, 2008 2:30 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby makc » Wed Dec 09, 2009 1:27 am

right, positive was node, not array of it :/ I forgot, ha ha. ok, I will make box-based example.
User avatar
makc
Development Team Member
Development Team Member
 
Posts: 1643
Joined: Tue Sep 18, 2007 5:48 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby echeese » Wed Dec 09, 2009 1:32 am

That would be great. Any ideas of where I went wrong? Or has this feature not ready? I'm not using the SVN build btw, but the haXe 3.1.2 version.
echeese
 
Posts: 4
Joined: Mon Aug 18, 2008 2:30 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby makc » Wed Dec 09, 2009 2:02 am

haxe trunk *IS* 3.1.2 :) or, actually, *WAS* because I committed getPlane() minutes ago. Any way, here goes your example.
Code: Select all
  1. // CustomBSPExample.hx
  2. package ;
  3. import flash.display.Sprite;
  4. import sandy.core.data.BSPNode;
  5. import sandy.core.Scene3D;
  6. import sandy.core.scenegraph.Camera3D;
  7. import sandy.core.scenegraph.Group;
  8. import sandy.core.scenegraph.Shape3D;
  9. import sandy.primitive.Box;
  10.  
  11. class CustomBSPExample extends Sprite {
  12.  
  13.     private var box:Box;
  14.     private var scene:Scene3D;
  15.     public function new () {
  16.         super ();
  17.  
  18.         scene = new Scene3D ("scene", this, new Camera3D (), new Group ("root"));
  19.         box = new Box ("box", 10, 10, 10, "quad"); scene.root.addChild (box);
  20.         box.rotateX = 123; box.rotateY = 45; box.rotateZ = 67;
  21.         box.sortingMode = Shape3D.SORT_CUSTOM_BSP;
  22.  
  23.         // box is actually convex shape, so we can cut it in any order
  24.         box.bsp = new BSPNode ();
  25.         box.bsp.plane = box.aPolygons [0].getPlane ();
  26.         box.bsp.faces = [ box.aPolygons [0] ];
  27.  
  28.         // any face is behind any other faces
  29.         // I think this means being in negative subspace
  30.         box.bsp.negative = new BSPNode ();
  31.         box.bsp.negative.plane = box.aPolygons [4].getPlane ();
  32.         box.bsp.negative.faces = [ box.aPolygons [4] ];
  33.  
  34.         box.bsp.negative.negative = new BSPNode ();
  35.         box.bsp.negative.negative.plane = box.aPolygons [5].getPlane ();
  36.         box.bsp.negative.negative.faces = [ box.aPolygons [5] ];
  37.  
  38.         box.bsp.negative.negative.negative = new BSPNode ();
  39.         box.bsp.negative.negative.negative.plane = box.aPolygons [3].getPlane ();
  40.         box.bsp.negative.negative.negative.faces = [ box.aPolygons [3] ];
  41.  
  42.         box.bsp.negative.negative.negative.negative = new BSPNode ();
  43.         box.bsp.negative.negative.negative.negative.plane = box.aPolygons [1].getPlane ();
  44.         box.bsp.negative.negative.negative.negative.faces = [ box.aPolygons [1] ];
  45.  
  46.         box.bsp.negative.negative.negative.negative.negative = new BSPNode ();
  47.         box.bsp.negative.negative.negative.negative.negative.plane = box.aPolygons [2].getPlane ();
  48.         box.bsp.negative.negative.negative.negative.negative.faces = [ box.aPolygons [2] ];
  49.  
  50.         // render
  51.         scene.camera.z = -123;
  52.         addEventListener ("enterFrame", loop);
  53.     }
  54.  
  55.     private function loop (e):Void {
  56.         // some motion
  57.         box.rotateX += 1;
  58.         box.rotateY = box.rotateX * box.rotateZ / 360;
  59.         box.rotateZ += 2;
  60.  
  61.         scene.render();
  62.     }
  63.    
  64.     public static function main () {
  65.         flash.Lib.current.addChild (new CustomBSPExample ());
  66.     }
  67. }
User avatar
makc
Development Team Member
Development Team Member
 
Posts: 1643
Joined: Tue Sep 18, 2007 5:48 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby echeese » Wed Dec 09, 2009 5:25 am

Am I mistaken or am I only able to use one texture for the entire bsp level?
echeese
 
Posts: 4
Joined: Mon Aug 18, 2008 2:30 pm

Re: Need help with Shape3D.SORT_CUSTOM_BSP

Postby makc » Wed Dec 09, 2009 12:14 pm

you can set textures to each polygon individually.
User avatar
makc
Development Team Member
Development Team Member
 
Posts: 1643
Joined: Tue Sep 18, 2007 5:48 pm


Return to 3.x technical help

Who is online

Users browsing this forum: No registered users and 1 guest