Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlendShape(with MorphTarget) is broken #1

Open
il-m-yamagishi opened this issue May 14, 2019 · 2 comments

Comments

@il-m-yamagishi
Copy link
Contributor

commented May 14, 2019

Update: It will be fixed at babylon.js v4.1.0!

Summary

some vrm BlendShape(uses MorphTarget) do not morph correctly.

Specs

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets

A Morph Target is a morphable Mesh where primitives' attributes are obtained by adding the original attributes to a weighted sum of targets attributes.

primitives[i].attributes.POSITION + 
  weights[0] * primitives[i].targets[0].POSITION +
  weights[1] * primitives[i].targets[1].POSITION +
  weights[2] * primitives[i].targets[2].POSITION + ...

primitives[i].targets[0].POSITION has relative position from original primitive position.

Implementations

OnLoading

https://github.com/BabylonJS/Babylon.js/blob/master/loaders/src/glTF/2.0/glTFLoader.ts#L898

        loadAttribute("POSITION", VertexBuffer.PositionKind, (babylonVertexBuffer, data) => {
            babylonVertexBuffer.forEach(data.length, (value, index) => {
                data[index] += value;
            });

            babylonMorphTarget.setPositions(data);
        });

babylonMorphTarget: MorphTarget has sum of original primitive position and morph relative position.

On GLSL

https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ShadersInclude/morphTargetsVertex.fx

// positionUpdated is original primitive position plus previous morphed position
// position is original primitive position
// position{X} is MorphTarget position
// morphTargetInfluences[{X}] is weight
	positionUpdated += (position{X} - position) * morphTargetInfluences[{X}];

Tests

glTF Sample

AliciaSolid from https://3d.nicovideo.jp/works/td32797

NG: All face.baked Mesh's MorphTarget

image (5)

OK: other.baked Mesh's MorphTarget

image (6)

VRoid Studio from https://studio.vroid.com/

NG

image (7)

ref. three.js

https://rdrgn.github.io/three-vrm/

All of above models are OK.

Implementations

OnLoading

https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/GLTFLoader.js#L1403

					// Three.js morph position is absolute value. The formula is
					//   basePosition
					//     + weight0 * ( morphPosition0 - basePosition )
					//     + weight1 * ( morphPosition1 - basePosition )
					//     ...
					// while the glTF one is relative
					//   basePosition
					//     + weight0 * glTFmorphPosition0
					//     + weight1 * glTFmorphPosition1
					//     ...
					// then we need to convert from relative to absolute here.

					if ( target.POSITION !== undefined ) {

						var positionAttribute = morphPositions[ i ];
						positionAttribute.name = attributeName;

						var position = geometry.attributes.position;

						for ( var j = 0, jl = positionAttribute.count; j < jl; j ++ ) {

							positionAttribute.setXYZ(
								j,
								positionAttribute.getX( j ) + position.getX( j ),
								positionAttribute.getY( j ) + position.getY( j ),
								positionAttribute.getZ( j ) + position.getZ( j )
							);

						}

					}

Implementations: On GLSL

https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js

	transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];

Where is implementation difference between babylon.js and three.js?

refs

@il-m-yamagishi

This comment has been minimized.

@il-m-yamagishi

This comment has been minimized.

Copy link
Contributor Author

commented May 20, 2019

It will be fixed at babylon.js v4.1.0!

il-m-yamagishi added a commit that referenced this issue Jun 28, 2019

il-m-yamagishi pushed a commit that referenced this issue Jun 28, 2019

chore(release): 1.4.1 [skip ci]
## [1.4.1](v1.4.0...v1.4.1) (2019-06-28)

### Bug Fixes

* **MorphTarget:** mesh must be found multiple ([4bb2166](4bb2166)), closes [#1](#1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.