Jump to content

How to reducing drawcall?


EricHunag
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

 

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? 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...