Lunarovich Posted March 15, 2015 Share Posted March 15, 2015 Hello! I'm puzzled by the SetMaterial() behavior. I have a scene with randomly disposed cubes made in the editor. When I do the mouse pick on a cube, I check its material, and switch/toggle the material of the cube. I have two separate materials, one with and the other without the emission texture/shader. Now, when I pick the closest cube and toggle its material, some of the other cubes (but not all) get the same material. Sometimes only one cube switches material, sometimes two or more. Everytime the same group of cubes react to the single cube picking/material setting, so apparently that's not something random. For the sake of completeness, I have tried to make individual cubes both with brushes and CTRL-axis drag & drop. The result is similar. Now, I suppose that this behavior has something to do with the Entity:Instance() VS Entity:Copy(). But could be totally wrong N.B. I use the closest entity option in the Pick routine. Here is my pick routine: local window = Window:GetCurrent() local context = Context:GetCurrent() if (window:MouseHit(1)) then local pickinfo = PickInfo() if (self.camera:Pick(context:GetWidth() / 2, context:GetHeight() / 2,pickinfo,0,true)) then if (pickinfo.entity:GetMaterial() == self.blokMatNormal) then pickinfo.entity:SetMaterial(self.blokMatEmissive) else pickinfo.entity:SetMaterial(self.blokMatNormal) end end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 hmmm thats weird... it does seem to be random on which ones it picks - but it consistently picks the same ones to change. At first i thought it had something to do with which material was used during its creation but that doesn't seem to be the case. 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...
Lunarovich Posted March 15, 2015 Author Share Posted March 15, 2015 I've tried to release a cube upon picking it, and the engine released every other connected cube. It probably has to do something with the way brushes work. I'm testing the behavior on the models right now... Just tested it. I get the same behavior with models and with prefabs. Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 It probably has to do something with the way brushes work. yeah that seems to be the issue. I added mass to some of the csg primitives and now they only change material by themselves. I assume adding an empty script will do the same. Edit-- yes, adding an empty script or mass will prevent this issue with CSG objects. 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...
Lunarovich Posted March 15, 2015 Author Share Posted March 15, 2015 Yeah, adding scripts effectively solved the issue with models (EDIT: with prefabs made out of brushes) as well as with brushes. Thanks! Is there some logical reason why adding scripts would help in this case? Does adding script do some under the hood "individualization" of the object? If yes, in what exactly consists this individualization? P.S. Sorry for philosophical terms. I'm a philosopher by profession Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 not sure why adding a script to a model would have made any difference - but with the CSG primitives, if it has mass or a script then it isn't collapsed into the scene when loaded in your game. 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...
Josh Posted March 15, 2015 Share Posted March 15, 2015 Brushes are collapsed when loaded, unless they have mass or a script, so what you think is a single object is actually a big cluster of merged objects. In the case of models, if you change the material of one instance, all other models of the same file will get the same material (actually, their surface will, since the surface is shared across them all). 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...
macklebee Posted March 15, 2015 Share Posted March 15, 2015 In the case of models, if you change the material of one instance, all other models of the same file will get the same material (actually, their surface will, since the surface is shared across them all). Why would adding a script effect this - at least based on OP's last post? havent tried it yet myself. 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...
Lunarovich Posted March 15, 2015 Author Share Posted March 15, 2015 Here, I have cubes made out of brushes with scripts attached to every cube: It works really neat in the game. Just as expected. I can turn on/off individual cubes with camera mouse picking. If I make a prefab out of the single cube (made using CSG, ie. brushes), it still works as intended. However, it does not work with models (even if I attach scripts to them). This agrees with what Josh has said: In the case of models, if you change the material of one instance, all other models of the same file will get the same material (actually, their surface will, since the surface is shared across them all). But why does it work then with prefabs (with scripts attached)? Aren't prefabs made out of brushes internally turned into models? And finally, why does it work with individual pieces of CSGs with scripts attached? P.S. Josh, thanks for this nice framework. Really enjoying it! Haven't found a 3D framework so transparent and so easy to use, but still not simplistic a bit... And I've tried a lot of them Quote Link to comment Share on other sites More sharing options...
Josh Posted March 15, 2015 Share Posted March 15, 2015 Why would adding a script effect this - at least based on OP's last post? havent tried it yet myself. I don't think it does, I think he is probably confused in his description. Nice glasses, BTW. 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...
Lunarovich Posted March 15, 2015 Author Share Posted March 15, 2015 I don't think it does, I think he is probably confused in his description. I've already corrected/edited the post #5 and said in post #9 that adding scripts to same instances of models do not make models have separate materials. So, their behavior is expected and explained (which puts my mind at ease). However, the question remains in respect to CSG. Why does adding scripts works in the case of objects made using brushes? And why random group of these objects react in the same manner - get / do not get the assigned material - on material change (via mouse picking, which is inessential here)? Does it stem from the fact that Leadwerks converts CSG objects with scripts, under the hood and in the runtime / on the map creation, into separate models, ie. models with separate surfaces? Quote Link to comment Share on other sites More sharing options...
Josh Posted March 15, 2015 Share Posted March 15, 2015 In order to improve performance, brushes are normally assumed to be static, so they are collapsed into big models in the scene. The clusters are defined by the scene octree, so instead of having hundreds of boxes, you just have a few large models in the scene, which renders much faster. 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...
Lunarovich Posted March 15, 2015 Author Share Posted March 15, 2015 Thanks for the answer! Quote Link to comment Share on other sites More sharing options...
Lunarovich Posted March 16, 2015 Author Share Posted March 16, 2015 I was going through this and he says that you need to give non-zero mass or attach a script to the CSG object in order to turn it into entity. Concerning what Josh have said, maybe he should have added, an entity with a separate surface, since large models made out of CSG are geometries turned into entities silently by Leadwerks, as I believe. P.S. Maybe I'm overdoing it, but it's just my cartesian need to have a clear and distinct understanding of the subject matter Quote Link to comment Share on other sites More sharing options...
Olby Posted March 16, 2015 Share Posted March 16, 2015 It's very simple. If CSG meshes have no scripts and have 0 mass then they get merged into static scene geometry (upon loading). In cases when mass is specified or scripts attached they are turned into individual entities. You can try this with a sphere. Create a CSG sphere, add mass and make it rigid body. Run the game and it will bounce around the scene. Quote Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64) Link to comment Share on other sites More sharing options...
Lunarovich Posted March 16, 2015 Author Share Posted March 16, 2015 Thanks! Is a static scene geometry, as you've said, an object of its own kind or is it a static model, ie. a rigid body entitiy with a mass 0? I mean, I know I'm pestering a bit with this question, but no one seems to give me the final answer... Quote Link to comment Share on other sites More sharing options...
Josh Posted March 26, 2015 Share Posted March 26, 2015 They get turned into a model entity that uses a polygonal mesh collision shape generated from the same geometry, with a mass of zero. 1 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...
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.