|
Shegl, Sr. Member
Posted: 17 June 2013 11:26 AM Total Posts: 134
Hello guys.
Here are code adding StaticObject with same geomertry and the same material to Stage;
Now I have kinda a MMO. There is a map. The map is 4096x4096 “virtual” cells.
The map consist of 64x64 (mini maps). So the full map consists 64x64 of mini maps.
Each mini map have terrain file. And “passing” file. He have data of passable cells in minimap, and Static Object Files (like trees, bushes, flowers etc.) in binary format.
So it can be about 500+ static objects in map. But most of them are same objects with different world placing (x,y).
Example: the map id is 1277. Map have 270 static objects of only 22 unical graphics. So I group them up. Then im loading and adding to stage by this code:
public function addStaticObject(sd:StaticData):void { var textMat:TextureMaterial = getMaterialForStaticObject(sd); var lastObject:Mesh; var merge:Merge = new Merge(false, true, false); var meshVector:Vector.<Mesh> = new Vector.<Mesh>; trace("Parsing group array with Length of " + sd.sameAsYou.length); for each(var ssd:StaticData in sd.sameAsYou) { var object:Mesh = (main_root.UOLoader.meshes[sd.getAwdFile()] as Mesh).clone() as Mesh; object.castsShadows = false; object.x = UoUtil.getEngineXbyGameY(sd.Y + all_Levels[sd.mapid].fromy); object.z = UoUtil.getEngineZbyGameX(sd.X + all_Levels[sd.mapid].fromx); object.y = UoUtil.getEngineYbyGameZ((sd.Z + 127) / 10); object.scaleX = object.scaleY = object.scaleZ = 1; if (lastObject) { meshVector.push(object); } else { lastObject = object; } } merge.applyToMeshes(lastObject, meshVector); lastObject.material = textMat; UOObjCtrl.addDisplayObject(lastObject); main_root.game.scene.addChild(lastObject); }
StaticObject have his Array of same objects with same graphics
So function is calling only one time for unique graphics.
And the objects are not showing up.
But if I erase “Merge” code and just add each mesh with his own Material. They all showing up with proper position.
What im doing wrong with Merge ?
|
Shegl, Sr. Member
Posted: 17 June 2013 06:55 PM Total Posts: 134
[ # 1 ]
I will upgrade my project from 4.0.9 to dev branch 4.1.2 (about 1-2 days) and then reply.
|
Shegl, Sr. Member
Posted: 18 June 2013 01:09 PM Total Posts: 134
[ # 2 ]
Ok, now I tested this on dev branch 4.1.2. And still showing only $lastObject mesh. Objects in $meshVector doesnt show up. Help me.
|
Shegl, Sr. Member
Posted: 19 June 2013 10:45 AM Total Posts: 134
[ # 3 ]
Could someone told me. My usage of Merge command is right ?
|
John Brookes, Moderator
Posted: 19 June 2013 02:08 PM Total Posts: 732
[ # 4 ]
Yeah ive think its a bug.
If you geometry isnt unique it disposes it before its merged all the other meshes.
eg
var geom:CubeGeometry = new CubeGeometry(); var cubesVct:Vector.<Mesh> = new Vector.<Mesh>; var rMesh:Mesh = new Mesh(geom, new ColorMaterial(0x00ff00));
var merge:Merge = new Merge(false, true, false); for (var i:uint = 0; i < 10; i++) { var mat:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff); //var mesh:Mesh = new Mesh(geom, mat); //fails var mesh:Mesh = new Mesh(new CubeGeometry(), mat); //works mesh.x = i * 150; cubesVct.push(mesh); }
merge.applyToMeshes(rMesh, cubesVct); scene.addChild(rMesh);
trace(rMesh.geometry.subGeometries.length)
edited bad idea for fix :/
Post an issue on git.
|
Fabrice Closier, Administrator
Posted: 19 June 2013 02:56 PM Total Posts: 1265
[ # 5 ]
It’s not a bug, that’s because second param is true (destroy sources). As the geometry is shared, it gets destroyed and next iteration you have a null.
|
John Brookes, Moderator
Posted: 19 June 2013 02:58 PM Total Posts: 732
[ # 6 ]
Which means you cant use merge with shared geom.
So bug no?
|
Fabrice Closier, Administrator
Posted: 19 June 2013 03:00 PM Total Posts: 1265
[ # 7 ]
if you share geom, simply set to false!
|
John Brookes, Moderator
Posted: 19 June 2013 03:03 PM Total Posts: 732
[ # 8 ]
eg mixed meshes one share geom other not.
var geom:CubeGeometry = new CubeGeometry(); var cubesVct:Vector.<Mesh> = new Vector.<Mesh>; var rMesh:Mesh = new Mesh(geom, new ColorMaterial(0x00ff00));
var merge:Merge = new Merge(false, true, false); for (var i:uint = 0; i < 10; i++) { var mat:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff); var mesh:Mesh = new Mesh(geom, mat); //fails var mySphere:Mesh = new Mesh(new SphereGeometry(), mat); mySphere.y = 300; mySphere.x = i * 150; cubesVct.push(mySphere); //var mesh:Mesh = new Mesh(new CubeGeometry(), mat); //works mesh.x = i * 150;
leaves 10 sphere geoms in memory cubesVct.push(mesh); }
merge.applyToMeshes(rMesh, cubesVct); scene.addChild(rMesh);
trace(rMesh.geometry.subGeometries.length)
|
Shegl, Sr. Member
Posted: 19 June 2013 03:31 PM Total Posts: 134
[ # 9 ]
So I cant merge in one Mesh a Vector<Mesh> with same Geom with using only 1 big geom ? So it will be same Meshes just sharing 1 material ? Is it optimising perfomance ? (Cause I was testing alot this problem, and if “false” the perfomance drops down as I didnt use Merge tool at all)
Sorry for bad english.
|
John Brookes, Moderator
Posted: 19 June 2013 03:46 PM Total Posts: 732
[ # 10 ]
Its a bug. And if its not a bug its bad design
Ill add an issue on Git.
|
seeker, Newbie
Posted: 19 June 2013 07:30 PM Total Posts: 7
[ # 11 ]
I’ve got same kind of a problem. It seems what Merge doesn’t work as it should. When merging few meshes - new mesh consist of multiple sub geometries, that’s mean it will be rendered by multiple draw calls.
Currently I have to use Merge class from previous version of Away3d (slightly modified though) which doesn’t have this issue.
|
Shegl, Sr. Member
Posted: 20 June 2013 10:27 AM Total Posts: 134
[ # 12 ]
|
seeker, Newbie
Posted: 20 June 2013 11:18 AM Total Posts: 7
[ # 13 ]
I can’t recall where I got it, and what version of Away3d it belongs to… For me, it works fine with Away3d 4.1.0
Could send it to u by e-mail, for example
|
Shegl, Sr. Member
Posted: 20 June 2013 03:57 PM Total Posts: 134
[ # 14 ]
http://pastebin.com/
.(JavaScript must be enabled to view this email address)
|