Bläddra i källkod

Simplified lua samples 08_Decals and TestScene

Mike3D 11 år sedan
förälder
incheckning
efdb2f0eb0
2 ändrade filer med 6 tillägg och 10 borttagningar
  1. 5 8
      Bin/Data/LuaScripts/08_Decals.lua
  2. 1 2
      Bin/Data/LuaScripts/TestScene.lua

+ 5 - 8
Bin/Data/LuaScripts/08_Decals.lua

@@ -191,8 +191,8 @@ function MoveCamera(timeStep)
 end
 end
 
 
 function PaintDecal()
 function PaintDecal()
-    local result, hitPos, hitDrawable = Raycast(250.0)
-    if result then
+    local hitPos, hitDrawable = Raycast(250.0)
+    if hitDrawable ~= nil then
         -- Check if target scene node already has a DecalSet component. If not, create now
         -- Check if target scene node already has a DecalSet component. If not, create now
         local targetNode = hitDrawable:GetNode()
         local targetNode = hitDrawable:GetNode()
         local decal = targetNode:GetComponent("DecalSet")
         local decal = targetNode:GetComponent("DecalSet")
@@ -215,7 +215,7 @@ function Raycast(maxDistance)
     local pos = ui.cursorPosition
     local pos = ui.cursorPosition
     -- Check the cursor is visible and there is no UI element in front of the cursor
     -- Check the cursor is visible and there is no UI element in front of the cursor
     if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
     if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
-        return false, nil, nil
+        return nil, nil
     end
     end
 
 
     local camera = cameraNode:GetComponent("Camera")
     local camera = cameraNode:GetComponent("Camera")
@@ -224,13 +224,10 @@ function Raycast(maxDistance)
     local octree = scene_:GetComponent("Octree")
     local octree = scene_:GetComponent("Octree")
     local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
     local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
     if result.drawable ~= nil then
     if result.drawable ~= nil then
-        -- Calculate hit position in world space
-        hitPos = cameraRay.origin + cameraRay.direction * result.distance
-        hitDrawable = result.drawable
-        return true, hitPos, hitDrawable
+        return result.position, result.drawable
     end
     end
 
 
-    return false, nil, nil
+    return nil, nil
 end
 end
 
 
 function HandleUpdate(eventType, eventData)
 function HandleUpdate(eventType, eventData)

+ 1 - 2
Bin/Data/LuaScripts/TestScene.lua

@@ -389,7 +389,6 @@ function HandleMouseButtonDown(eventType, eventData)
                 local cameraRay = camera:GetScreenRay(pos.x / graphics:GetWidth(), pos.y / graphics:GetHeight())
                 local cameraRay = camera:GetScreenRay(pos.x / graphics:GetWidth(), pos.y / graphics:GetHeight())
                 local result = testScene:GetComponent("Octree"):RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY)
                 local result = testScene:GetComponent("Octree"):RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY)
                 if result.drawable ~= nil then
                 if result.drawable ~= nil then
-                    local rayHitPos = cameraRay.origin + cameraRay.direction * result.distance
                     local decal = result.drawable:GetNode():GetComponent("DecalSet")
                     local decal = result.drawable:GetNode():GetComponent("DecalSet")
                     if decal == nil then
                     if decal == nil then
                         decal = result.drawable:GetNode():CreateComponent("DecalSet")
                         decal = result.drawable:GetNode():CreateComponent("DecalSet")
@@ -400,7 +399,7 @@ function HandleMouseButtonDown(eventType, eventData)
                             decal.maxIndices = 4096
                             decal.maxIndices = 4096
                         end
                         end
                     end
                     end
-                    decal:AddDecal(result.drawable, rayHitPos, cameraNode:GetWorldRotation(), 0.5, 1.0, 1.0, Vector2(0, 0), Vector2(1, 1))
+                    decal:AddDecal(result.drawable, result.position, cameraNode:GetWorldRotation(), 0.5, 1.0, 1.0, Vector2(0, 0), Vector2(1, 1))
                 end
                 end
             end
             end
         end
         end