From 2f56a703d9c7156f9c3ffd29ada2f44925a03984 Mon Sep 17 00:00:00 2001 From: 0b5vr <0b5vr@0b5vr.com> Date: Fri, 26 Jul 2024 12:51:19 +0900 Subject: [PATCH] fix: Fix type of NodeMaterial members See about the type assertion: https://github.com/three-types/three-ts-types/pull/1123 --- .../src/nodes/MToonNodeMaterial.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts b/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts index 49b69d8ec..b707c2bd1 100644 --- a/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts +++ b/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts @@ -255,7 +255,7 @@ export class MToonNodeMaterial extends THREE.NodeMaterial { public setupNormal(builder: THREE.NodeBuilder): void { // we must apply uv scroll to the normalMap // this.normalNode will be used in super.setupNormal() so we temporarily replace it - const tempNormalNode: THREE.ShaderNodeObject | null = this.normalNode; + const tempNormalNode = this.normalNode; if (this.normalNode == null) { this.normalNode = THREE.materialNormal; @@ -266,7 +266,8 @@ export class MToonNodeMaterial extends THREE.NodeMaterial { } if (this.isOutline) { - this.normalNode = this.normalNode.negate(); + // See about the type assertion: https://github.com/three-types/three-ts-types/pull/1123 + this.normalNode = (this.normalNode as THREE.ShaderNodeObject).negate(); } } @@ -323,7 +324,7 @@ export class MToonNodeMaterial extends THREE.NodeMaterial { public setupPosition(builder: THREE.NodeBuilder): THREE.ShaderNodeObject { // we must apply outline position offset // this.positionNode will be used in super.setupPosition() so we temporarily replace it - const tempPositionNode: THREE.ShaderNodeObject | null = this.positionNode; + const tempPositionNode = this.positionNode; if (this.isOutline && this.outlineWidthMode !== MToonMaterialOutlineWidthMode.None) { this.positionNode ??= THREE.positionLocal; @@ -341,11 +342,15 @@ export class MToonNodeMaterial extends THREE.NodeMaterial { const outlineOffset = width.mul(worldNormalLength).mul(normalLocal); if (this.outlineWidthMode === MToonMaterialOutlineWidthMode.WorldCoordinates) { - this.positionNode = this.positionNode.add(outlineOffset); + // See about the type assertion: https://github.com/three-types/three-ts-types/pull/1123 + this.positionNode = (this.positionNode as THREE.ShaderNodeObject).add(outlineOffset); } else if (this.outlineWidthMode === MToonMaterialOutlineWidthMode.ScreenCoordinates) { const clipScale = THREE.cameraProjectionMatrix.element(1).element(1); - this.positionNode = this.positionNode.add(outlineOffset.div(clipScale).mul(THREE.positionView.z.negate())); + // See about the type assertion: https://github.com/three-types/three-ts-types/pull/1123 + this.positionNode = (this.positionNode as THREE.ShaderNodeObject).add( + outlineOffset.div(clipScale).mul(THREE.positionView.z.negate()), + ); } this.positionNode ??= THREE.positionLocal;