Skip to content

Commit 8199b42

Browse files
first commit
0 parents  commit 8199b42

33 files changed

+7385
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Erdong Chen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

example/CharacterAnimation.png

638 KB
Loading

example/DynamicPlatforms.jsx

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { Text } from "@react-three/drei";
2+
import { useFrame } from "@react-three/fiber";
3+
import {
4+
CuboidCollider,
5+
CylinderCollider,
6+
RigidBody,
7+
} from "@react-three/rapier";
8+
import { useRef, useMemo } from "react";
9+
import * as THREE from "three";
10+
11+
export default function DynamicPlatforms() {
12+
const sideMovePlatformRef = useRef();
13+
const verticalMovePlatformRef = useRef();
14+
const rotatePlatformRef = useRef();
15+
const rotationDrumRef = useRef();
16+
17+
// Initializ animation settings
18+
let time = null;
19+
const xRotationAxies = new THREE.Vector3(1, 0, 0);
20+
const yRotationAxies = new THREE.Vector3(0, 1, 0);
21+
const zRotationAxies = new THREE.Vector3(0, 0, 1);
22+
const quaternionRotation = useMemo(() => new THREE.Quaternion(), []);
23+
24+
useFrame((state) => {
25+
time = state.clock.elapsedTime;
26+
27+
// Move platform
28+
sideMovePlatformRef.current?.setNextKinematicTranslation({
29+
x: 5 * Math.sin(time / 2) - 12,
30+
y: -0.5,
31+
z: -10,
32+
});
33+
34+
// Elevate platform
35+
verticalMovePlatformRef.current?.setNextKinematicTranslation({
36+
x: -25,
37+
y: 2 * Math.sin(time / 2) + 2,
38+
z: 0,
39+
});
40+
verticalMovePlatformRef.current?.setNextKinematicRotation(
41+
quaternionRotation.setFromAxisAngle(yRotationAxies, time * 0.5)
42+
);
43+
44+
// Rotate platform
45+
rotatePlatformRef.current?.setNextKinematicRotation(
46+
quaternionRotation.setFromAxisAngle(yRotationAxies, time * 0.5)
47+
);
48+
49+
// Rotate drum
50+
rotationDrumRef.current?.setNextKinematicRotation(
51+
quaternionRotation.setFromAxisAngle(xRotationAxies, time * 0.5)
52+
);
53+
});
54+
55+
return (
56+
<>
57+
{/* Moving platform */}
58+
<RigidBody
59+
type="kinematicPosition"
60+
ref={sideMovePlatformRef}
61+
colliders={false}
62+
>
63+
<Text
64+
scale={0.5}
65+
color="black"
66+
maxWidth={10}
67+
textAlign="center"
68+
position={[0, 2.5, 0]}
69+
>
70+
Kinematic Moving Platform
71+
</Text>
72+
<CuboidCollider args={[2.5, 0.1, 2.5]} />
73+
<mesh receiveShadow castShadow>
74+
<boxGeometry args={[5, 0.2, 5]} />
75+
<meshStandardMaterial color={"moccasin"} />
76+
</mesh>
77+
</RigidBody>
78+
79+
{/* Elevating platform */}
80+
<RigidBody
81+
type="kinematicPosition"
82+
position={[-25, 0, 0]}
83+
ref={verticalMovePlatformRef}
84+
colliders={false}
85+
>
86+
<Text
87+
scale={0.5}
88+
color="black"
89+
maxWidth={10}
90+
textAlign="center"
91+
position={[0, 2.5, 0]}
92+
rotation={[0, Math.PI / 2, 0]}
93+
>
94+
Kinematic Elevating Platform
95+
</Text>
96+
<CuboidCollider args={[2.5, 0.1, 2.5]} />
97+
<mesh receiveShadow castShadow>
98+
<boxGeometry args={[5, 0.2, 5]} />
99+
<meshStandardMaterial color={"moccasin"} />
100+
</mesh>
101+
</RigidBody>
102+
103+
{/* Rotating Platform */}
104+
<RigidBody
105+
type="kinematicPosition"
106+
position={[-25, -0.5, -10]}
107+
ref={rotatePlatformRef}
108+
colliders={false}
109+
>
110+
<Text
111+
scale={0.5}
112+
color="black"
113+
maxWidth={10}
114+
textAlign="center"
115+
position={[0, 2.5, 0]}
116+
>
117+
Kinematic Rotating Platform
118+
</Text>
119+
<CuboidCollider args={[2.5, 0.1, 2.5]} />
120+
<mesh receiveShadow castShadow>
121+
<boxGeometry args={[5, 0.2, 5]} />
122+
<meshStandardMaterial color={"moccasin"} />
123+
</mesh>
124+
</RigidBody>
125+
126+
{/* Rotating drum */}
127+
<Text
128+
scale={0.5}
129+
color="black"
130+
maxWidth={10}
131+
textAlign="center"
132+
position={[-15, 2.5, -15]}
133+
>
134+
Kinematic Rotating Drum
135+
</Text>
136+
<RigidBody
137+
colliders={false}
138+
type="kinematicPosition"
139+
position={[-15, -1, -15]}
140+
ref={rotationDrumRef}
141+
>
142+
<group rotation={[0, 0, Math.PI / 2]}>
143+
<CylinderCollider args={[5, 1]} />
144+
<mesh receiveShadow>
145+
<cylinderGeometry args={[1, 1, 10]} />
146+
<meshStandardMaterial color={"moccasin"} />
147+
</mesh>
148+
</group>
149+
</RigidBody>
150+
</>
151+
);
152+
}

0 commit comments

Comments
 (0)