Jump to content

Recommended Posts

Posted

Just trying to get copies (not the default instances) of models I can individually apply textures to. Neither of the following work and I can't find any helpful examples online.

 

model=Model::Load("Models/brick2.mdl",Asset::CreateNew);

 

model=(Model *)Model::Load("Models/brick2.mdl")->Copy();

 

I was trying to work off of this example with no luck and whatever I could find online.

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/asset/assetcopy-r40

Posted

 

Well, thats what he is showing in his second code example. It works in lua so it should work in c++. The only suggestion would be to try to create the copy from the original loaded model reference instead to see if it makes a difference.

 

model1 = Model:Load("Models/brick.mdl")
model2 = model1:Copy()
model2:SetPosition(1,0,1)

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

Good thought but no luck. I'll make a simpler example and see if I can submit a bug report with example. This is part of the two for loops which go through the array and create bricks:

 

level[j][i].model=(Model *)preloads_models[2]->Copy(true);
// level[j][i].model=Model::Load("Models/brick2.mdl", Asset::CreateNew);
level[j][i].model->SetPosition(i, 0, j, true);
level[j][i].model->SetRotation(90, 270, 0, true);

ran=(int)Math::Random(0, 4);
if(ran==0) level[j][i].model->GetSurface(0)->GetMaterial()->SetTexture(Texture::Load("Models/blue.tex"));
else if(ran==1) level[j][i].model->GetSurface(0)->GetMaterial()->SetTexture(Texture::Load("Models/green.tex"));
else if(ran==2) level[j][i].model->GetSurface(0)->GetMaterial()->SetTexture(Texture::Load("Models/red.tex"));
else level[j][i].model->GetSurface(0)->GetMaterial()->SetTexture(Texture::Load("Models/yellow.tex"));

 

... results in the same texture for all of the copies.

Posted

hmmm the problem there is probably due to the fact that the material itself is not an individual copy... you have the same material being applied to all the copied bricks, so just changing the texture would just apply the last texture change to the same material thats being used on everything. This should work if you apply different materials to each model copy. Or create your own material via code and then make an individual copy of it to be applied to each individual brick that you want to have a certain texture.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

this seems to work ok:

 

mymodel = Model:Load("Models/crates/crate_large.mdl")
model = {}
mat = {}
mat[0] = Material:Load("materials/developer/bluegrid.mat")
mat[1] = Material:Load("materials/developer/greengrid.mat")
mat[2] = Material:Load("materials/developer/greygrid.mat")
for i = 0,2 do
 model[i] = mymodel:Copy()
 model[i]:SetPosition(1+i,0,0)
 model[i]:SetMaterial(mat[i])
end

 

and this way as well:

 

mymodel = Model:Load("Models/crates/crate_large.mdl")
material = mymodel:GetSurface(0):GetMaterial()
model = {}
mat = {}
tex = {}
tex[0] = Texture:Load("materials/developer/bluegrid.tex")
tex[1] = Texture:Load("materials/developer/greengrid.tex")
tex[2] = Texture:Load("materials/developer/greygrid.tex")
for i = 0,2 do
 model[i] = mymodel:Copy()
 model[i]:SetPosition(1+i,0,0)
 mat[i] = tolua.cast(material:Copy(), "Material")
 mat[i]:SetTexture(tex[i])
 model[i]:SetMaterial(mat[i])
end

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

At this point I'm not exactly sure what's going on but based on what you suggested, I decided to start experimenting again. The following ended up working for me.

 

ran=(int)Math::Random(0, 4);
if(ran==0) level[j][i].model->SetMaterial(Material::Load("Models/blue.mat"));
else if(ran==1) level[j][i].model->SetMaterial(Material::Load("Models/green.mat"));
else if(ran==2) level[j][i].model->SetMaterial(Material::Load("Models/red.mat"));
else level[j][i].model->SetMaterial(Material::Load("Models/yellow.mat"));

 

I'm in your debt macklebee. Thank you for all your help!!

  • Upvote 1
  • 3 years later...
Posted

I came across this again as I was animating explosions and wanted to add a note here that using the following (adding the true argument) is also needed.

explosion[i].model->SetMaterial(Material::Load(material_filename), true);

 

Posted

It's not supposed to be true, it is Asset::Unmanaged for the flags value. But that is probably equal to 1 and true resolves to that.

My job is to make tools you love, with the features you want, and performance you can't live without.

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.

×
×
  • Create New...