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

MMDPhysics: Use CapsuleGeometry. #24448

Merged
merged 1 commit into from
Aug 5, 2022
Merged
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
23 changes: 2 additions & 21 deletions examples/jsm/animation/MMDPhysics.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Bone,
BoxGeometry,
CapsuleGeometry,
Color,
CylinderGeometry,
Euler,
Matrix4,
Mesh,
Expand Down Expand Up @@ -1358,7 +1358,7 @@ class MMDPhysicsHelper extends Object3D {
return new BoxGeometry( param.width * 2, param.height * 2, param.depth * 2, 8, 8, 8 );

case 2:
return new createCapsuleGeometry( param.width, param.height, 16, 8 );
return new CapsuleGeometry( param.width, param.height, 8, 16 );

default:
return null;
Expand All @@ -1367,25 +1367,6 @@ class MMDPhysicsHelper extends Object3D {

}

function createCapsuleGeometry( radius, cylinderHeight, segmentsRadius, segmentsHeight ) {

var geometry = new CylinderGeometry( radius, radius, cylinderHeight, segmentsRadius, segmentsHeight, true );
var upperSphere = new Mesh( new SphereGeometry( radius, segmentsRadius, segmentsHeight, 0, Math.PI * 2, 0, Math.PI / 2 ) );
var lowerSphere = new Mesh( new SphereGeometry( radius, segmentsRadius, segmentsHeight, 0, Math.PI * 2, Math.PI / 2, Math.PI / 2 ) );

upperSphere.position.set( 0, cylinderHeight / 2, 0 );
lowerSphere.position.set( 0, - cylinderHeight / 2, 0 );

upperSphere.updateMatrix();
lowerSphere.updateMatrix();

geometry.merge( upperSphere.geometry, upperSphere.matrix );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was actually broken since a matrix is no valid argument. It has to be an integer. This bug broke the merge and thus the entire geometry generation.

I guess this issue was overlooked when Geometry was deprecated since BufferGeometry.merge() works differently than Geometry.merge().

Related #24443.

geometry.merge( lowerSphere.geometry, lowerSphere.matrix );

return geometry;

}

for ( var i = 0, il = bodies.length; i < il; i ++ ) {

var param = bodies[ i ].params;
Expand Down