Jump to content

first post here...how to swap object, textures, material or shader???


10shu
 Share

Recommended Posts

Hi,

 

This is my first post here. I hope I wont break any rules of this forum...I apologize right now in case i do...

 

I m a 40 year old game dev. I m mostly an artist although I ve got some tech knowledge.

and yes, english isnt my primary language...:)

 

I m currently working for a big game publisher, but I always have few games project at home I work on my free time. some of which i complete other end up just being test...

 

Anyhow, I ve started to play around with LeadWerks, And I love it...However I have zero Lua knowledge.

A friend programmer will help me later on when he is done in is current project but for now I m on my own.

 

I Followed the tutorials, and I did tweaked few script to do what I need so far but I reached an wall last night...

 

So this is my Issues:

 

-I ve got that lamp in my level. (something like this:

https://s7d2.scene7.com/is/image/BedBathandBeyond/5612514187030p?229$ )

 

-where the light buld is I ve added an omnie

 

-Ive set the lamp object so it do not cast shadow.

 

-To simulate the light going through the lamp shade I ve added on self illum material.

 

-Finally I ve added a activator script on the omnie and a switch button script on the light switch

 

 

OK, so this work fine...the light look nice when it s switched on.

and the button let me switch it off...

However, when my light is turned off I still have the shade self illum

 

Is there a script somewhere That would I could add to my lamp shades so I can change the shaders, or swap the object, or change the textures loaded into the material???

 

Thanks

Link to comment
Share on other sites

At the moment you switch the light on/off in the script you can either set a new material or set a new texture in the current material.

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetmaterial-r183

http://www.leadwerks.com/werkspace/page/api-reference/_/material/materialsettexture-r184

 

If you post your light script we can help you even better.

Link to comment
Share on other sites

At the moment you switch the light on/off in the script you can either set a new material or set a new texture in the current material.

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetmaterial-r183

http://www.leadwerks.com/werkspace/page/api-reference/_/material/materialsettexture-r184

 

If you post your light script we can help you even better.

 

Thank s for that...I ll check those link tonite, And will post more here if I cannot make it work

Link to comment
Share on other sites

OK So after many tried, and a lot of copy and paste from other script i finally managed to do something...

Dont get me wrong it dont work smile.png but I ve made progress...

 

So this is what I ve got:

 

I ve managed to load 2 materials.( Well I m sure the first one is loaded)

and to add the toggle for the flowgraph editor.

 

Capture2.jpg

 

So my script is attached to the entity and in the flowgraph editor and it s linked to the switch light button

 

However when I press the button the script crash with this error

 

44 : attempt to index field 'setMaterial' (a nil value)

 

function App:Start()


--Create a material
local material1 = Material:Load("Materials/Concrete/concrete_clean.mat")
local material2 = Material:Load("Materials/Concrete/concrete_dirty.mat")

--Load and apply a shader
local shader = Shader:Load("Shaders/Model/diffuse.shader")
material:SetShader(shader)
shader:Release()

--Create a model and apply the material
-- local model = Model:Sphere()
-- model:SetMaterial(material)
-- model:SetPosition(0,0,2)

return true
end

function App:Loop()

if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end

Time:Update()
self.world:Update()
self.world:Render()
self.context:Sync()

return true
end


--function ToggleMaterial ()

-- end

function Script:ToggleMaterial()--in
if not self.entity.setMaterial:Hidden() then
if (state == 0) then
self.setMaterial(materialOn)
else self.setMaterial(materialOff)
state = not state
end
end
end

 

What do I do wrong?

Please keep in mind I dont know programing. I ve started with what you provided to me.. and added on top of it...Although I kind of understand what the script is doing I still find it difficult to fully understand everything here... so they maybe some really noob stupid thing here tongue.png

 

Thanks.

 

ohh and you asked for it so, this is the script I used for the light: (but maybe at tihs point its not nessesary anymore?)

 

-- activate light
function Script:Activate()--in
if self.entity:Hidden() then
self.entity:Show()
self.component:CallOutputs("Activate")
end
end
-- deactivate light
function Script:Deactivate()--in
if not self.entity:Hidden() then
self.entity:Hide()
self.component:CallOutputs("Deactivate")
end
end
-- toggle light
function Script:Toggle()--in
if not self.entity:Hidden() then
self:Deactivate()
else
self:Activate()
end
end

 

 

got it from this forum.

work great!

I used part of it to add the toggle part of my material script.

 

Thanks again for you help

Link to comment
Share on other sites

First off: it is good that you are trying yourself. So hats of to you.

 

Secondly: I would not recommend altering the app.lua script for the following reasons:

  • The behaviour you are looking for is entity related. The app lua is about managing the game loop.
  • The app,lua is soon to be deprecated. If you really must alter the main loop, use main.lua.

 

Thirdly: so this is your setup right: You have a lamp and you have a light.

 

The light still has this script:

-- activate light
function Script:Activate()--in
if self.entity:Hidden() then
self.entity:Show()
self.component:CallOutputs("Activate")
end
end
-- deactivate light
function Script:Deactivate()--in
if not self.entity:Hidden() then
self.entity:Hide()
self.component:CallOutputs("Deactivate")
end
end
-- toggle light
function Script:Toggle()--in
if not self.entity:Hidden() then
self:Deactivate()
else
self:Activate()
end
end

 

The lamp model has a new script attached. Drag both items into the flowgraph editor and you can hook them up. You can also use a toggle function instead of 2 separate functions.

Script.material1;
Script.material2;

function Script:Start()
self.material1 = Material:Load("Materials/Concrete/concrete_clean.mat")
self.material2 = Material:Load("Materials/Concrete/concrete_dirty.mat")
end

-- Set material 1
function Script:Material1()--in
self.entity:SetMaterial(self.material1)
end


-- Set material 1
function Script:Material2()--in
self.entity:SetMaterial(self.material2)
end

Link to comment
Share on other sites

I m sorry but its not working.

I must be doing something wrong.

 

Got this error message:

 

: 1 : '=' expected near ';'

 

it s this line : Script.material1;

I try to add a = but it do not work.

so I hided those lines

 

--Script.material1;
--Script.material2;
function Script:Start()
self.material1 = Material:Load("Materials/Concrete/concrete_clean.mat")
self.material2 = Material:Load("Materials/Grass/Grass01.mat")
end-- Set material 1
function Script:Material1()--in
self.entity:SetMaterial(self.material1)
end

-- Set material 1
function Script:Material2()--in
self.entity:SetMaterial(self.material2)
end

 

my flowcharts look like this now:Capture2_3.jpg

 

Lightswitch:PushButton -> its the light switch object.

Box 3:set textures -> its should be the lampshade currently it s a test cube, the new script you gave me is applied to this object.

SpotLight4 :activate -> the spot light I turn on when I switch on

 

I try to look into a 2 node solution but I dont see how that would work.?!

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