1.vite.config.js多入口配置
import vitePluginCompress from 'vite-plugin-compression'
const isCodeSandbox = 'SANDBOX_URL' in process.env || 'CODESANDBOX_HOST' in process.env
import {resolve} from 'path'
import {sync} from 'glob'
// 保存每个页面的名称和路径,后面会用到
const multiPage = {};
// 保存页面文件路径
const pageEntry = {};
function getInput() {
const allEntry = sync("src/*/index.html");
allEntry.forEach((entry) => {
const pathArr = entry.split("\\");
const name = pathArr[pathArr.length - 2];
multiPage[name] = {
name,
rootPage: `./src/${name}/index.html`,
};
pageEntry[name] = `./src/${name}/index.html`;
});
}
// 调用一下
getInput()
export default {
plugins:
[
react(),
vitePluginCompress(),
],
root: 'src/',//确定项目运行和编译的根目录
publicDir: "../public",//相对于根目录或root+base?
base: './',//相对于根目录
server:
{
host: true,
open: !isCodeSandbox // Open if it's not a CodeSandbox
},
build:
{
rollupOptions: {
// 在这里引入就行
input: pageEntry,
},
outDir: '../docs',
emptyOutDir: true,
sourcemap: false
}
}
2.在R3F中两个刚性模型,如果移动速度过快,会穿模没有碰撞体积,怎么处理? juejin.cn/post/721226…
方案一:r3f的 physics组件设置时间步长
import { Physics } from '@react-three/cannon'
function App() {
return (
<Physics allowSleep={true} step={1 / 120}>
{/* ... */}
</Physics>
)
}
方案二:r3f的组件开启连续碰撞检测
import { Physics, useSphere } from '@react-three/cannon'
function Sphere(props) {
const [ref] = useSphere(() => ({ mass: 1, position: [0, 5, 0], args: 1 }))
return (
<mesh ref={ref} {...props}>
<sphereBufferGeometry />
<meshStandardMaterial />
</mesh>
)
}
function App() {
return (
<Canvas>
<ambientLight />
<pointLight position={[10, 10, 10]} />
<Physics>
<Sphere ccdSpeedThreshold={0.5} ccdIterations={10} />
{/* 其他物体 */}
</Physics>
</Canvas>
)
}
方案三:r3f的 physics组件设置 broadphase
<Physics
iterations={20}
tolerance={0.0001}
defaultContactMaterial={{
contactEquationRelaxation: 1,
contactEquationStiffness: 1e7,
friction: 0.9,
frictionEquationRelaxation: 2,
frictionEquationStiffness: 1e7,
restitution: 0.7,
depthWrite:false
}}
broadphase="Naive"
gravity={[0, -40, 0]}
allowSleep={false}
step={1 / 120}
ccdSpeedThreshold={0.5} ccdIterations={10}
>
三个方案都试了,都不行啊。。。