szr*_*ght 5 blender cannon.js reactjs react-three-fiber react-three-drei
我在尝试使用仅用于碰撞的导入 glb 文件使碰撞正常工作时遇到问题。
这个问题有两个部分:
.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.
Run Code Online (Sandbox Code Playgroud)
.vertices[555] = Vec3(-18.135730743408203,9.071623802185059,-13.433568000793457)
Run Code Online (Sandbox Code Playgroud)
我不确定这个错误是否与我如何合并对象的几何形状或对象如何在搅拌机内构建有关。
这是我用来导入 glb 模型的代码:
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>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |