Jump to content

optimisation technique


waverider
 Share

Recommended Posts

This is impossible to debug given the information you have provided...

None of us are psychic none of us have looked at you'r script  and have no clue what you are actually doing...

A PG or some samples of code are necessary.

Points: Make sure you are using Clones and Instances correctly.  Push Dynamic and static meshes to a quadtree.  Make sure things are being disposed of correctly.  Check your draw calls.

Link to comment
Share on other sites

lol it's a very longlist of code, but i'll try to chunk it: Maybe i'm doing the instances and cloning wrong, here's the code i used to create the lampost

Game.prototype.createLamposts = function(){

var mat = this.mat[4];
 var scale = 4;
var build = this.verybigbuilding

//gems
 var gemshapes = []
        for(var i = 0; i<10; i++){
            var myMat4 = new BABYLON.StandardMaterial("mat1", scene);
    myMat4.alpha = 1.0;
   myMat4.diffuseColor = new BABYLON.Color3(0.5, 7, 0.5);

        var icosphere = BABYLON.MeshBuilder.CreatePolyhedron("oct", {type: 4, size: 0.7}, scene);

        icosphere.scaling.y = 3
icosphere.position.z = Math.sin(i)*3
icosphere.position.x = Math.cos(i)*3
icosphere.material = myMat4


    icosphere.rotation.z = -Math.sin(i)*4
    icosphere.rotation.x = -Math.cos(i)*4
gemshapes.push(icosphere)
        }
var gems = new BABYLON.Mesh.MergeMeshes(gemshapes)

gems.scaling.set(20, 20, 20)

        //lamposts
    for(var i = 0; i<this.pos.length; i++){
var lampost = BABYLON.Mesh.CreateCylinder("cylinder", 3, 3, 3, 16, 1, scene, false)

lampost.scaling.set(16.2*scale, 505, 16.2*scale);
lampost.material = this.mat[1]
 this.lamposts.push(lampost)
this.torch = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);

this.torches.push(this.torch)



this.vent = new BABYLON.Mesh.CreateBox("vent", 60, scene)
this.vent.scaling.y = 0.4
this.vent.scaling.x = 0.4*scale
this.vent.scaling.z = 2.5*this.worldscale;
this.vent.material = this.mat[2];
var box = this.vent.getBoundingInfo()
box.boundingBox.maximum.copyFrom(new BABYLON.Vector3(30, -968, 30))

this.vent2 = this.vent.clone()

this.vents.push(this.vent)
this.vents.push(this.vent2)

if(i%9 == 0){
   

     this.verybigbuilding.rotation.y = 82.1415926535898

this.verybigbuilding.position.set(this.pos[i].x+400, this.pos[i].y, this.pos[i].z-160)
}
if(i%8 == 0){
 this.vent.scaling.y = 50
 this.vent.material = mat
 
   //this.vent.position.y = 100
}
 if(i%2 == 0){
this.torch.position.x = this.pos[i].x+60
this.torch.position.y = this.pos[i].y+80
this.torch.position.z = this.pos[i].z+(60*this.worldscale)

lampost.position.x = this.pos[i].x
lampost.position.y = this.pos[i].y
lampost.position.z = this.pos[i].z+(95*this.worldscale)

this.vent.position.x = this.pos[i].x
this.vent.position.y = this.pos[i].y+200
this.vent.position.z = this.pos[i].z

this.vent2.position.x = this.pos[i].x
this.vent2.position.y = this.pos[i].y+400
this.vent2.position.z = this.pos[i].z
}

}

for(var i = 0; i<this.pos.length; i++){
var lampost2 = BABYLON.Mesh.CreateCylinder("cylinder", 3, 3, 3, 16, 1, scene, false)

lampost2.scaling.set(19.2*scale, 505, 19.2*scale);
lampost2.material = this.mat[1]
this.torch2 = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
this.torches.push(this.torch2)
var gem2 = gems.clone()
gem2.position.y = 24
this.gems.push(gem2)
   this.lamposts.push(lampost2)
if(i%2 == 0){
    
gem2.position.set(Math.random()*this.pos[i].x, this.pos[i].y, this.pos[i].z-(60*this.worldscale))
 this.torch2.position.x = this.pos[i].x+60
this.torch2.position.y = this.pos[i].y+80
this.torch2.position.z = this.pos[i].z-(60*this.worldscale)

lampost2.position.x = this.pos[i].x
lampost2.position.y = this.pos[i].y
lampost2.position.z = this.pos[i].z-(95*this.worldscale)
}
}
}

 

Link to comment
Share on other sites

I looking at the code and you are doing huge scaling. Your scene may be too big. It's better to use small scales for an entire game. The larger your object, the bigger your ground will be and this will have an impact on performance.

Ensuring you also use octree can increase performance. There are many solutions to optimize. Look in the documentation.

Link to comment
Share on other sites

13 minutes ago, Dad72 said:

I looking at the code and you are doing huge scaling. Your scene may be too big. It's better to use small scales for an entire game. The larger your object, the bigger your ground will be and this will have an impact on performance.

Ensuring you also use octree can increase performance. There are many solutions to optimize. Look in the documentation.

size should not effect fps.

a plane that is 1 b 1 and 1 poly is the same as a plane that is 1000000000 by 1000000000 and 1 poly... same draw calls, maybe a slight difference in parsing due to large numbers but I think they would have to be astronomical to even be something noticeable.
https://www.babylonjs-playground.com/#WGTPLJ

Unless there is something I am missing.

Link to comment
Share on other sites

10 hours ago, Pryme8 said:

size should not effect fps.

a plane that is 1 b 1 and 1 poly is the same as a plane that is 1000000000 by 1000000000 and 1 poly... same draw calls, maybe a slight difference in parsing due to large numbers but I think they would have to be astronomical to even be something noticeable.

The larger the models, the larger the terrain should be with a larger subdivision if you want to make mountains. The weight of the scene also increases with large objects. The distance from the camera also increases if you want to see the sky for example. this has a noticeable impact on performance. The poly number also has an impact.

It is not with a single object that one can see it, but with a concrete scene.

It's a bit like image resolution, the bigger it is, the more the weight increases. Performance is tied to a lot of things.

Link to comment
Share on other sites

5 hours ago, Dad72 said:

The larger the models, the larger the terrain should be with a larger subdivision if you want to make mountains. The weight of the scene also increases with large objects. The distance from the camera also increases if you want to see the sky for example. this has a noticeable impact on performance. The poly number also has an impact.

It is not with a single object that one can see it, but with a concrete scene.

It's a bit like image resolution, the bigger it is, the more the weight increases. Performance is tied to a lot of things.

 

Link to comment
Share on other sites

In fact Pryme, what I want to say is that the fact of making large model requires to create great world (large skybox and large terrain, which says large terrain says more subdivision, so loss of performance because more of poly ...

By large the large mesh leads to the creation of larger world, with more models, more subdivision on the ground and others.

It is not the mesh that is given to the scale that makes losing perfs, but the consequences that entails then.

Do you see what I mean? I have experienced it.

Link to comment
Share on other sites

25 minutes ago, Dad72 said:

In fact Pryme, what I want to say is that the fact of making large model requires to create great world (large skybox and large terrain, which says large terrain says more subdivision, so loss of performance because more of poly ...

By large the large mesh leads to the creation of larger world, with more models, more subdivision on the ground and others.

It is not the mesh that is given to the scale that makes losing perfs, but the consequences that entails then.

Do you see what I mean? I have experienced it.

That is scope, not scale but yes I know understand what you are saying ^_^!

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