T0X1N Posted January 13, 2016 Share Posted January 13, 2016 I wrote a LUA script to setup frame by frame animation, but if I try to change the material for a CSG brush during the game loop, it will not appear on the object in the game. I applied the same script I wrote to a sprite object and a cube model I exported from Blender and the material for each changed just fine during the loop. Am I doing something wrong for CSG brushes or is this a bug? Thanks! Here is the script I wrote for testing purposes: Script.speed = 10.0 -- float "Animation Speed" Script.material1 = "" --path "Material (Frame 1)" "Material File (*mat):mat|Material" Script.material2 = "" --path "Material (Frame 2)" "Material File (*mat):mat|Material" Script.material3 = "" --path "Material (Frame 3)" "Material File (*mat):mat|Material" Script.material4 = "" --path "Material (Frame 4)" "Material File (*mat):mat|Material" Script.material5 = "" --path "Material (Frame 5)" "Material File (*mat):mat|Material" Script.frames = 0 Script.currTime = 0.0 Script.currFrame = 0; Script.mat1 = nil; Script.mat2 = nil; Script.mat3 = nil; Script.mat4 = nil; Script.mat5 = nil; function Script:Start() if(self.material1 ~= "") then self.frames = self.frames + 1; self.mat1 = Material:Load(self.material1); end; if(self.material2 ~= "") then self.frames = self.frames + 1; self.mat2 = Material:Load(self.material2); end; if(self.material3 ~= "") then self.frames = self.frames + 1; self.mat3 = Material:Load(self.material3); end; if(self.material4 ~= "") then self.frames = self.frames + 1; self.mat4 = Material:Load(self.material4; end; if(self.material5 ~= "") then self.frames = self.frames + 1; self.mat5 = Material:Load(self.material5); end; end function Script:UpdateWorld() if(self.currTime >= self.speed) then self.entity:SetMaterial(self.mat2) self.currFrame = self.currFrame + 1; if( self.currFrame > self.frames ) then self.currFrame = 1 end if( self.currFrame == 1 ) then self.entity:SetMaterial(self.mat1) end if( self.currFrame == 2 ) then self.entity:SetMaterial(self.mat2) end if( self.currFrame == 3 ) then self.entity:SetMaterial(self.mat3) end if( self.currFrame == 4 ) then self.entity:SetMaterial(self.mat4) end if( self.currFrame == 5 ) then self.entity:SetMaterial(self.mat5) end self.currTime = 0; else self.currTime = self.currTime + Time:GetSpeed(); end end Quote Website | Twitter | Facebook | Steam Play Our Latest Game: Relic Rogue Link to comment Share on other sites More sharing options...
reepblue Posted January 13, 2016 Share Posted January 13, 2016 Check the sprite shader in this. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
T0X1N Posted January 13, 2016 Author Share Posted January 13, 2016 Thanks Reepblu! I checked it out and the shader does work for CSG objects. Although, I was hoping that I could get my LUA script to work with CSG objects. It would give me a lot more control over UVs on each face of the brush as the shader does not allow you to adjust the UVs also the LUA script would be alot easier for me as I don't know how to code in GLSL. 1 Quote Website | Twitter | Facebook | Steam Play Our Latest Game: Relic Rogue Link to comment Share on other sites More sharing options...
pharoseer Posted February 2, 2016 Share Posted February 2, 2016 I've encountered this as well. Same exact setup with two CSG objects, one changes color only (works) and the other changes materials (doesn't work). Looking at the log it shows that the material was loaded, it just isn't being applied to the surface. (Edit) I figured I'd include the code for my script as well: Script.primary = "" --path "Primary Material" "Material File (*mat):mat|Material" Script.alternate = "" --path "Alternate Material" "Material File (*mat):mat|Material" Script.current = 0 function Script:SetPrimary()--in self.current = 0 local material = Material:Load(self.primary) if (not material) then print("[ERROR] ChangeMaterial:SetPrimary() -> Failed to load material") material = Material:Create() material:SetColor(1, 0, 1) end self.entity:SetMaterial(material, true) end function Script:SetAlternate()--in self.current = 1 local material = Material:Load(self.alternate) if (not material) then print("[ERROR] ChangeMaterial:SetAlternate() -> Failed to load material") material = Material:Create() material:SetColor(1, 0, 1) end self.entity:SetMaterial(material, true) end Quote Link to comment Share on other sites More sharing options...
Brutile Posted February 2, 2016 Share Posted February 2, 2016 This may be something to do with the engine optimization. I've noticed that it will combine meshes that have the same material to save draw calls. It probably combines it into another object and hides the original (I'm not 100% on this though) Quote Link to comment Share on other sites More sharing options...
Josh Posted February 3, 2016 Share Posted February 3, 2016 It's not possible to do this at this time because there are brush commands that are not supported/exposed. The reason for this is the brush class is too complicated for people to use. It requires a lot of calls to different update functions and would be confusing. Brushes use faces, and the face is where the material is stored. So when you set an entity material on a brush it has no effect other than storing that value. I can expose the Brush::Build() function to Lua, but this will rebuild surfaces, normals, texture coordinates, and update the octree node, so it is not really a real-time operation. It would be better to just change the texture of the material. 2 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...
T0X1N Posted February 3, 2016 Author Share Posted February 3, 2016 I did not think of just changing the texture of the material. Nice! Thanks, Josh! I will do that then! Quote Website | Twitter | Facebook | Steam Play Our Latest Game: Relic Rogue 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.