-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from pmndrs/controllers
Controllers First Pass
- Loading branch information
Showing
76 changed files
with
9,362 additions
and
7,269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// creates a bridge static rigidbody | ||
import { RigidBody } from "@react-three/jolt"; | ||
|
||
export function Arch(props: any) { | ||
const { position = [0, 0, 0] } = props; | ||
|
||
return ( | ||
<RigidBody position={position} type={"static"} allowObstruction> | ||
<mesh position={[0, 7, 0]}> | ||
<boxGeometry args={[7, 1, 3]} /> | ||
<meshStandardMaterial color="#AD6A6C" /> | ||
</mesh> | ||
<mesh position={[3.5, 3.5, 0]}> | ||
<boxGeometry args={[1, 7, 3]} /> | ||
<meshStandardMaterial color="#AD6A6C" /> | ||
</mesh> | ||
<mesh position={[-3.5, 3.5, 0]}> | ||
<boxGeometry args={[1, 7, 3]} /> | ||
<meshStandardMaterial color="#AD6A6C" /> | ||
</mesh> | ||
</RigidBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// creates a bridge static rigidbody | ||
import { BodyState, RigidBody } from "@react-three/jolt"; | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function Conveyor(props: any) { | ||
const rigidBodyRef = useRef(); | ||
const { | ||
size = [5, 0.4, 15], | ||
position = [0, 0, 0], | ||
target = [0, 0, 3], | ||
asSensor = false, | ||
rotation = [0, 0, 0], | ||
color = "#1EA896", | ||
...rest | ||
} = props; | ||
|
||
useEffect(() => { | ||
if (!rigidBodyRef.current) return; | ||
const body = rigidBodyRef.current as BodyState; | ||
body.isConveyor = true; | ||
body.conveyorVector = target; | ||
}, [target]); | ||
|
||
return ( | ||
<RigidBody ref={rigidBodyRef} position={position} rotation={rotation} type={"static"}> | ||
<mesh {...rest}> | ||
<boxGeometry args={size} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
</RigidBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// creates a bridge static rigidbody | ||
import { RigidBody } from "@react-three/jolt"; | ||
|
||
export function Stairs(props: any) { | ||
const { | ||
stairHeight = 0.4, | ||
height = 7, | ||
stairWidth = 1, | ||
position = [0, 0, 0], | ||
rotation = [0, 0, 0], | ||
color = "#7A9E9F" | ||
} = props; | ||
const count = Math.ceil(height / stairHeight); | ||
return ( | ||
<RigidBody | ||
allowObstruction | ||
obstructionTimelimit={2000} | ||
position={position} | ||
rotation={rotation} | ||
type={"static"} | ||
> | ||
{Array.from({ length: count }, (_, i) => ( | ||
<mesh key={i} position={[0, 7 - i * stairHeight, i * stairWidth]}> | ||
<boxGeometry args={[7, stairHeight, stairWidth]} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
))} | ||
</RigidBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// creates a bridge static rigidbody | ||
import { BodyState, RigidBody } from "@react-three/jolt"; | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function Teleport(props: any) { | ||
const rigidBodyRef = useRef(); | ||
const { | ||
size = [5, 0.4, 5], | ||
position = [0, 0, 0], | ||
target = [5, 5, 5], | ||
asSensor = false, | ||
rotation = [0, 0, 0], | ||
color = "#151E3F", | ||
...rest | ||
} = props; | ||
|
||
useEffect(() => { | ||
if (!rigidBodyRef.current) return; | ||
const body = rigidBodyRef.current as BodyState; | ||
body.isTeleporter = true; | ||
body.teleporterVector = target; | ||
}, [target]); | ||
|
||
return ( | ||
<RigidBody | ||
ref={rigidBodyRef} | ||
isSensor={asSensor} | ||
position={position} | ||
rotation={rotation} | ||
type={"static"} | ||
> | ||
<mesh {...rest}> | ||
<boxGeometry args={size} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
</RigidBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// creates a bridge static rigidbody | ||
import { RigidBody, type BodyState } from "@react-three/jolt"; | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function Tunnel(props: any) { | ||
const { position = [0, 0, 0], rotation = [0, 0, 0], color = "#151E3F" } = props; | ||
const rigidBodyRef = useRef(); | ||
useEffect(() => { | ||
if (!rigidBodyRef.current) return; | ||
const body = rigidBodyRef.current as BodyState; | ||
body.allowObstruction = false; | ||
}, []); | ||
return ( | ||
<RigidBody ref={rigidBodyRef} position={position} rotation={rotation} type={"static"}> | ||
<mesh position={[0, 7, 0]}> | ||
<boxGeometry args={[7, 1, 30]} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
<mesh position={[3.5, 3.5, 0]}> | ||
<boxGeometry args={[1, 7, 30]} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
<mesh position={[-3.5, 3.5, 0]}> | ||
<boxGeometry args={[1, 7, 30]} /> | ||
<meshStandardMaterial color={color} /> | ||
</mesh> | ||
</RigidBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { | ||
useConstraint, | ||
RigidBody | ||
//useSetInterval, | ||
//Raw, | ||
//useJolt, | ||
//BodyState, | ||
} from "@react-three/jolt"; | ||
import { | ||
//useEffect, | ||
useRef | ||
} from "react"; | ||
//import * as THREE from 'three'; | ||
|
||
/*const rotateQuaternion = ( | ||
quaternion: THREE.Quaternion, | ||
axis: string, | ||
rotation: number | ||
): THREE.Quaternion => { | ||
const euler = new THREE.Euler(); | ||
euler.setFromQuaternion(quaternion); | ||
switch (axis) { | ||
case 'x': | ||
euler.x += THREE.MathUtils.degToRad(rotation); | ||
break; | ||
case 'y': | ||
euler.y += THREE.MathUtils.degToRad(rotation); | ||
break; | ||
case 'z': | ||
euler.z += THREE.MathUtils.degToRad(rotation); | ||
break; | ||
default: | ||
console.error('Invalid axis specified'); | ||
break; | ||
} | ||
const newQuaternion = new THREE.Quaternion(); | ||
newQuaternion.setFromEuler(euler); | ||
return newQuaternion; | ||
}; | ||
*/ | ||
|
||
export function BoundBoxes() { | ||
const body1Ref = useRef(null); | ||
const body2Ref = useRef(null); | ||
const body3Ref = useRef(null); | ||
const body4Ref = useRef(null); | ||
const body5Ref = useRef(null); | ||
const body6Ref = useRef(null); | ||
const body7Ref = useRef(null); | ||
const body8Ref = useRef(null); | ||
// const body9Ref = useRef<RigidBody>(null); | ||
// const body10Ref = useRef<RigidBody>(null); | ||
//const { physicsSystem } = useJolt(); | ||
|
||
useConstraint("slider", body1Ref, body2Ref, { | ||
min: 6, | ||
max: 15 | ||
}); | ||
|
||
useConstraint("distance", body3Ref, body4Ref, { | ||
min: 10, | ||
max: 30 | ||
}); | ||
// distance constraint test for the rigging system | ||
useConstraint("distance", body6Ref, body5Ref, { | ||
min: 0, | ||
max: 2 | ||
}); | ||
// motorized slider constraint to test rotation of parent | ||
//const sliderRef = | ||
useConstraint("slider", body7Ref, body8Ref, { | ||
motor: { target: 6 } | ||
}); | ||
|
||
//const intervals = useSetInterval(); | ||
|
||
//let current = 1; | ||
/* | ||
useEffect(() => { | ||
intervals.setInterval(() => { | ||
//rotate the slider core | ||
// get the current rotation | ||
//@ts-ignore | ||
const baseQuat = body7Ref.current!.rotation; | ||
const newQuat = rotateQuaternion(baseQuat, 'x', 15); | ||
//@ts-ignore | ||
body7Ref.current!.rotation = newQuat; | ||
console.log('rotating', newQuat); | ||
//@ts-ignore | ||
sliderRef.current.SetTargetPosition(current++); | ||
console.log('setting target position', current); | ||
//@ts-ignore | ||
physicsSystem.bodyInterface.ActivateBody(body8Ref.current.body.GetID()); | ||
}, 3000); | ||
}, []); | ||
*/ | ||
|
||
return ( | ||
<> | ||
<RigidBody ref={body1Ref} position={[10, 15, 0]} mass={1}> | ||
<mesh> | ||
<boxGeometry args={[4, 4, 4]} /> | ||
<meshStandardMaterial color="#7F055F" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody position={[12, 5, 5]} ref={body2Ref} mass={2}> | ||
<mesh> | ||
<sphereGeometry args={[4, 32, 32]} /> | ||
<meshStandardMaterial color="#FF9505" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body3Ref} position={[15, 2, 10]} mass={1}> | ||
<mesh> | ||
<boxGeometry args={[4, 4, 4]} /> | ||
<meshStandardMaterial color="#EC4E20" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body4Ref} position={[15, 2, 15]} mass={1}> | ||
<mesh> | ||
<boxGeometry args={[4, 4, 4]} /> | ||
<meshStandardMaterial color="#45F0DF" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body5Ref} type={"rig"} position={[15, 2, 20]} mass={1}> | ||
<mesh> | ||
<sphereGeometry args={[4, 8, 8]} /> | ||
<meshStandardMaterial wireframe color="#ff521b" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body6Ref} position={[15, 2, 20]} mass={1}> | ||
<mesh> | ||
<sphereGeometry args={[1, 8, 8]} /> | ||
<meshStandardMaterial color="#69DDFF" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body7Ref} position={[-15, 1, 20]} type={"static"} mass={1}> | ||
<mesh> | ||
<sphereGeometry args={[1, 8, 8]} /> | ||
<meshStandardMaterial color="#320A28" /> | ||
</mesh> | ||
</RigidBody> | ||
<RigidBody ref={body8Ref} position={[-15, 3, 24]} mass={1}> | ||
<mesh> | ||
<boxGeometry args={[1, 1, 2]} /> | ||
<meshStandardMaterial color="#8E443D" /> | ||
</mesh> | ||
</RigidBody> | ||
</> | ||
); | ||
} |
Oops, something went wrong.