wiki.sine.space | sinespace

Difference between revisions of "Scripting/SLight"

From wiki.sine.space
Jump to: navigation, search
Line 2: Line 2:
  
 
=Properties=
 
=Properties=
{{ScriptFunction|bool|Enabled|{ get; set;}|Enable/Disable this light.|5=-- Disable this object's Light Source --<br>Space.Host.ExecutingObject.Light.Enabled = false;}}
+
{{ScriptFunction|bool|Enabled|{ get; set;}|Enable/Disable this light.|5=-- Disable this object's Light Source --<br>Space.Host.ExecutingObject.Light.Enabled = false;|6=<pre>--the below script will make the object Enable/Disable it's Light component
 +
--[Add "light" reference to the Scripting Runtime component]
  
{{ScriptFunction|float|Range|{ get; set;}|Get/Set the effective range of the light source.|5=-- Change the range of the Light --<br>Space.Host.ExecutingObject.Light.Range = 8.0;}}
+
thisGameObject = Space.Host.ExecutingObject
 +
light = Space.Host.GetReference("light").Light
 +
 
 +
 
 +
OnClick = function()
 +
light.Enabled =  not light.Enabled
 +
end
 +
 
 +
 
 +
thisGameObject.AddClickable()
 +
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
 +
 
 +
{{ScriptFunction|float|Range|{ get; set;}|Get/Set the effective range of the light source.|5=-- Change the range of the Light --<br>Space.Host.ExecutingObject.Light.Range = 8.0;|6=<pre>--the below script will make a slider set the Light's range
 +
--[Add "slider" and "light" references to the Scripting Runtime component]
 +
 
 +
light = Space.Host.GetReference("light").Light
 +
slider = Space.Host.GetReference("slider").UISlider
 +
 
 +
OVC = function()
 +
light.Range = (slider.Value * 100) --(from 0 to 100)
 +
end
 +
 
 +
slider.OnValueChanged(OVC) </pre>}}
  
 
{{ScriptFunction|float|SpotAngle|{ get; set;}|The angle of the light's spotlight cone in degrees.|5=light=Space.Host.ExecutingObject.AddLight();<br>
 
{{ScriptFunction|float|SpotAngle|{ get; set;}|The angle of the light's spotlight cone in degrees.|5=light=Space.Host.ExecutingObject.AddLight();<br>
 
light.Type=2;<br>
 
light.Type=2;<br>
 
light.SpotAngle=60;
 
light.SpotAngle=60;
''--set spot angle to 60 degree.''
+
''--set spot angle to 60 degree.''|6=<pre>--the below script will make a slider set the Light's Spot Angle
}}
+
--[Add "slider" and "light" references to the Scripting Runtime component]
  
{{ScriptFunction|float|Intensity|{ get; set;}|Get/Set the intensity of the light source. (Multiplied with the light color)|5=-- Get the intensity of the Light --<br>Space.Log("Intensity: " .. Space.Host.ExecutingObject.Light.Intensity);}}
+
light = Space.Host.GetReference("light").Light
 +
slider = Space.Host.GetReference("slider").UISlider
 +
 
 +
light.Type = 2 --it has to be Spot type
 +
 
 +
OVC = function()
 +
light.SpotAngle = (slider.Value * 178) + 1 --(from 1 to 179)
 +
end
 +
 
 +
slider.OnValueChanged(OVC)</pre>}}
 +
 
 +
{{ScriptFunction|float|Intensity|{ get; set;}|Get/Set the intensity of the light source. The Intensity of a light is multiplied with the Light color. The value can be between 0 and 8.|5=-- Get the intensity of the Light --<br>Space.Log("Intensity: " .. Space.Host.ExecutingObject.Light.Intensity);|6=<pre>--the below script will make a slider set the Light's Intensity
 +
--[Add "slider" and "light" references to the Scripting Runtime component]
 +
 
 +
light = Space.Host.GetReference("light").Light
 +
slider = Space.Host.GetReference("slider").UISlider
 +
 
 +
 
 +
 
 +
OVC = function()
 +
light.Intensity = (slider.Value * 8) --(from 0 to 8)
 +
end
 +
 
 +
slider.OnValueChanged(OVC) </pre>}}
  
 
{{ScriptFunction|SVector|Color|{ get; set;}|Get/Set the color of the light.|5=
 
{{ScriptFunction|SVector|Color|{ get; set;}|Get/Set the color of the light.|5=
Line 20: Line 66:
 
local newColor = Vector.New(0.5,0.5,0); ''-- yellow color''<br>
 
local newColor = Vector.New(0.5,0.5,0); ''-- yellow color''<br>
 
obj.Light.Color = newColor;<br>
 
obj.Light.Color = newColor;<br>
''-- Now the color of the light is yellow.''}}
+
''-- Now the color of the light is yellow.''|6=<pre>--clicking the object will open a color picker that changes Light's color
 +
----[Add "light" reference to the Scripting Runtime component]
 +
 
 +
thisGameObject = Space.Host.ExecutingObject
 +
light = Space.Host.GetReference("light").Light
 +
 
 +
OnChange = function(SColor)
 +
light.Color = SColor
 +
end
 +
 
 +
OnSelect = function(SColor)
 +
light.Color = SColor
 +
end
 +
 
 +
OnCancel = function()
 +
end
 +
 
 +
OnClick = function()
 +
Space.Dialogues.ColorPicker("Pick a color","Ok", OnChange, OnSelect, OnCancel, Color.Red)
 +
end
 +
 
 +
 
 +
thisGameObject.AddClickable()
 +
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
  
 
{{ScriptFunction|SLightType|Type|{ get; set;}|4= Get/Set the type of light this source is. 0 = Directional, 1 = Point, 2 = Spot, 3 = Area.|5=
 
{{ScriptFunction|SLightType|Type|{ get; set;}|4= Get/Set the type of light this source is. 0 = Directional, 1 = Point, 2 = Spot, 3 = Area.|5=
Line 27: Line 96:
 
''-- prints "1" (default) to the console.''<br>
 
''-- prints "1" (default) to the console.''<br>
 
obj.Light.Type = 0;<br>
 
obj.Light.Type = 0;<br>
''-- Now the light type has changed to Directional.''}}
+
''-- Now the light type has changed to Directional.''|6=<pre>--Clicking the object toggles between the 4 different light types
 +
--[Add "light" reference to the Scripting Runtime component]
 +
 
 +
thisGameObject = Space.Host.ExecutingObject
 +
light = Space.Host.GetReference("light").Light
 +
 
 +
OnClick = function()
 +
 
 +
  if light.Type == 3 then
 +
    light.Type = 0
 +
  else light.Type = light.Type + 1
 +
  end
 +
 
 +
end
 +
 
 +
thisGameObject.AddClickable()
 +
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
  
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 16:58, 11 October 2021

Light sources within the Space scene.

Properties

Enabled

bool Enabled { get; set;}

Enable/Disable this light.

-- Disable this object's Light Source --
Space.Host.ExecutingObject.Light.Enabled = false;


--the below script will make the object Enable/Disable it's Light component
--[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light


OnClick = function()
light.Enabled =  not light.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

Range

float Range { get; set;}

Get/Set the effective range of the light source.

-- Change the range of the Light --
Space.Host.ExecutingObject.Light.Range = 8.0;


--the below script will make a slider set the Light's range
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider

OVC = function()
light.Range = (slider.Value * 100) --(from 0 to 100)
end

slider.OnValueChanged(OVC) 

SpotAngle

float SpotAngle { get; set;}

The angle of the light's spotlight cone in degrees.

light=Space.Host.ExecutingObject.AddLight();

light.Type=2;
light.SpotAngle=60;

--set spot angle to 60 degree.


--the below script will make a slider set the Light's Spot Angle
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider

light.Type = 2 --it has to be Spot type 

OVC = function()
light.SpotAngle = (slider.Value * 178) + 1 --(from 1 to 179)
end

slider.OnValueChanged(OVC)

Intensity

float Intensity { get; set;}

Get/Set the intensity of the light source. The Intensity of a light is multiplied with the Light color. The value can be between 0 and 8.

-- Get the intensity of the Light --
Space.Log("Intensity: " .. Space.Host.ExecutingObject.Light.Intensity);


--the below script will make a slider set the Light's Intensity
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider



OVC = function()
light.Intensity = (slider.Value * 8) --(from 0 to 8)
end

slider.OnValueChanged(OVC) 

Color

SVector Color { get; set;}

Get/Set the color of the light.

local obj = Space.Host.ExecutingObject;

Space.Log(obj.Light.Color);
-- prints "[1,1,1]" (white) to the console.
local newColor = Vector.New(0.5,0.5,0); -- yellow color
obj.Light.Color = newColor;

-- Now the color of the light is yellow.


--clicking the object will open a color picker that changes Light's color
----[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light

OnChange = function(SColor) 
 light.Color = SColor
end

OnSelect = function(SColor)
 light.Color = SColor
end

OnCancel = function()
end

OnClick = function()
Space.Dialogues.ColorPicker("Pick a color","Ok", OnChange, OnSelect, OnCancel, Color.Red)
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

Type

SLightType Type { get; set;}

Get/Set the type of light this source is. 0 = Directional, 1 = Point, 2 = Spot, 3 = Area.

local obj = Space.Host.ExecutingObject;

Space.Log(obj.Light.Type);
-- prints "1" (default) to the console.
obj.Light.Type = 0;

-- Now the light type has changed to Directional.


--Clicking the object toggles between the 4 different light types
--[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light

OnClick = function()
  
  if light.Type == 3 then
    light.Type = 0
  else light.Type = light.Type + 1
  end
  
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)