ConvexHullCollider instead of TriMesh
This commit is contained in:
@@ -58,7 +58,7 @@ export const GameView = observer(function () {
|
||||
|
||||
return (<>
|
||||
<Suspense>
|
||||
{/* <PlayerMovement /> */}
|
||||
<PlayerMovement />
|
||||
<Physics paused={game.isPaused}>
|
||||
<SceneView scene={game.scene} />
|
||||
</Physics>
|
||||
|
||||
@@ -80,6 +80,7 @@ export const ObjectEditorView = observer(function ({ object }: ObjectEditorViewP
|
||||
<ObjectViewInternal
|
||||
ref={groupRef}
|
||||
object={object}
|
||||
isEditor
|
||||
objectType={objectType}
|
||||
onClick={handleClick}
|
||||
/>
|
||||
|
||||
@@ -1,43 +1,36 @@
|
||||
import { observer } from "mobx-react-lite";
|
||||
import type { ObjectType, RuntimeObjectInstance } from "../types";
|
||||
import { forwardRef, useMemo } from "react";
|
||||
import { forwardRef } from "react";
|
||||
import type { Group } from "three";
|
||||
import { Instance, Instances } from "@react-three/drei";
|
||||
import type { ThreeEvent } from "@react-three/fiber";
|
||||
import { state } from "../state";
|
||||
import { TrimeshCollider } from "@react-three/rapier";
|
||||
import { ConvexHullCollider } from "@react-three/rapier";
|
||||
import { SyncRigidBody } from "./SyncRigidBody";
|
||||
import { runInAction } from "mobx";
|
||||
import { buildObjectTrimesh } from "../utils/graphics/mesh";
|
||||
|
||||
type ObjectViewInternalProps = {
|
||||
object: Omit<RuntimeObjectInstance, 'typeId'>;
|
||||
objectType: ObjectType;
|
||||
isEditor?: boolean;
|
||||
onClick?: (e: ThreeEvent<MouseEvent>) => void;
|
||||
}
|
||||
|
||||
export const ObjectViewInternal = observer(forwardRef<Group | null, ObjectViewInternalProps>(
|
||||
function ({ object, objectType, onClick }, ref) {
|
||||
const trimeshArgs = useMemo(
|
||||
() => buildObjectTrimesh(objectType, state.world.data.voxelTypes),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[objectType.id]
|
||||
);
|
||||
function ({ object, objectType, ...props }, ref) {
|
||||
|
||||
return (
|
||||
<SyncRigidBody
|
||||
colliders={false}
|
||||
gravityScale={object.physics ? 1 : 0.1}
|
||||
onSync={(data) => {
|
||||
runInAction(() => {
|
||||
const obj = state.game?.scene.objects[object.id];
|
||||
if (obj) {
|
||||
obj.position = data.position;
|
||||
obj.rotation = data.rotation;
|
||||
obj.linearVelocity = data.linearVelocity;
|
||||
obj.radialVelocity = data.radialVelocity;
|
||||
}
|
||||
});
|
||||
onSync={(_data) => {
|
||||
// TODO rewrite so that is does not trigger re-render
|
||||
// runInAction(() => {
|
||||
// object.position = data.position;
|
||||
// object.rotation = data.rotation;
|
||||
// if (!props.isEditor) {
|
||||
// (object as RuntimeGameObjectInstance).linearVelocity = data.linearVelocity;
|
||||
// (object as RuntimeGameObjectInstance).radialVelocity = data.radialVelocity;
|
||||
// }
|
||||
// });
|
||||
}}
|
||||
>
|
||||
<group
|
||||
@@ -46,7 +39,7 @@ export const ObjectViewInternal = observer(forwardRef<Group | null, ObjectViewIn
|
||||
position={object.position}
|
||||
rotation={object.rotation}
|
||||
scale={object.scale}
|
||||
onClick={onClick}
|
||||
onClick={props.onClick}
|
||||
>
|
||||
{
|
||||
object.cache.voxelGroups.map((vg) =>
|
||||
@@ -57,7 +50,7 @@ export const ObjectViewInternal = observer(forwardRef<Group | null, ObjectViewIn
|
||||
</Instances>
|
||||
)
|
||||
}
|
||||
{trimeshArgs && <TrimeshCollider args={trimeshArgs} />}
|
||||
{object.cache.colliderMesh && <ConvexHullCollider args={[object.cache.colliderMesh[0]]} />}
|
||||
</group>
|
||||
</SyncRigidBody>
|
||||
);
|
||||
|
||||
@@ -2,8 +2,6 @@ import { observer } from "mobx-react-lite";
|
||||
import type { RuntimeScene } from "../types";
|
||||
import { CharacterView } from "./CharacterView";
|
||||
import { GameObjectView } from "./GameObjectView";
|
||||
import { useFrame } from "@react-three/fiber";
|
||||
import { useRapier } from "@react-three/rapier";
|
||||
import { ObjectEditorView } from "./ObjectEditorView";
|
||||
|
||||
type SceneViewProps = {
|
||||
@@ -12,9 +10,9 @@ type SceneViewProps = {
|
||||
}
|
||||
|
||||
export const SceneView = observer(function (props: SceneViewProps) {
|
||||
const rapier = useRapier();
|
||||
// const rapier = useRapier();
|
||||
|
||||
useFrame((_, dt) => {
|
||||
// useFrame((_, dt) => {
|
||||
// if (props.editMode)
|
||||
// return;
|
||||
|
||||
@@ -23,7 +21,7 @@ export const SceneView = observer(function (props: SceneViewProps) {
|
||||
// return;
|
||||
|
||||
// rapier.step(dt);
|
||||
})
|
||||
// })
|
||||
|
||||
return (<>
|
||||
<ambientLight intensity={0.5} />
|
||||
|
||||
Reference in New Issue
Block a user