gamecreator Posted March 14, 2015 Share Posted March 14, 2015 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 Quote Link to comment Share on other sites More sharing options...
Jazz Posted March 15, 2015 Share Posted March 15, 2015 What about http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitycopy-r172 Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
Genebris Posted March 15, 2015 Share Posted March 15, 2015 I thought that same model file can never have different materials. They are always instances. No, sorry. Now I see they are always instanced only in the editor. Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 What about http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitycopy-r172 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) 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted March 15, 2015 Author Share Posted March 15, 2015 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. Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 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. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 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 2 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted March 15, 2015 Author Share Posted March 15, 2015 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!! 1 Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 25, 2018 Author Share Posted December 25, 2018 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); Quote Link to comment Share on other sites More sharing options...
Josh Posted December 27, 2018 Share Posted December 27, 2018 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. 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...
gamecreator Posted December 27, 2018 Author Share Posted December 27, 2018 I think you're talking about Material::Load. I was talking about SetMaterial, the bool argument to set it to recursive since I guess it's false by default. 1 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.