I guess you are having those problems trying to spawn new sprite instances frequently ? Try reusing them
On Tue, Jun 14, 2011 at 7:33 AM, Jahiro <macro.mar...@gmail.com> wrote: > Hi Fabrice, > > I'd like use the Merge class on a group of Sprite3Ds, is that > possible? It looks like the Merge class only deals with Meshes, and > Sprite3D doesn't extend Mesh. > > I'm struggling with performance issues having lots of Sprite3Ds on the > stage at one time - would be great if I could fix it with the Merge > class. > > Any ideas? > > Thanks > > On May 27, 12:25 am, Fabrice3D <fabric...@gmail.com> wrote: > > Hi all, > > Merge class is updated (in Git repo) > > various issues were fixed and lots of enhancement/rewriting was done. > > > > in big lines what is now different with previous version: > > > > 1: > > constructor has changed, the first param "objectspace" is now the third > param. > > simply because in 99% of cases, you do not need object space > > > > so where you did say, new Merge(false, true, true); , you can update your > code by just getting rid of first param as its by default false > > becomes --> new Merge(true, true); > > > > 2: > > Added new method, as I've seen already several cases where you were > merging during a loop. > > public function applyToMeshes(receiver:Mesh, meshes:Vector.<Mesh>):Mesh > > (see first snippet example) > > > > 3: > > it takes now in account, scale, and rotations of the to be merged items, > but also respects reciever rotations and scale. > > It is faster and uses less resource than previous version > > It supports now also cloned meshes inputs and even empty mesh (new > Mesh()) as receiver > > > > merging multiple meshes > > if you merge for instance from a loaded model or if you loop to generate > a merged mesh > > do not use "apply", instead, use "applyToMeshes" or "applyToContainer" > > apply would work but would ask way more processing time. > > > > A few examples with few variations in use. Covering probably most of your > possible cases. > > > > merge.applyToMeshes > > private function mergeUsingVectors() : void > > { > > var iteration : uint = 20; > > var increase : Number = 200; > > var offset:Number = -((increase *iteration) *.5); > > > > var merge:Merge = new Merge(false, false); > > > > var bmd:BitmapData = new > BitmapData(64,64,false,0xFF00FF); > > var mat:BitmapMaterial = new > BitmapMaterial(bmd,true,false,true); > > mat.lights = [_light1, _light2]; > > > > var sphere : Sphere; > > var sphereReceiver : Sphere; > > > > var meshes:Vector.<Mesh> = new Vector.<Mesh>(); > > var i:uint; > > var scaleIncrease:Number = .1; > > var nscale:Number = 0.2; > > for (i = 0;i < iteration; ++i) { > > sphere = new Sphere(mat, 100*nscale, 6, > 6); > > sphere.x = offset + (i*increase); > > sphere.y = Math.sin(sphere.x)*100; > > meshes.push(Mesh(sphere)); > > > > nscale+=scaleIncrease; > > } > > > > > _view.scene.addChild(merge.applyToMeshes(Mesh(meshes.shift()), meshes)); > > } > > > > merge.applyToContainer > > in this case we loop, but this could be your loaded model (make sure if > your model have more material to set keepMaterial to true) > > > > private function mergeWithContainer() : void > > { > > var _rows : Number = 8; > > var _space : Number = 250; > > var _radius : Number = 200; > > > > var merge:Merge = new Merge(false,true); > > > > var sphere : Sphere; > > var container:ObjectContainer3D = new > ObjectContainer3D(); > > > > var z:uint; > > var y:uint; > > var x:uint; > > for (z = 0;z < _rows; ++z) { > > for (y= 0;y < _rows;++y) { > > for (x = 0;x < _rows;++x) { > > sphere = new Sphere(null, > _radius, 6, 6, true ); > > sphere.x = > -(_rows*(_radius+_space)*0.5) + x * _radius * 2 + (x*_space); > > sphere.y = > -(_rows*(_radius+_space)*0.5) + y * _radius * 2 + (y*_space); > > sphere.z = > -(_rows*(_radius+_space)*0.5) + z * _radius * 2 + (z*_space); > > > container.addChild(sphere); > > } > > } > > } > > > > var mergedMesh:Mesh = > merge.applyToContainer(container, "myMergedMesh"); > > > > var bmd:BitmapData = new > BitmapData(64,64,false,0xFF00FF); > > var mat:BitmapMaterial = new > BitmapMaterial(bmd,true,false,true); > > mat.lights = [_light1, _light2]; > > > > mergedMesh.material = mat; > > _view.scene.addChild(mergedMesh); > > } > > > > merge.apply > > in this case, notice that the scale and rotations of originals are > respected, if you compare with the green non merged cubes placed right > above. > > > > private function singleMerge() : void > > { > > //we want to keep the materials different and > clear the source > > var merge:Merge = new Merge(true, true); > > > > var matcube:BitmapMaterial = new > BitmapMaterial(new BitmapData(256,256, false, 0xFF0000)); > > var matcube1:BitmapMaterial = new > BitmapMaterial(new BitmapData(256,256, false, 0x0000FF)); > > matcube.lights = [_light1, _light2]; > > matcube1.lights = [_light1, _light2]; > > > > var cube1:Cube = new Cube(matcube, 800, 400, > 100); > > var cube2:Cube = new Cube(matcube1, 800, 400, > 100); > > > > cube1.x = 600; > > cube2.x = -600; > > cube1.z = cube2.z = 0; > > cube1.y = cube2.y = 0; > > > > //here an example where the reciever as scale and > rotations > > cube1.rotationY = -45; > > cube2.rotationY = 45; > > > > cube1.scaleY = 2; > > cube2.scaleY = 2; > > > > merge.apply(cube1, cube2); > > _view.scene.addChild(cube1); > > > > // the same settings but higher on y not merge to > check results, shown here in green > > var matcube2:BitmapMaterial = new > BitmapMaterial(new BitmapData(256,256, false, 0x00FF00)); > > matcube2.lights = [_light1, _light2]; > > var cube3:Cube = new Cube(matcube2, 800, 400, > 100); > > var cube4:Cube = new Cube(matcube2, 800, 400, > 100); > > > > cube3.x = 600; > > cube4.x = -600; > > cube3.z = cube4.z = 0; > > cube3.y = cube4.y = 800; > > > > cube3.rotationY = -45; > > cube4.rotationY = 45; > > > > cube3.scaleY = 2; > > cube4.scaleY = 2; > > > > _view.scene.addChild(cube3); > > _view.scene.addChild(cube4); > > > > } > > > > example of empty reciever and the use of clones > > private function mergeWithClones() : void > > { > > var merge:Merge = new Merge(true, true); > > > var matcube:BitmapMaterial = new > BitmapMaterial(new BitmapData(256,256, false, 0xFF0000)); > > matcube.lights = [_light1, _light2]; > > > > var cube:Cube = new Cube(matcube, 800, 400, 100); > > var meshes:Vector.<Mesh> = new Vector.<Mesh>(); > > > > //empty mesh reciever > > var receiver:Mesh = new Mesh(); > > var cubeclone:Mesh; > > > > var i:uint; > > var iteration : uint = 20; > > var increase : Number = 200; > > var offset:Number = -((increase *iteration) *.5); > > > > for (i = 0;i < iteration; ++i) { > > cubeclone = cube.clone() as Mesh; > > cubeclone.x = offset + (i*increase); > > cubeclone.y = i*50; > > meshes.push(cubeclone); > > } > > > _view.scene.addChild(merge.applyToMeshes(receiver, meshes)); > > cube = null; > > } > > > > I'll add soon these in the examples section. > > > > cheers, > > Fabrice > -- Michael Ivanov ,Programmer Neurotech Solutions Ltd. Flex|Air |3D|Unity| www.neurotechresearch.com http://blog.alladvanced.net Tel:054-4962254 mich...@neurotech.co.il t...@neurotech.co.il