Skip to content

Commit

Permalink
Add screen to world example to the basic_3d scene
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Sep 20, 2023
1 parent 2eff3af commit 48573f3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/scenes/basic_3d/basic_3d.collection
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ embedded_instances {
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
""
position {
Expand All @@ -284,3 +286,45 @@ embedded_instances {
z: 1.0
}
}
embedded_instances {
id: "raycast_target"
data: "embedded_components {\n"
" id: \"mesh\"\n"
" type: \"mesh\"\n"
" data: \"material: \\\"/scene3d/materials/primitive_max_yellow_red.material\\\"\\n"
"vertices: \\\"/scene3d/assets/meshes/primitive_sphere.buffer\\\"\\n"
"textures: \\\"/scene3d/assets/textures/grid_10x10.png\\\"\\n"
"primitive_type: PRIMITIVE_TRIANGLES\\n"
"position_stream: \\\"position\\\"\\n"
"normal_stream: \\\"normal\\\"\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 0.5
y: 0.5
z: 0.5
}
}
21 changes: 21 additions & 0 deletions examples/scenes/basic_3d/basic_3d_main.script
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,26 @@ end
function on_message(self, message_id, message, sender)
end

local RAYCAST_GROUPS = { hash("default") }
local CLOSEST = { all = false }

function on_input(self, action_id, action)
if action_id == nil or action_id == hash("touch") then
local from = render3d.screen_to_world(action.screen_x, action.screen_y, 1)
local to = render3d.screen_to_world(action.screen_x, action.screen_y, 50)
-- UNCOMMENT TO DEBUG
-- if action.pressed then
-- go.set("/raycast_target", "position", from)
-- go.animate("/raycast_target", "position", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, 3)
-- else
local results = physics.raycast(from, to, RAYCAST_GROUPS, CLOSEST)
if results ~= nil then
for _, result in ipairs(results) do
go.cancel_animations("/raycast_target", "position")
go.animate("/raycast_target", "position", go.PLAYBACK_ONCE_FORWARD, result.position, go.EASING_OUTQUAD, 0.1)
break
end
end
-- end
end
end

0 comments on commit 48573f3

Please sign in to comment.