[Papervision3D] MeshBatch (sorting multiple meshes by face)
Simon Oliver
psifli at yahoo.com
Mon Dec 18 11:19:12 EST 2006
Some of the scenes I've been playing around with work a bit better when all the faces for some meshes are combined and then z-sorted all in one batch (rather than z-sorting the average vertex pos per object) if their shape is a bit peculiar (large objects such as floors, walls, boxes etc when compared with smaller objects inside them perhaps). Was thinking a MeshBatch class might be useful where you can combine multiple Meshes into a single entity to allow all faces to be sorted together. The class below does this, and you can use it as you would add to a scene, ie:
_meshBatch=new MeshBatch();
blocks= new Ase( brickMaterial, "blocks_01.ase" ,1);;
room= new Ase( material, "room_01.ase" ,1);;
floor= new Ase( floorMaterial, "floor_01.ase" ,1);;
_meshBatch.push(blocks);
_meshBatch.push(floor);
_meshBatch.push(room);
scene.push(_meshBatch);
Hope its of use :)
Also, the ASE issue with the Maya exporter still seems to be there (the use of \r\n rather than just \n). Reckon we could switch to just \n ? ta!
package org.papervision3d.objects {
import org.papervision3d.objects.Mesh;
import org.papervision3d.core.proto.DisplayObject3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Sprite
public class MeshBatch extends DisplayObject3D
{
public var meshes :Array;
public var faces :Array;
public var showFaces :Boolean;
public var sortFaces :Boolean;
public function MeshBatch()
{
super();
this.meshes = new Array();
this.faces = new Array();
//showFaces=true;
sortFaces=true;
}
public function push( mesh:Mesh ):void
{
meshes.push(mesh);
}
public override function project( camera :CameraObject3D ):void
{
var mesh:Mesh;
for (var i:Number=0;mesh=meshes[i];i++)
mesh.project(camera);
}
public override function render( scene :SceneObject3D ):void
{
this.faces = new Array();
var mesh:Mesh;
for (var i:Number=0;mesh=meshes[i];i++)
this.faces=this.faces.concat(mesh.faces);
var faces:Array = this.faces;
if( this.sortFaces )
faces.sortOn( 'screenZ', Array.DESCENDING | Array.NUMERIC );
var container :Sprite = this._container || scene.container;
var showFaces :Boolean = this.showFaces;
var rendered :Number = 0;
var face :Face3D;
for( var j:int = 0; face = faces[j]; j++ )
{
if( face.visible )
rendered += face.render( container, showFaces );
}
scene.stats.rendered += rendered;
}
}
}
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20061218/34da1e91/attachment.htm
More information about the Papervision3D
mailing list