L B Posted November 28, 2009 Share Posted November 28, 2009 I think the title is self-descriptive. What's the simplest script to attach a point light to my model? Thanks. Quote Link to comment Share on other sites More sharing options...
T0X1N Posted November 28, 2009 Share Posted November 28, 2009 One way to do that is to use light:SetParent(model) light = your light entity and model = your model Quote Website | Twitter | Facebook | Steam Play Our Latest Game: Relic Rogue Link to comment Share on other sites More sharing options...
L B Posted November 28, 2009 Author Share Posted November 28, 2009 One way to do that is to use light:SetParent(model) light = your light entity and model = your model How would I access these objects? I just want to place my streetlamp entity and it already has the light on it. I copied the code from the point light script into the streetlamp script, and it works fine. I have a point light, but at the origin of the model, which is way too low. How would I go making "entity.light" move up? I tried "entity.light:Move(0, -2, 0)" but this doesn't work. dofile("Scripts/base.lua") -- We need the base class entity function InitDialog(grid) base_InitDialog(grid) group=grid:AddGroup("Light") group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048") group:AddProperty("linearoffset",PROPERTY_FLOAT,"0,1,2","Linear offset") group:AddProperty("multoffset",PROPERTY_FLOAT,"0,1,2","Multiplicative offset") group:AddProperty("Range",PROPERTY_FLOAT,"1,100,0") group:Expand(1) end function Spawn(model) local entity=base_Spawn(model) entity.model=model entity.light=CreatePointLight(10,model) return entity end function GetKey( model, key, value ) local entity=entitytable[model] if entity==nil then return value end if entity.model==nil then return end if entity.light==nil then return base_GetKey(model,key,value) else if key=="linearoffset" then return entity.light:GetShadowOffset(0,0)--..","..entity.light:GetShadowOffset(0,1)..","..entity.light:GetShadowOffset(0,2) elseif key=="multoffset" then return entity.light:GetShadowOffset(1,0)--..","..entity.light:GetShadowOffset(1,1)..","..entity.light:GetShadowOffset(1,2) elseif key=="range" then return entity.light:GetRange() else return base_GetKey(model,key,value) end end end function SetKey(model, key,value) local entity=entitytable[model] if entity==nil then return 1 end if entity.model==nil then return 1 end if entity.light==nil then base_SetKey(model,key,value) else if key=="resolution" then if value=="0" then entity.light:SetShadowmapSize(256) elseif value=="1" then entity.light:SetShadowmapSize(512) elseif value=="2" then entity.light:SetShadowmapSize(1024) elseif value=="3" then entity.light:SetShadowmapSize(2048) end elseif key=="range" then entity.light:SetRange(value) elseif key=="shadowresolution" then resolution=entity.light:GetShadowmapSize() if resolution==256 then return 0 elseif resolution==512 then return 1 elseif resolution==1024 then return 2 elseif resolution==2048 then return 3 else return -1 end elseif key=="multoffset" then entity.light:SetShadowOffset(entity.light:GetShadowOffset(0,0),value,0) elseif key=="linearoffset" then entity.light:SetShadowOffset(value,entity.light:GetShadowOffset(1,0),0) else return base_SetKey(model,key,value) end end return 1 end --[[ dofile("Scripts/baseclass.lua") -- We need the base class entity dofile("Scripts/table.lua") -- We need the table.Inherit function -- Set this script"s Entity table to an inherit of BaseClass"s entity table EntityNew = { } Entity = table.Inherit(EntityNew, Entity) function Entity:Spawn(model) if (model == nil) then Notify("Entity passed to Entity:Spawn is nil") end Entity.BaseClass:Spawn(model) -- Since the entity object is passed to the BaseCLass spawn, it is in Entity.BaseClass.model, we need to either remove the above line and uncomment the one below, or simply leave both -- If you are wondering why Entity.model isn"t inherited at the top of the script when we called table.Inherit, it is because we had not yet defined an Entity.model variable -- You will come to notice that variables we assign via BaseClass functions AFTER inheritence will not exist from this Entity scope. We can still access them via Entity.BaseClass.variablename --Entity.model = Entity.BaseClass.model -- Hold onto you for later use and add it to this scope self.model = model model:SetKey("intensity","1") self.light = CreatePointLight(10,model) self.speed=1.0 end function Entity:SetKey(key,value) if self.model==nil then return 1 end if self.light==nil then self.BaseClass:SetKey(key,value) else if key=="resolution" then if value=="0" then self.light:SetShadowmapSize(256) elseif value=="1" then self.light:SetShadowmapSize(512) elseif value=="2" then self.light:SetShadowmapSize(1024) elseif value=="3" then self.light:SetShadowmapSize(2048) end elseif key=="muloffset" then self.light:SetShadowOffset(0,tonumber(value),0) elseif key=="range" then self.light:SetRange(value) elseif key=="shadowresolution" then resolution=self.light:GetShadowmapSize() if resolution==256 then return 0 elseif resolution==512 then return 1 elseif resolution==1024 then return 2 elseif resolution==2048 then return 3 else return -1 end else return self.BaseClass:SetKey(key,value) end end return 1 end function Entity:InitDialog(grid) self.BaseClass:InitDialog(grid) group=grid:AddGroup( "Light" ) group:AddProperty( "Resolution", "1|256,512,1024,2048", PROPERTY_CHOICE, "" ) group:AddProperty( "muloffset","|0,1,2",PROPERTY_FLOAT,"Mult offset" ) group:AddProperty( "range","|1,100,0",PROPERTY_FLOAT,"" ) group:Expand(1) end function Entity:ReceiveMessage(message,extra) if message=="toggle" then if self.model:Hidden()==1 then self.model:Show() else self.model:Hide() end else end end ]]-- Quote Link to comment Share on other sites More sharing options...
Josh Posted November 28, 2009 Share Posted November 28, 2009 Either: light:Move(Vec3(1,2,3)) light:Movef(1,2,3) I will try to add the "f" version for every command. 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...
Richard Simpson Posted November 28, 2009 Share Posted November 28, 2009 Either: light:Move(Vec3(1,2,3)) light:Movef(1,2,3) I will try to add the "f" version for every command. What does the "F" do? Quote Intel core 2 quad 6600 | Nvidia Geforce GTX460 1GB | 2GB DDR2 Ram | Windows 7. Google Sketchup | Photoshop | Blender | UU3D | Leadwerks Engine 2.4 Link to comment Share on other sites More sharing options...
L B Posted November 28, 2009 Author Share Posted November 28, 2009 What does the "F" do? Most likely "Fast". Quote Link to comment Share on other sites More sharing options...
Josh Posted November 28, 2009 Share Posted November 28, 2009 float 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...
L B Posted November 28, 2009 Author Share Posted November 28, 2009 float Fail. >.< Quote Link to comment Share on other sites More sharing options...
Richard Simpson Posted November 28, 2009 Share Posted November 28, 2009 Ah Quote Intel core 2 quad 6600 | Nvidia Geforce GTX460 1GB | 2GB DDR2 Ram | Windows 7. Google Sketchup | Photoshop | Blender | UU3D | Leadwerks Engine 2.4 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.