~etc-pgh-launchpad/wildpockets/trunk

« back to all changes in this revision

Viewing changes to baseresources/wild pockets team/tutorials/sceneobjecttutorials/sceneobjectvisualscript.lua

  • Committer: etc-pgh-launchpad at cmu
  • Date: 2010-11-30 20:56:30 UTC
  • Revision ID: etc-pgh-launchpad@lists.andrew.cmu.edu-20101130205630-0blbkcz28ovjl8wj
Committing the Wild Pockets code base to Launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- This is the demo pocket which displays the theory from 
 
2
-- the Visual Properties section of SceneObject tutorial
 
3
 
 
4
myObject, bot = nil
 
5
 
 
6
function onSceneStart()
 
7
    -- Get object to be operated on
 
8
    myObject = SceneManager.getObject("Big Cube")
 
9
    -- Get another object
 
10
    bot = SceneManager.getObject("Bot")
 
11
    -- Set up the Camera
 
12
    Camera.setExactEye(vec(-3,13,5))
 
13
    Camera.focusOnObject(myObject)
 
14
    -- Set the Camera rotating
 
15
    Timer.every(function() Camera.rotateLeft(0.1) end, 0)
 
16
    -- Set up the gui
 
17
    GuiManager.call("gui", updateGui)
 
18
end
 
19
-- The functions
 
20
-- Replace model
 
21
function replaceFromObject()
 
22
    myObject:replaceModel(bot)
 
23
end
 
24
function replaceFromFile()
 
25
    myObject:replaceModel("ali/wild pockets cube")
 
26
end
 
27
-- Mesh business
 
28
function setWireframe()
 
29
    local meshes = myObject:getMeshes()
 
30
    for i, mesh in ipairs(meshes) do
 
31
        if not (mesh == nil) then
 
32
        myObject:setMeshMode(mesh, "wireframe")
 
33
        end
 
34
    end
 
35
end
 
36
function setStandard()
 
37
    local meshes = myObject:getMeshes()
 
38
    for i, mesh in ipairs(meshes) do
 
39
        if not (mesh == nil) then
 
40
        myObject:setMeshMode(mesh, "standard")
 
41
        end
 
42
    end
 
43
end
 
44
function setAlphatest()
 
45
    local meshes = myObject:getMeshes()
 
46
    for i, mesh in ipairs(meshes) do
 
47
        if not (mesh == nil) then
 
48
        myObject:setMeshMode(mesh, "alphatest")
 
49
        end
 
50
    end
 
51
end
 
52
-- Textures
 
53
function replaceTextures()
 
54
    local numTextures = myObject:getNumTextures()
 
55
    for i = 1, numTextures do
 
56
        myObject:setTexture("ecanaan/canon_blue-blue", i)
 
57
    end
 
58
end
 
59
function setDefaultTextures()
 
60
    local numTextures = myObject:getNumTextures()
 
61
    for i = 1, numTextures do
 
62
        myObject:setTexture(myObject:getDefaultTexture(i), i)
 
63
    end
 
64
end
 
65
-- Shadow, lighting, highlight and stash
 
66
function toggleShadow()
 
67
    if myObject:getCastsShadow() then
 
68
        myObject:setCastsShadow(false)
 
69
    else
 
70
        myObject:setCastsShadow(true)
 
71
    end
 
72
end
 
73
function toggleLighting()
 
74
    if myObject:getLightingEnabled() then
 
75
        myObject:setLightingEnabled(false)
 
76
    else
 
77
        myObject:setLightingEnabled(true)
 
78
    end
 
79
end
 
80
function toggleStash()
 
81
    if myObject:getStashed() then
 
82
        myObject:setStashed(false)
 
83
    else
 
84
        myObject:setStashed(true)
 
85
    end
 
86
end
 
87
function setHighlight(flag)
 
88
    if flag then
 
89
        myObject:highlight(color(0,1,1,1))
 
90
    else
 
91
        myObject:highlight(nil)
 
92
    end
 
93
end
 
94
function setNewColor()
 
95
    myObject:setColor(1,0,0,0.7)
 
96
end
 
97
function setWhite()
 
98
    myObject:setColor(1,1,1,1)
 
99
end
 
100
-- Extra: SceneManager show Bones and Collisions
 
101
function showBonesAndCollisions(flag)
 
102
    SceneManager.showBones(flag)
 
103
    SceneManager.showCollisions(flag)
 
104
end
 
105
-- Gui - out of scope of this tutorial
 
106
function updateGui()
 
107
    local screen = Rect.screen()
 
108
    local fromFileButton = screen:sub("file", 10, 10, 300, 30)
 
109
    local fromObjectButton = screen:sub("object", 10, 30, 180, 50)
 
110
    fromFileButton:drawButton(nil, GuiManager.standardSkin(), 'Replace from file: "ali/Wild Pockets Cube"', replaceFromFile)
 
111
    fromObjectButton:drawButton(nil, GuiManager.standardSkin(), "Replace from object", replaceFromObject)
 
112
    
 
113
    local wireframeButton = screen:sub("wireframe", 10, 70, 100, 90)
 
114
    local standardButton = screen:sub("standard", 10, 90, 100, 110)
 
115
    local alphatestButton = screen:sub("alphatest", 10, 110, 100, 130)
 
116
    wireframeButton:drawButton(nil, GuiManager.standardSkin(), "wireframe", setWireframe)
 
117
    standardButton:drawButton(nil, GuiManager.standardSkin(), "standard", setStandard)
 
118
    alphatestButton:drawButton(nil, GuiManager.standardSkin(), "alphatest", setAlphatest)
 
119
    
 
120
    local textureButton = screen:sub("texture", 10, 150, 140, 170)
 
121
    local defaultTextureButton = screen:sub("default texture", 10, 170, 170, 190)
 
122
    textureButton:drawButton(nil, GuiManager.standardSkin(), "replace textures", replaceTextures)
 
123
    defaultTextureButton:drawButton(nil, GuiManager.standardSkin(), "set default textures", setDefaultTextures)
 
124
    
 
125
    local shadowButton = screen:sub("shadow", 10, 230, 130, 250)
 
126
    local lightingButton = screen:sub("lighting", 10, 250, 130, 270)
 
127
    local stashButton = screen:sub("stash", 10, 270, 130, 290)
 
128
    local setNewColorButton = screen:sub("newColor", 10, 310, 100, 330)
 
129
    local setWhiteButton = screen:sub("white", 10, 290, 100, 310)
 
130
    local highlightText = screen:sub("highlightText", 10, 330, 100, 350)
 
131
    local highlightCheckbox = screen:sub("highlightText", 100, 335, 110, 345)
 
132
    shadowButton:drawButton(nil, GuiManager.standardSkin(), "toggle shadow", toggleShadow)
 
133
    lightingButton:drawButton(nil, GuiManager.standardSkin(), "toggle lighting", toggleLighting)
 
134
    stashButton:drawButton(nil, GuiManager.standardSkin(), "toggle stashed", toggleStash)
 
135
    setNewColorButton:drawButton(nil, GuiManager.standardSkin(), "new color", setNewColor)
 
136
    setWhiteButton:drawButton(nil, GuiManager.standardSkin(), "default color", setWhite)
 
137
    highlightText:drawText(nil, {size = 10}, "highlight:")
 
138
    highlightCheckbox:drawCheckBox(nil, GuiManager.standardSkin(), false, function() setHighlight(highlightCheckbox:getCheckBoxValue()) end)
 
139
    
 
140
    local bonesCollisionsText =  screen:sub("bones text", 10, 350, 180, 370)
 
141
    local bonesCollisionsCheckbox =  screen:sub("bones checkbox", 180, 355, 190, 365)
 
142
    bonesCollisionsText:drawText(nil, {size = 8}, "Show Bones and Collisions:")
 
143
    bonesCollisionsCheckbox:drawCheckBox(nil, GuiManager.standardSkin(), false, function() showBonesAndCollisions(bonesCollisionsCheckbox:getCheckBoxValue()) end)
 
144
end
 
 
b'\\ No newline at end of file'