Skip to content

Commit

Permalink
fix: Fix type of NodeMaterial members
Browse files Browse the repository at this point in the history
See about the type assertion: three-types/three-ts-types#1123
  • Loading branch information
0b5vr committed Jul 26, 2024
1 parent e753d89 commit 2f56a70
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<THREE.Node> | null = this.normalNode;
const tempNormalNode = this.normalNode;

if (this.normalNode == null) {
this.normalNode = THREE.materialNormal;
Expand All @@ -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<THREE.Node>).negate();
}
}

Expand Down Expand Up @@ -323,7 +324,7 @@ export class MToonNodeMaterial extends THREE.NodeMaterial {
public setupPosition(builder: THREE.NodeBuilder): THREE.ShaderNodeObject<THREE.Node> {
// we must apply outline position offset
// this.positionNode will be used in super.setupPosition() so we temporarily replace it
const tempPositionNode: THREE.ShaderNodeObject<THREE.Node> | null = this.positionNode;
const tempPositionNode = this.positionNode;

if (this.isOutline && this.outlineWidthMode !== MToonMaterialOutlineWidthMode.None) {
this.positionNode ??= THREE.positionLocal;
Expand All @@ -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<THREE.Node>).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<THREE.Node>).add(
outlineOffset.div(clipScale).mul(THREE.positionView.z.negate()),
);
}

this.positionNode ??= THREE.positionLocal;
Expand Down

0 comments on commit 2f56a70

Please sign in to comment.