Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 56 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"eslint-config-mdcs": "^5.0.0",
"eslint-plugin-compat": "^6.0.0",
"eslint-plugin-html": "^8.1.3",
"eslint-plugin-jsdoc": "^61.4.1",
"eslint-plugin-jsdoc": "^62.0.0",
"globals": "^17.0.0",
"jpeg-js": "^0.4.4",
"jsdoc": "^4.0.5",
Expand Down
18 changes: 11 additions & 7 deletions src/nodes/accessors/SkinningNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ class SkinningNode extends Node {
}

/**
* Transforms the given vertex normal via skinning.
* Transforms the given vertex normal and tangent via skinning.
*
* @param {Node} [boneMatrices=this.boneMatricesNode] - The bone matrices
* @param {Node<vec3>} [normal=normalLocal] - The vertex normal in local space.
* @return {Node<vec3>} The transformed vertex normal.
* @param {Node<vec3>} [tangent=tangentLocal] - The vertex tangent in local space.
* @return {{skinNormal: Node<vec3>, skinTangent:Node<vec3>}} The transformed vertex normal and tangent.
*/
getSkinnedNormal( boneMatrices = this.boneMatricesNode, normal = normalLocal ) {
getSkinnedNormalAndTangent( boneMatrices = this.boneMatricesNode, normal = normalLocal, tangent = tangentLocal ) {

const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this;

Expand All @@ -161,7 +162,7 @@ class SkinningNode extends Node {
const boneMatZ = boneMatrices.element( skinIndexNode.z );
const boneMatW = boneMatrices.element( skinIndexNode.w );

// NORMAL
// NORMAL and TANGENT

let skinMatrix = add(
skinWeightNode.x.mul( boneMatX ),
Expand All @@ -172,7 +173,10 @@ class SkinningNode extends Node {

skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );

return skinMatrix.transformDirection( normal ).xyz;
const skinNormal = skinMatrix.transformDirection( normal ).xyz;
const skinTangent = skinMatrix.transformDirection( tangent ).xyz;

return { skinNormal, skinTangent };

}

Expand Down Expand Up @@ -220,13 +224,13 @@ class SkinningNode extends Node {

if ( builder.hasGeometryAttribute( 'normal' ) ) {

const skinNormal = this.getSkinnedNormal();
const { skinNormal, skinTangent } = this.getSkinnedNormalAndTangent();

normalLocal.assign( skinNormal );

if ( builder.hasGeometryAttribute( 'tangent' ) ) {

tangentLocal.assign( skinNormal );
tangentLocal.assign( skinTangent );

}

Expand Down
15 changes: 15 additions & 0 deletions src/nodes/core/StructNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ class StructNode extends Node {

}

_getChildren() {

// Ensure struct type is the last child for correct code generation order

const children = super._getChildren();

const structTypeProperty = children.find( child => child.childNode === this.structTypeNode );

children.splice( children.indexOf( structTypeProperty ), 1 );
children.push( structTypeProperty );

return children;

}

generate( builder ) {

const nodeVar = builder.getVarFromNode( this );
Expand Down
Loading