FrustumClipping makes all Sprite3D objects disappear near screen borders

65 views
Skip to first unread message

Gleb Kobzar

unread,
Jun 10, 2010, 8:19:14 AM6/10/10
to Away3D.dev
Hello,

I have a problem with Sprite3D and FrustumClipping. When I use
Rectangular or Nearfield clipping Sprite3D objects are displayed
correctly. But FrustumClipping makes all Sprite3D objects disappear
near screen borders. I noticed they disappear when Sprite3D center/
pivot point moves out of view borders (moving over the surface with
arrows):
http://www.kollaps.com.ua/gb/SpriteFrustum/

Here are sources for Flash CS4:
http://www.kollaps.com.ua/gb/SpriteFrustum/SpritePlants.zip

And AS3 code related to Sprites, view, scene and camera setup:

function initEngine():void
{
scene = new Scene3D();

scamera = new SpringCam();
...
clipping= new FrustumClipping({minZ:50, maxZ:2000});

var basicrenderer:BasicRenderer = new BasicRenderer();

view = new View3D();
view.renderer=basicrenderer;
//view.renderer=Renderer.INTERSECTING_OBJECTS;
view.x = stage.stageWidth / 2;
view.y = stage.stageHeight / 2;

view.scene = scene;
view.camera = scamera;
view.clipping = clipping;

addChild(view);
}
function initMaterials():void
{

floorMaterial = new TransformBitmapMaterial(Cast.bitmap(GrassOld), {
scaleX:0.05, scaleY:0.05, repeat:true});
treeMaterial = new BitmapMaterial(Cast.bitmap(OakTree));
//treeMaterial = new BitmapMaterial(new OakTree(362,263*2));
}
function initObjects():void
{

floor=new Plane();

floor.height=PLANE_LENGTH;
floor.width=PLANE_LENGTH;
floor.segmentsH=PLANE_SEGMENTS;
floor.segmentsW=PLANE_SEGMENTS;
floor.material=floorMaterial;

view.scene.addChild(floor);

Trees=new Array();
var sprite:Sprite3D;
var spriteMesh:Mesh;

for (var i:int = 0; i <100; i++) {
spriteMesh=new Mesh();
sprite = new Sprite3D(null,362,526);

spriteMesh.x=PLANE_LENGTH*Math.random()-PLANE_LENGTH/2;
spriteMesh.z=PLANE_LENGTH*Math.random()-PLANE_LENGTH/2;
spriteMesh.y=0;
sprite.material=treeMaterial;

sprite.scaling=2.0+2.0*Math.random();

spriteMesh.addSprite(sprite);
view.scene.addChild(spriteMesh);
}

}

You may notice that I create a Mesh object for each sprite, because I
would need to add interactivity and zDepth actions. By the way without
this all sprites disappear under Frustum Clipping.

May be I'm doing something wrong?

Thanks beforehand for advice

Michael Iv

unread,
Jun 10, 2010, 8:26:29 AM6/10/10
to away3...@googlegroups.com
As far as I understand that , because Sprites have no meshes of triangles ,so there can be no clipping on triangles level(So only triangles that outside the frustrum are invisible). Therefore When your sprite passes the clipping border it disappears completely . Try to push view.minX and maxX . to broaden clipping area.

Gleb Kobzar

unread,
Jun 10, 2010, 8:48:56 AM6/10/10
to Away3D.dev
Hi Michael,

Thanks a lot for the reply. But I can't find properties minX and maxX
for view3D object. Guess you mean according clipping props. Setting
clipping properties even up to:
clipping.minX = -10000;
clipping.minY = -10000;
clipping.maxX = 10000;
clipping.maxY = 10000;

doesn't help - there is no effect at all. This is strange because
smaller values do clip the view.
> explomas...@gmail.com
> t...@neurotech.co.il

Michael Iv

unread,
Jun 10, 2010, 8:57:28 AM6/10/10
to away3...@googlegroups.com
Well ,although i am sure that there is easier solution (still did not look for it) ,you can go into FrustrumClipping class and hack it. You should work with Frustrum planes against which the distance to the objects that need to be clipped  is measured. But it is quite strange that minX maxX don't work.

Gleb Kobzar

unread,
Jun 30, 2010, 3:35:05 AM6/30/10
to Away3D.dev
The problem is not yet solved. If anybody had the same and got it
solved please share your experience!

Rob Bateman

unread,
Jul 2, 2010, 8:27:48 AM7/2/10
to away3...@googlegroups.com
Hey Gleb

I beleive this is a problem to do with object culling - the frustum clipping class culls while objects by detecting whether their bounding spheres are visible within the view - and for that to function correctly, the bounding dimensions of each object have to be correctly caclulated. Sounds like this isn't happening for Sprite3D

I'll look into the problem, but in the meantime you should be able to turn off object culling on the clipping class:

myFrustumClipping.objectCulling =  false;

and to help keep this bug alive, you can submit a report to the issues list on googlecode:

http://code.google.com/p/away3d/issues/list

this has been growing a little in recent months, but i'm finally getting a chance to have a look at the outstanding bugs

cheers!

Rob
--
Rob Bateman
Flash Development & Consultancy

rob.b...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

Rujia Liu

unread,
Jul 8, 2010, 8:00:48 AM7/8/10
to away3...@googlegroups.com
I solved a similar problem (with my own kind of sprite) by hacking the source code. It might be helpful to you:

in ProjectionTraverser.as, just after computing _viewTransform, add the following lines:

if (node is Sprite3D)
{
            _nodeClassification = _cameraVarsStore.nodeClassificationDictionary[node] = Frustum.IN;
            return true;
}

but since in my case I'm dealing with my own kind of sprite, I'm not sure if it works for Sprite3D. Good luck!

- Rujia

Rujia Liu

unread,
Jul 8, 2010, 9:35:51 AM7/8/10
to away3...@googlegroups.com
oops, I was wrong. I didn't notice that Sprite3D extends Element rather than Object3D. The code should work with other sprites subclassing Object3D.

Personally I don't use Sprite3D in my project so I've no idea how to deal with it, but I think you can find a way by debugging the source code (MeshProjector and FrustumClipping, I think), just as I did to find my solution.

Good luck!
Reply all
Reply to author
Forward
0 new messages