Jump to content

Instantiate() Ignores changes to model ?


Slastraf
 Share

Go to solution Solved by Josh,

Recommended Posts

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 ?

Theomenofpenumbra Screenshot 2021.04.12 - 13.18.27.97.png

Theomenofpenumbra Screenshot 2021.04.12 - 13.18.21.34.png

Bild_2021-04-12_131939.png

Link to comment
Share on other sites

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.

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

@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?

Link to comment
Share on other sites

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.

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.

 Share

×
×
  • Create New...