diff --git a/examples/5-audio/Ambient_Sound_Example.lua b/examples/5-audio/Ambient_Sound_Example.lua new file mode 100644 index 00000000..42136176 --- /dev/null +++ b/examples/5-audio/Ambient_Sound_Example.lua @@ -0,0 +1,25 @@ +--require getScriptFilename so we can add current path to modelSearch Path +require("getScriptFilename") +vrjLua.appendToModelSearchPath(getScriptFilename()) + +--find the path of an MP3 file and store it in "mp3Path" variable +mp3Path = vrjLua.findInModelSearchPath("SampleMP3.mp3") +--find the path of a WAV file and store it in "wavPath" variable +wavPath = vrjLua.findInModelSearchPath("SampleWAV.wav") + +--In order to play the sound, we need to change to the correct API (must uncomment one of the following) +--1)Use OpenAL for WAV files +snx.changeAPI("OpenAL") +--2)Use Audiere for MP3 files +--snx.changeAPI("Audiere") + +--create a sound info object +soundInfo = snx.SoundInfo() +-- set the filename attribute of the soundFile (path to your sound file) +soundInfo.filename = wavPath +--create a new sound handle and pass it the filename from the soundInfo object +soundHandle = snx.SoundHandle(soundInfo.filename) +--configure the soundHandle to use the soundInfo +soundHandle:configure(soundInfo) +--play or "trigger" the sound +soundHandle:trigger(1) diff --git a/examples/5-audio/SampleMP3.mp3 b/examples/5-audio/SampleMP3.mp3 new file mode 100644 index 00000000..515a1c4f Binary files /dev/null and b/examples/5-audio/SampleMP3.mp3 differ diff --git a/examples/5-audio/SampleWAV.wav b/examples/5-audio/SampleWAV.wav new file mode 100644 index 00000000..96a0702f Binary files /dev/null and b/examples/5-audio/SampleWAV.wav differ diff --git a/examples/advanced/light_example.lua b/examples/advanced/light_example.lua new file mode 100644 index 00000000..aaf22448 --- /dev/null +++ b/examples/advanced/light_example.lua @@ -0,0 +1,68 @@ +require("getScriptFilename") +vrjLua.appendToModelSearchPath(getScriptFilename()) + +--load in an example model (so we can see the effect of our lights) +factory = Transform{ + orientation = AngleAxis(Degrees(-90), Axis{1.0, 0.0, 0.0}), + scale = ScaleFrom.inches, + Model("../models/basicfactory.ive") +} +--add example model 'factory' to the scene graph +RelativeTo.World:addChild(factory) + + +-- need thw RelativeTo.World's state set to turn on our lights int the scene +worldStateSet = RelativeTo.World:getOrCreateStateSet() + +function createLight1() + -- create a light object + light1 = osg.Light() + -- set light number (openGL and osg can have up to eight lights in a scene #0-7) + light1:setLightNum(0) + -- create a lightsource object + lightsource1 = osg.LightSource() + -- turn the light source on + lightsource1:setLocalStateSetModes(osg.StateAttribute.Values.ON) + -- set light l1 to light source ls1 + lightsource1:setLight(light1) + + --set light attributes + light1:setAmbient(osg.Vec4(0.8, 0.8, 0.8, 0.5)) + light1:setDiffuse(osg.Vec4(0.8, 0.8, 0.8, 0.8)) + light1:setSpecular(osg.Vec4(0.8, 0.8, 0.8, 0.8)) + + -- turn the light on in the relativeto.world state set + worldStateSet:setAssociatedModes(light1, osg.StateAttribute.Values.ON) + --add lightsource to scene (room) + RelativeTo.Room:addChild(lightsource1) + -- set position of light + light1:setPosition(osg.Vec4(0, 3, -5, 1.0)) +end + +function createLight2() + -- create a light object + light2 = osg.Light() + -- set light number (openGL and osg can have up to eight lights in a scene #0-7) + light2:setLightNum(1) + -- create a lightsource object + lightsource2 = osg.LightSource() + -- turn the light source on + lightsource2:setLocalStateSetModes(osg.StateAttribute.Values.ON) + -- set light light2 to lightsource lightsource2 + lightsource2:setLight(light2) + --set light attributes + light2:setAmbient(osg.Vec4(.8, .8, 0.6, .50)) + + -- turn the light on in the relativeto.world state set + worldStateSet:setAssociatedModes(light2, osg.StateAttribute.Values.ON) + + --add lightsource to scene (room) + RelativeTo.Room:addChild(lightsource2) + -- set position of light + light2:setPosition(osg.Vec4(1.5, 2, 2, 1.0)) +end + +--calls to turn create lights functions (by extension creates them and turns them ON) +createLight1() +createLight2() + diff --git a/examples/models/basicfactory.ive b/examples/models/basicfactory.ive new file mode 100644 index 00000000..5b6e0d4b Binary files /dev/null and b/examples/models/basicfactory.ive differ diff --git a/vrjugglua/lua/nav-app-skeleton.lua b/vrjugglua/lua/nav-app-skeleton.lua index f7456f4c..0f78ae3e 100644 --- a/vrjugglua/lua/nav-app-skeleton.lua +++ b/vrjugglua/lua/nav-app-skeleton.lua @@ -73,6 +73,30 @@ function osgnav:latePreFrame() end end +function osgnav:setupDefaultLighting() + WorldStateSet = RelativeTo.World:getOrCreateStateSet() + --Light 0 + light0 = osg.Light() + light0:setAmbient(osg.Vec4(0.8, 0.8, 0.8, 0.8)) + lightsource0 = osg.LightSource() + lightsource0:setLight(light0) + lightsource0:setLocalStateSetModes(osg.StateAttribute.Values.ON) + WorldStateSet:setAssociatedModes(light0, osg.StateAttribute.Values.ON) + RelativeTo.Room:addChild(lightsource0) + light0:setPosition(osg.Vec4(0, 10, 0, 1.0)) + + --Light 1 + light1 = osg.Light() + light1:setLightNum(1) + light1:setAmbient(osg.Vec4(.8, .8, 0.6, .50)) + lightsource1 = osg.LightSource() + lightsource1:setLight(light1) + lightsource1:setLocalStateSetModes(osg.StateAttribute.Values.ON) + WorldStateSet:setAssociatedModes(light1, osg.StateAttribute.Values.ON) + RelativeTo.Room:addChild(lightsource1) + light1:setPosition(osg.Vec4(1.5, 2, 0, 1.0)) +end + print("Setting up scenegraph") navtransform = osg.PositionAttitudeTransform() @@ -86,6 +110,8 @@ osgnav.appProxy:setAppDelegate(osgnav) print("Setting kernel application") osgnav.appProxy:setActiveApplication() +print("Setting up default Lighting. Override OpenGL Light #0 & #1") +osgnav:setupDefaultLighting()