三个js角度:属性“dispose”在类型“Material |”上不存在 材料[]'

Din*_*ino 5 types three.js angular

我有一个 Angular 6.0.5,运行三个。

全部使用三个版本 0.89.0 和 @types/三个版本 0.84.3

我已经更新到三个版本0.93.0和@types/三个版本0.92.5

现在一切都坏了。我收到以下错误:

Property 'dispose' does not exist on type 'Material | Material[]'.

Property 'dispose' does not exist on type 'Material[]'.
Run Code Online (Sandbox Code Playgroud)

Property 'clippingPlanes' does not exist on type 'Material | 
Material[]'.
Property 'clippingPlanes' does not exist on type 'Material[]'.
Run Code Online (Sandbox Code Playgroud)

Property 'clippingPlanes' does not exist on type 'Material | 
Material[]'.

Property 'clippingPlanes' does not exist on type 'Material[]'.
Run Code Online (Sandbox Code Playgroud)

Argument of type '{ shading: Shading; side: Side; shininess: number; 
color: number; transparent: true; opacity: num...' is not assignable 
to parameter of type 'MeshPhongMaterialParameters'.

Object literal may only specify known properties, and 'shading' does 
not exist in type 'MeshPhongMaterialParameters'.
Run Code Online (Sandbox Code Playgroud)

我的猜测是类型和库不兼容。有人知道如何解决这个烂摊子吗?

小智 3

我也遇到了这个问题。因为没有Multimaterial,所以必须使用材质数组。如果你看一下 Mesh 中“材质”的签名,它现在是:材质 | Material[],因此您无法直接将其作为材质访问。我所做的,假设你从不使用材质数组,被转换为 ,例如:

mesh1.material.dispose();  //error since material could be an array
(<any>mesh1.material).dispose();     //OK since it doesn't know what it is
Run Code Online (Sandbox Code Playgroud)

我认为一般的解决方案是检查数组并单独处理每种情况,但这会导致代码难看,所以也许有更好的解决方案。

您的另一个问题是“shading”已更改为布尔值“flatShading”。