gpt4 book ai didi

typescript - Shaders with Typescript 和 React 三纤

转载 作者:行者123 更新时间:2023-12-02 02:27:19 25 4
gpt4 key购买 nike

我正在尝试将着色器与 React-three-fiber 和 Typescript 结合使用。着色器文件:

import { ShaderMaterial } from "three"
import { extend } from "react-three-fiber"

class CustomMaterial extends ShaderMaterial {
constructor() {
super({
vertexShader: `...`,
fragmentShader: `...`,
uniforms: [...]
})
}
}

extend({ CustomMaterial })

和组件文件:

<mesh
key={el.name}
material={el.material}
receiveShadow
castShadow
>
<bufferGeometry attach="geometry" {...el.geometry} />
<customMaterial attach="material" />
</mesh>

我遇到错误:

Property 'customMaterial' does not exist on type'JSX.IntrinsicElements'.

最佳答案

尝试:

declare global {
namespace JSX {
interface IntrinsicElements {
customMaterial: ReactThreeFiber.Object3DNode<CustomMaterial, typeof CustomMaterial>
}
}
}

您可能还需要在导入中坚持以下内容:

import { extend } from 'react-three-fiber'
...
extend ({ CustomMaterial })

关于typescript - Shaders with Typescript 和 React 三纤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65459024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com