Jump to content

Can't Change Material to CSG Brushes During Game Loop


T0X1N
 Share

Recommended Posts

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

Play Our Latest Game: Relic Rogue

Link to comment
Share on other sites

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.

  • Upvote 1

Play Our Latest Game: Relic Rogue

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

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.

  • Upvote 2

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

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...