EricHunag Posted October 9, 2015 Share Posted October 9, 2015 hi everyone~ ex:i clone 100 meshs form thesame mesh.they use thesame material, but drawcalls=100....why? how to reducing drawcall? Quote Link to comment Share on other sites More sharing options...
gryff Posted October 9, 2015 Share Posted October 9, 2015 Eric, what happens if instead of creating "clones", you create "instances" - you say they all use the same materialso it should be no problem? cheers, gryff Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 var successFun=function(newScene){ _scene=newScene; _scene.debugLayer.show(); var meshBG=newScene.getMeshByName("background"); meshBG.position= new BABYLON.Vector3(0,0,50); meshBG.scaling= new BABYLON.Vector3(1.6,2,1.5); BABYLON.SceneLoader.ImportMesh("body", "Assets/noCameraTesst/", "tortoise.babylon", this._scene, function (newMeshes2, particleSystems2, skeletons2) { this._scene.activeCamera.mode=BABYLON.Camera.ORTHOGRAPHIC_CAMERA; this._scene.activeCamera.orthoTop=350; this._scene.activeCamera.orthoBottom=-350; this._scene.activeCamera.orthoLeft=-500; this._scene.activeCamera.orthoRight=500; console.log(skeletons2); var fish=_scene.getMeshByName("body"); fish.scaling=new BABYLON.Vector3(0.08,0.08,0.08); _fishAnimated=_scene.getAnimatableByTarget(fish); fish.vx=0; fish.vy=0; console.log(_fishAnimated); var cloneFish; for(var i=0;i<100;i++) { var offx=(Math.random()*(500-(-500)))-500; var offy=(Math.random()*(350-(-350)))-350; cloneFish=fish.clone("body_"+i); cloneFish.position.x=offx; cloneFish.position.y=offy; cloneFish.vx=Math.random()*5-2.5; cloneFish.vy=Math.random()*5-2.5; var atan=Math.atan(cloneFish.vy/cloneFish.vx); if(cloneFish.vx<0){ cloneFish.rotation.z=atan; }else{ cloneFish.rotation.z=atan+Math.PI; } _aryFish.push(cloneFish); //newScene.beginAnimation(cloneFish.skeleton,0,fishAnimated.toFrame,true); }; _scene.registerBeforeRender(registerBeforeRenderFunction); }); renderFunction();};var count=0;var registerBeforeRenderFunction=function(){ //-----Brownian motion---- count++; //console.log("count>>"+count); var len=_aryFish.length; for(var i=0;i<len;i++) { var fishMotion=_aryFish[i]; if(count==50) { //console.log("name>>"+fishMotion.name+">>>position>>"+fishMotion.position) fishMotion.vx+=Math.random()*5-2.5; fishMotion.vy+=Math.random()*5-2.5; var atan=Math.atan(fishMotion.vy/fishMotion.vx); fishMotion.vx*=_friction; fishMotion.vy*=_friction; if(fishMotion.vx<0){ fishMotion.rotation.z=atan; }else{ fishMotion.rotation.z=atan+Math.PI; } } fishMotion.position.x+=fishMotion.vx; fishMotion.position.y+=fishMotion.vy; if(fishMotion.position.x>500){ fishMotion.position.x=0; }else if(fishMotion.position.x<-500){ fishMotion.position.x=500; } if(fishMotion.position.y>350){ fishMotion.position.y=0; }else if(fishMotion.position.y<-350){ fishMotion.position.y=350; } //console.log(fishMotion.position.x); }; if( count==10)count=0;};i don`t know~why drawcall is 101???how can i reducing drawcall? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 9, 2015 Share Posted October 9, 2015 Use MergeMeshes:var cloneFishArray = [];cloneFishArray.push(cloneFish);var fusionMesh = BABYLON.Mesh.MergeMeshes(cloneFishArray , true);This will create only a single drawcall Quote Link to comment Share on other sites More sharing options...
adam Posted October 9, 2015 Share Posted October 9, 2015 You might want to use SolidParticleSystem. Check out this thread:http://www.html5gamedevs.com/topic/15154-mesh-based-particle-system/ You can do stuff like this with one draw call:http://www.babylonjs-playground.com/#2KSQ1R#40 Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 Use MergeMeshes:var cloneFishArray = [];cloneFishArray.push(cloneFish);var fusionMesh = BABYLON.Mesh.MergeMeshes(cloneFishArray , true);This will create only a single drawcall i get message>>"Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices" so~how can i do? thanks everyone.. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 9, 2015 Share Posted October 9, 2015 You add an additional parameter has MergeMeshes () var cloneFishArray = [];cloneFishArray.push(cloneFish);var fusionMesh = BABYLON.Mesh.MergeMeshes(cloneFishArray , true, true); Quote Link to comment Share on other sites More sharing options...
jerome Posted October 9, 2015 Share Posted October 9, 2015 BTW, a question just for my own knowledgeIs this limit of 65K vertices per mesh a WebGL limit ? When I do some tests with the SPS I often manage a single mesh with more than 65K vertices and get no error yet. Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 You add an additional parameter has MergeMeshes () var cloneFishArray = [];cloneFishArray.push(cloneFish);var fusionMesh = BABYLON.Mesh.MergeMeshes(cloneFishArray , true, true); i add parameter after~.... mm...drawcall has been reduced...but.. render look like freeze~scene is not any change... why? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 9, 2015 Share Posted October 9, 2015 Yes it is a WebGL limit. but with the MergeMehes function, the third option to go beyond this limit. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 9, 2015 Share Posted October 9, 2015 EricHunag is that your FPS should be very low. I think your merging mesh too many polygon display. try to create several objects with MergesMesh and not a single. Quote Link to comment Share on other sites More sharing options...
jerome Posted October 9, 2015 Share Posted October 9, 2015 well, this example : http://www.babylonjs-playground.com/#2KSQ1R#98 has 70800 vertices Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 this link is my test project why use "Use MergeMeshes"....scene can`t show update.. it look like freeze..https://mega.nz/#!b0MVgaab!jsArOTl6DO-95K1lg005Gwk-PDIduqWfpxle6jdUmPU Quote Link to comment Share on other sites More sharing options...
adam Posted October 9, 2015 Share Posted October 9, 2015 this link is my test project why use "Use MergeMeshes"....scene can`t show update.. it look like freeze..https://mega.nz/#!b0MVgaab!jsArOTl6DO-95K1lg005Gwk-PDIduqWfpxle6jdUmPU If you want the fish to be move and rotate individually, then use SPS. Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 EricHunag is that your FPS should be very low. I think your merging mesh too many polygon display. try to create several objects with MergesMesh and not a single. fps number is 60FPS~my graphic card is <Nvidia GeForce GTX960> Quote Link to comment Share on other sites More sharing options...
EricHunag Posted October 9, 2015 Author Share Posted October 9, 2015 If you want the fish to be move and rotate individually, then use SPS. if i don`t use "soild particle system"...please tell me..how can i do? i hope don`t use lib,because i can learn more... Quote Link to comment Share on other sites More sharing options...
adam Posted October 9, 2015 Share Posted October 9, 2015 Look at my first response to your question above. Quote Link to comment Share on other sites More sharing options...
adam Posted October 9, 2015 Share Posted October 9, 2015 https://github.com/BabylonJSX/SolidParticleSystem Quote Link to comment Share on other sites More sharing options...
jerome Posted October 9, 2015 Share Posted October 9, 2015 I will port it in the BJS core soon, DK is OK Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 9, 2015 Share Posted October 9, 2015 More than ok actually Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.