Skip to content

Commit

Permalink
fix: jolt context type
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-mason committed Apr 14, 2024
1 parent be70fbd commit 94033f4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
10 changes: 2 additions & 8 deletions packages/react-three-jolt/src/components/Heightfield.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useTexture } from '@react-three/drei';
import React, { useEffect, useRef } from 'react';
import { BodyState } from 'src';
import * as THREE from 'three';
import { applyHeightmapToPlane } from '../heightField/Generators';
import { useJolt, useUnmount } from '../hooks';
Expand All @@ -24,7 +23,7 @@ export function Heightfield({
...props
}: HeightfieldProps) {
const planeRef = useRef<THREE.Mesh>(null);
const activeBody: React.MutableRefObject<BodyState | null> = useRef(null);
const activeBody: React.MutableRefObject<number | null> = useRef(null);

const { bodySystem } = useJolt();
// try and load the url as a texture
Expand Down Expand Up @@ -66,12 +65,7 @@ export function Heightfield({
<>
<mesh ref={planeRef} {...props}>
<planeGeometry args={[width, height, size - 1, size - 1]} />
<meshStandardMaterial
transparent={true}
//opacity={0.2}
color="#8F2D56"
side={THREE.DoubleSide}
/>
<meshStandardMaterial transparent={true} color="#8F2D56" side={THREE.DoubleSide} />
</mesh>
</>
);
Expand Down
5 changes: 2 additions & 3 deletions packages/react-three-jolt/src/components/Physics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Jolt from 'jolt-physics';
//import InitJolt from 'jolt-physics/wasm-compat'
import { suspend } from 'suspend-react';
import { Raw, initJolt } from '../raw';
import { joltContext } from '../context';
import { JoltContext, joltContext } from '../context';
import {
FC,
ReactNode,
Expand Down Expand Up @@ -86,7 +86,7 @@ export const Physics: FC<PhysicsProps> = (props) => {
const pid = useId();

const [physicsSystem, setPhysicsSystem] = useState<PhysicsSystem>();
const [contextApi, setContextApi] = useState({});
const [contextApi, setContextApi] = useState<JoltContext>();

useMount(() => {
console.log('** Physics Component: ' + pid + ' Mounted **');
Expand Down Expand Up @@ -138,7 +138,6 @@ export const Physics: FC<PhysicsProps> = (props) => {
if (physicsSystem.paused !== paused) physicsSystem.paused = paused;
}, [debug, jolt, paused, physicsSystem, step]);

//@ts-ignore
if (!contextApi || !contextApi.physicsSystem) return null;

return (
Expand Down
7 changes: 3 additions & 4 deletions packages/react-three-jolt/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { createContext } from 'react';
import type { BodySystem } from './systems/body-system';
import type { PhysicsSystem } from './systems/physics-system';

// Context object
export interface JoltContext {
export type JoltContext = {
jolt: typeof Jolt;
physicsSystem: PhysicsSystem;
bodySystem: BodySystem;
joltInterface: Jolt.JoltInterface;
paused: boolean;
debug: boolean;
step: (dt: number) => void;
}
};

export const joltContext = createContext<any>(undefined);
export const joltContext = createContext<JoltContext>(null!);
2 changes: 1 addition & 1 deletion packages/react-three-jolt/src/systems/body-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class BodySystem {
}

// There's probably a better pattern, but im making my own function for this
public addHeightfield(planeMesh: THREE.Mesh) {
public addHeightfield(planeMesh: THREE.Mesh): number {
//const position = vec3.threeToJolt(planeMesh.position);
// const quaternion = quat.threeToJolt(planeMesh.quaternion);
const shapeSettings = generateHeightfieldShapeFromThree(planeMesh);
Expand Down

0 comments on commit 94033f4

Please sign in to comment.