Skip to content

Commit 4dbfc9f

Browse files
Site changes
1 parent 0926014 commit 4dbfc9f

789 files changed

Lines changed: 3728 additions & 861 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

_data/examplesindex.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,19 @@
10921092
"title": "Box2D Chain Terrain",
10931093
"twitter_image": "https://www.defold.com/examples/physics/box2d_chain_terrain/thumbnail.webp"
10941094
},
1095+
{
1096+
"author": "Defold Foundation",
1097+
"brief": "Create and control a motorized Box2D joint from script using Box2D V2 and V3.",
1098+
"category": "physics",
1099+
"layout": "example",
1100+
"opengraph_image": "https://www.defold.com/examples/physics/box2d_motor_joint/thumbnail.webp",
1101+
"path": "physics/box2d_motor_joint",
1102+
"scripts": "box2d_motor_joint_v3.script, box2d_motor_joint_v2.script",
1103+
"tags": "physics, box2d",
1104+
"thumbnail": "thumbnail.webp",
1105+
"title": "Box2D Motor Joint",
1106+
"twitter_image": "https://www.defold.com/examples/physics/box2d_motor_joint/thumbnail.webp"
1107+
},
10951108
{
10961109
"author": "Defold Foundation",
10971110
"brief": "Create a mouse joint that pulls dynamic bodies toward a moving target.",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
local TOUCH = hash("touch")
2+
local MOTOR_SPEED = 1.5
3+
local MAX_MOTOR_TORQUE = 50000
4+
5+
local function update_label(self)
6+
local direction = self.direction > 0 and "counter-clockwise" or "clockwise"
7+
label.set_text("#label", string.format("Box2D V2 motor joint\nMotor: %s\nClick or touch to reverse", direction)) -- <1>
8+
end
9+
10+
local function set_motor_speed(self)
11+
b2d.joint.set_motor_speed(self.joint, self.direction * MOTOR_SPEED) -- <2>
12+
update_label(self)
13+
end
14+
15+
local function reverse_motor(self)
16+
self.direction = -self.direction -- <3>
17+
set_motor_speed(self)
18+
end
19+
20+
function init(self)
21+
self.direction = -1
22+
23+
local b2d_version = b2d.get_version() -- <4>
24+
self.active = b2d_version.major == 2 -- <5>
25+
26+
if not self.active then -- <6>
27+
return
28+
end
29+
30+
msg.post(".", "acquire_input_focus") -- <7>
31+
32+
local pivot_position = go.get_position("pivot") -- <8>
33+
local arm_position = go.get_position("arm")
34+
local pivot = b2d.get_body(msg.url(nil, "pivot", "collisionobject")) -- <9>
35+
local arm = b2d.get_body(msg.url(nil, "arm", "collisionobject")) -- <10>
36+
b2d.body.set_gravity_scale(arm, 0.0) -- <11>
37+
38+
local arm_anchor = vmath.vector3(
39+
pivot_position.x - arm_position.x,
40+
pivot_position.y - arm_position.y,
41+
pivot_position.z - arm_position.z
42+
) -- <12>
43+
44+
self.joint = b2d.joint.create_revolute(pivot, arm, { -- <13>
45+
local_anchor_a = vmath.vector3(),
46+
local_anchor_b = arm_anchor,
47+
enable_motor = true,
48+
max_motor_torque = MAX_MOTOR_TORQUE,
49+
motor_speed = self.direction * MOTOR_SPEED,
50+
collide_connected = false,
51+
})
52+
53+
update_label(self)
54+
end
55+
56+
-------------------
57+
-- Input handling:
58+
59+
function on_input(self, action_id, action)
60+
if not self.active then -- <14>
61+
return
62+
end
63+
64+
if action_id == TOUCH and action.pressed then -- <15>
65+
reverse_motor(self)
66+
end
67+
end
68+
69+
function final(self)
70+
if not self.active then
71+
return
72+
end
73+
74+
if self.joint then
75+
b2d.joint.destroy(self.joint) -- <16>
76+
self.joint = nil
77+
end
78+
79+
msg.post(".", "release_input_focus") -- <17>
80+
end
81+
82+
--[[
83+
1. Updates the label with the active backend and the current motor direction.
84+
2. Sets the motor speed on the revolute joint through the Box2D joint API.
85+
3. Reverses the stored motor direction before applying the new speed.
86+
4. Reads the active Box2D backend version.
87+
5. Enables this script only when the project is running the Box2D V2 backend.
88+
6. Stops the script early when Box2D V2 is not active.
89+
7. Acquires input focus so this script can receive click or touch input.
90+
8. Reads the editor-placed pivot and arm positions used to calculate the local joint anchor.
91+
9. Gets the Box2D body from the static `pivot` collision object.
92+
10. Gets the Box2D body from the dynamic `arm` collision object.
93+
11. Disables gravity on the arm body so the example focuses on the joint motor.
94+
12. Converts the pivot world position into the arm's local space using the editor positions. This keeps the arm rotating around the visible pivot.
95+
13. Creates a revolute joint with its motor enabled. The revolute joint provides the pivot, while the motor drives the rotation.
96+
14. Skips input handling if this script is inactive.
97+
15. Handles a click or touch press and uses it to reverse the motor direction.
98+
16. Destroys the runtime-created joint during cleanup.
99+
17. Releases input focus when the script or collection is unloaded.
100+
]]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
local TOUCH = hash("touch")
2+
local MOTOR_SPEED = 1.5
3+
local MAX_MOTOR_TORQUE = 50000
4+
5+
local function update_label(self)
6+
local direction = self.direction > 0 and "counter-clockwise" or "clockwise"
7+
label.set_text("#label", string.format("Box2D V3 motor joint\nMotor: %s\nClick or touch to reverse", direction)) -- <1>
8+
end
9+
10+
local function set_motor_speed(self)
11+
b2d.joint.set_motor_speed(self.joint, self.direction * MOTOR_SPEED) -- <2>
12+
update_label(self)
13+
end
14+
15+
local function reverse_motor(self)
16+
self.direction = -self.direction -- <3>
17+
set_motor_speed(self)
18+
end
19+
20+
function init(self)
21+
self.direction = -1
22+
23+
local b2d_version = b2d.get_version() -- <4>
24+
self.active = b2d_version.major == 3 -- <5>
25+
26+
if not self.active then -- <6>
27+
return
28+
end
29+
30+
msg.post(".", "acquire_input_focus") -- <7>
31+
32+
local world = b2d.get_world() -- <8>
33+
b2d.world.set_gravity(world, vmath.vector3()) -- <9>
34+
b2d.world.set_joint_tuning(world, 60, 1.0) -- <10>
35+
36+
local pivot_position = go.get_position("pivot") -- <11>
37+
local pivot = b2d.get_body(msg.url(nil, "pivot", "collisionobject")) -- <12>
38+
local arm = b2d.get_body(msg.url(nil, "arm", "collisionobject")) -- <13>
39+
b2d.body.set_gravity_scale(arm, 0.0) -- <14>
40+
41+
local arm_anchor = b2d.body.get_local_point(arm, pivot_position) -- <15>
42+
43+
self.joint = b2d.joint.create_revolute(pivot, arm, { -- <16>
44+
local_anchor_a = vmath.vector3(),
45+
local_anchor_b = arm_anchor,
46+
enable_motor = true,
47+
max_motor_torque = MAX_MOTOR_TORQUE,
48+
motor_speed = self.direction * MOTOR_SPEED,
49+
collide_connected = false,
50+
})
51+
52+
update_label(self)
53+
end
54+
55+
-------------------
56+
-- Input handling:
57+
58+
function on_input(self, action_id, action)
59+
if not self.active then -- <17>
60+
return
61+
end
62+
63+
if action_id == TOUCH and action.pressed then -- <18>
64+
reverse_motor(self)
65+
end
66+
end
67+
68+
function final(self)
69+
if not self.active then
70+
return
71+
end
72+
73+
if self.joint then
74+
b2d.joint.destroy(self.joint) -- <19>
75+
self.joint = nil
76+
end
77+
78+
msg.post(".", "release_input_focus") -- <20>
79+
end
80+
81+
--[[
82+
1. Updates the label with the active backend and the current motor direction.
83+
2. Sets the motor speed on the revolute joint through the Box2D joint API.
84+
3. Reverses the stored motor direction before applying the new speed.
85+
4. Reads the active Box2D backend version.
86+
5. Enables this script only when the project is running the Box2D V3 backend.
87+
6. Stops the script early when Box2D V3 is not active.
88+
7. Acquires input focus so this script can receive click or touch input.
89+
8. Gets the current Box2D world handle.
90+
9. Clears world gravity so the arm stays in the editor-placed setup.
91+
10. Tunes the Box2D V3 joint solver used by the motorized joint.
92+
11. Reads the editor-placed pivot position, which is the world point the arm should rotate around.
93+
12. Gets the Box2D body from the static `pivot` collision object.
94+
13. Gets the Box2D body from the dynamic `arm` collision object.
95+
14. Disables gravity on the arm body so the example focuses on the joint motor.
96+
15. Converts the pivot world position into the arm's local space using the V3 body helper. This keeps the arm rotating around the visible pivot.
97+
16. Creates a revolute joint with its motor enabled. The revolute joint provides the pivot, while the motor drives the rotation.
98+
17. Skips input handling if this script is inactive.
99+
18. Handles a click or touch press and uses it to reverse the motor direction.
100+
19. Destroys the runtime-created joint during cleanup.
101+
20. Releases input focus when the script or collection is unloaded.
102+
]]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"content":[{"name":"game.projectc","size":4777,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":3168,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":1448548,"pieces":[{"name":"game0.arcd","offset":0}]},{"name":"game.dmanifest","size":3303,"pieces":[{"name":"game0.dmanifest","offset":0}]}],"total_size":1459796}
1+
{"content":[{"name":"game.projectc","size":4856,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":3168,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":1443904,"pieces":[{"name":"game0.arcd","offset":0}]},{"name":"game.dmanifest","size":3302,"pieces":[{"name":"game0.dmanifest","offset":0}]}],"total_size":1455230}
-4.54 KB
Binary file not shown.
0 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.

examples/animation/3d_animations/archive/game0.projectc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ max_resources = 1024
104104
repeat_delay = 0.5
105105
repeat_interval = 0.2
106106
gamepads = /builtins/input/default.gamepadsc
107+
gamepad_database = /builtins/input/gamecontrollerdb.txt
108+
gamepad_deadzone = 0.2
107109
game_binding = /input/game.input_bindingc
108110
use_accelerometer = 1
109111

examples/animation/3d_animations/dmloader.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ var FileLoader = {
224224
var EngineLoader = {
225225
arc_sha1: "",
226226
wasm_sha1: "",
227-
wasm_size: 2827830,
227+
wasm_size: 2825791,
228228
wasmjs_sha1: "",
229229
wasmjs_size: 282852,
230230
wasm_pthread_sha1: "",
231231
wasm_pthread_size: 2000000,
232232
wasmjs_pthread_sha1: "",
233233
wasmjs_pthread_size: 250000,
234-
wasm_file: "/examples/wasm/1cb2daded744b16282557ec3e42d9dc2.wasm",
235-
wasm_pthread_file: "/examples/wasm/1cb2daded744b16282557ec3e42d9dc2.wasm",
236-
wasmjs_file: "/examples/wasm/019af777c7ea2eba57c5e3c9fcd1c4c2.wasm.js",
237-
wasmjs_pthread_file: "/examples/wasm/019af777c7ea2eba57c5e3c9fcd1c4c2.wasm.js",
234+
wasm_file: "/examples/wasm/62d49d3a1e25642da4df5a1f75e1ac68.wasm",
235+
wasm_pthread_file: "/examples/wasm/62d49d3a1e25642da4df5a1f75e1ac68.wasm",
236+
wasmjs_file: "/examples/wasm/29c6d3b0c9d07e47c3b76094bdc73808.wasm.js",
237+
wasmjs_pthread_file: "/examples/wasm/29c6d3b0c9d07e47c3b76094bdc73808.wasm.js",
238238
wasm_instantiate_progress: 0,
239239

240240
stream_wasm: "false" === "true",
@@ -897,7 +897,7 @@ var Progress = {
897897

898898
var Module = {
899899
engineVersion: "1.13.1",
900-
engineSdkSha1: "070624ab8bd5e66a84a580312557d9f44fcec700",
900+
engineSdkSha1: "a17be93c6c9ac834117c95e94d874f72574e8f88",
901901
noInitialRun: true,
902902

903903
_filesToPreload: [],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"content":[{"name":"game.projectc","size":4785,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":1488,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":53888,"pieces":[{"name":"game0.arcd","offset":0}]},{"name":"game.dmanifest","size":1544,"pieces":[{"name":"game0.dmanifest","offset":0}]}],"total_size":61705}
1+
{"content":[{"name":"game.projectc","size":4864,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":1488,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":49240,"pieces":[{"name":"game0.arcd","offset":0}]},{"name":"game.dmanifest","size":1543,"pieces":[{"name":"game0.dmanifest","offset":0}]}],"total_size":57135}

0 commit comments

Comments
 (0)