I am having issues trying to make collision work properly with an imported glb file only used for collision.
There are two parts to this question:
- I am currently getting a whole lot of faceNormal errors and vertices warnings in the console.
.faceNormals[767] = Vec3(0.999994684003945,-4.252105447140875e-10,0.003260669233505899) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.
.vertices[555] = Vec3(-18.135730743408203,9.071623802185059,-13.433568000793457)
I am not sure if this error has something to do with how I'm merging the geometry of the object or how the object is built inside blender.
- When my sphere collides with the glb model it will clip through it sometimes with enough force. (holding down the W key to move the sphere forward). It clips through especially on the edges of the environment, against a flat wall it gives some resistance but still manages to clip through with enough time holding down a movement key.
Here is the code I'm using to import my glb model:
import React, { useMemo } from "react";
import { useConvexPolyhedron } from "@react-three/cannon";
import { Geometry } from "three-stdlib/deprecated/Geometry";
import {useGLTF} from "@react-three/drei";
import collision from "./Collision6.glb";
function toConvexProps(bufferGeometry) {
const geo = new Geometry().fromBufferGeometry(bufferGeometry);
geo.mergeVertices();
return [geo.vertices.map((v) => [v.x, v.y, v.z]), geo.faces.map((f) => [f.a, f.b, f.c]), []];
}
export default function Collision(props) {
const { nodes } = useGLTF(collision);
const geo = useMemo(() => toConvexProps(nodes.Collision001.geometry), [nodes]);
const [ref] = useConvexPolyhedron(() => ({ type: 'Static', mass: 100 ,position:[0,0,0], args: geo
}));
return (
<mesh
ref={ref}
geometry={nodes.Collision001.geometry}
>
<meshStandardMaterial wireframe color="#ff0000" opacity={0} transparent />
</mesh>
);
}