Slastraf Posted April 12, 2021 Share Posted April 12, 2021 I Instantiate a loaded model like this worldGenerator->terrainChunk = Model::Load("Models/terrain_Plane.mdl"); ... c->chunkModel = (Model*)terrainChunk->Instance(); then I applied some previously tested code on the surface of the model like this: Surface* surface = c->chunkModel->GetSurface(0); for(int i = 0; i<surface->CountVertices(); i++) { Vec3 xy = surface->GetVertexPosition(i); float height = (rand()%(3)); if(i==surface->CountVertices()*0.5) { height = -100*(rand()%(3)); cout<<"Offset height:"<<height; } if(i==0)cout<<"height at: "<<height<<endl; surface->SetVertexPosition(i, xy+Vec3(0,height*.1,0)); } surface->Update(); c->chunkModel->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); For every vertex, I set a randomly generated position. This is simplified to show the issue. All the generated model chunks are the same. A good guess would be that LE copies an already Instantiated model over, and overwrites all changes of the current one to all previous ones, or somehow ignores changes otherwise. I put a screnshot of the console and two images showing duplicate chunks. There are 9 chunks and each of them looks the same. How to fix this behaviour ? Quote Link to comment Share on other sites More sharing options...
Slastraf Posted April 12, 2021 Author Share Posted April 12, 2021 Here another screenshot without the block. The hole in the middle should only generate 3 times, as the other times the offset for this position is 0. But it is there on every chunk. Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted April 12, 2021 Solution Share Posted April 12, 2021 Use Copy() if you want to create a new model with unique geometry. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted April 12, 2021 Author Share Posted April 12, 2021 9 minutes ago, Josh said: Use Copy() if you want to create a new model with unique geometry. I was very happy with performance of Instance. Does Copy have similar performance ? Quote Link to comment Share on other sites More sharing options...
Josh Posted April 12, 2021 Share Posted April 12, 2021 1 minute ago, Slastraf said: I was very happy with performance of Instance. Does Copy have similar performance ? It will be slower under some conditions but you would need a large number of models before you saw much difference. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted April 12, 2021 Share Posted April 12, 2021 @Slastraf I would imagine you're recycling 9 chunks? If you make 8 copies of the 1 terrain model then as the player moves around I would think you could just reuse the ones the player is furthest away from so then you only need to call Copy() during initialization of your game right? Quote Link to comment Share on other sites More sharing options...
Slastraf Posted April 12, 2021 Author Share Posted April 12, 2021 6 minutes ago, Rick said: @Slastraf I would imagine you're recycling 9 chunks? If you make 8 copies of the 1 terrain model then as the player moves around I would think you could just reuse the ones the player is furthest away from so then you only need to call Copy() during initialization of your game right? That would be doable if copy takes a long time. For now the Idea is to copy it and iterate over vertices for every new chunk and hide out of bound ones. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted April 12, 2021 Author Share Posted April 12, 2021 Hmmm. I cant tell for sure but copy seems to make it lag even less than Instantiate. 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.