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

[1.0] Follow new constraint spec #934

Merged
merged 8 commits into from
Mar 17, 2022
108 changes: 78 additions & 30 deletions packages/three-vrm-node-constraint/examples/aim.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>three-vrm-constraints example - position.html</title>
<title>three-vrm-constraints example - aim.html</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
Expand All @@ -21,8 +21,45 @@
<body>
<script src="https://unpkg.com/three@0.137.4/build/three.js"></script>
<script src="https://unpkg.com/three@0.137.4/examples/js/controls/OrbitControls.js"></script>
<script src="https://unpkg.com/tweakpane@3.0"></script>
<script src="https://unpkg.com/@0b5vr/tweakpane-plugin-rotation@0.1"></script>
<script src="../lib/three-vrm-node-constraint.js"></script>
<script>
// gui
const guiParams = {

upperArm: { x: 0.0, y: 0.0, z: 0.0 },
lowerArm: { x: 0.0, y: 0.0, z: 0.0 },
weight: 1.0,

};

const pane = new Tweakpane.Pane();
pane.registerPlugin( TweakpaneRotationInputPlugin );

pane.addInput( guiParams, 'upperArm', {

view: 'rotation',
rotationMode: 'euler',
unit: 'deg',

} );

pane.addInput( guiParams, 'lowerArm', {

view: 'rotation',
rotationMode: 'euler',
unit: 'deg',

} );

pane.addInput( guiParams, 'weight', {

min: 0.0,
max: 1.0,

} );

// renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
Expand All @@ -31,12 +68,12 @@

// camera
const camera = new THREE.PerspectiveCamera( 30.0, window.innerWidth / window.innerHeight, 0.1, 20.0 );
camera.position.set( 0.0, 0.5, 5.0 );
camera.position.set( 0.0, 1.0, 10.0 );

// camera controls
const controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = true;
controls.target.set( 0.0, 0.5, 0.0 );
controls.target.set( 0.0, 1.0, 0.0 );
controls.update();

// scene
Expand All @@ -48,28 +85,22 @@
scene.add( light );

// objects
const modelRoot = new THREE.Object3D();
modelRoot.name = 'modelRoot';
scene.add( modelRoot );

const parent = new THREE.Object3D();
parent.name = 'parent';
parent.rotation.y = Math.PI;
modelRoot.add( parent );

const geometryCone = new THREE.ConeBufferGeometry( 0.25, 0.5, 5 );
const geometryCube = new THREE.BoxGeometry( 0.25, 0.25, 0.25 );
const geometry = new THREE.ConeBufferGeometry( 0.25, 0.5, 5 );
const material = new THREE.MeshStandardMaterial( { color: 0xbbbbbb } );

const cone = new THREE.Mesh( geometryCone, material );
cone.rotation.x = Math.PI / 4.0;
cone.name = 'cone';
parent.add( cone );
const upperArm = new THREE.Mesh( geometry, material );
upperArm.name = 'upperArm';
scene.add( upperArm );

const cube = new THREE.Mesh( geometryCube, material );
cube.name = 'cube';
cube.position.set( 0.0, 1.0, 1.0 );
parent.add( cube );
const lowerArm = new THREE.Mesh( geometry, material );
lowerArm.position.y = 2.0;
lowerArm.name = 'lowerArm';
upperArm.add( lowerArm );

const aim = new THREE.Mesh( geometry, material );
aim.position.x = 1.0;
aim.name = 'aim';
scene.add( aim );

// helpers
const gridHelper = new THREE.GridHelper( 10, 10 );
Expand All @@ -79,14 +110,15 @@
scene.add( axesHelper );

// constraints
const constraintManager = new THREE_VRM_NODE_CONSTRAINT.VRMNodeConstraintManager({
const constraintManager = new THREE_VRM_NODE_CONSTRAINT.VRMNodeConstraintManager( {

autoRemoveCircularDependency: true
});

const constraint = new THREE_VRM_NODE_CONSTRAINT.VRMAimConstraint(cone, modelRoot);
constraint.aimVector.set( 0.0, 0.0, 1.0 ).normalize();
constraint.setSource(cube);
constraintManager.addConstraint(constraint);
} );

const constraint = new THREE_VRM_NODE_CONSTRAINT.VRMAimConstraint( aim, lowerArm );
Copy link
Contributor

Choose a reason for hiding this comment

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

[MEMO]

aimがlowerArmに従う。
仕様より +Y 軸がlowerArmのほうにむく。

constraint.aimAxis = '+Y';
constraintManager.addConstraint( constraint );

// constraint helpers
Array.from( constraintManager.constraints ).forEach( ( constraint ) => {
Expand All @@ -107,9 +139,25 @@

requestAnimationFrame( animate );

const deltaTime = clock.getDelta();
upperArm.rotation.set(

THREE.MathUtils.DEG2RAD * guiParams.upperArm.x,
THREE.MathUtils.DEG2RAD * guiParams.upperArm.y,
THREE.MathUtils.DEG2RAD * guiParams.upperArm.z,
'ZYX',

);

lowerArm.rotation.set(

THREE.MathUtils.DEG2RAD * guiParams.lowerArm.x,
THREE.MathUtils.DEG2RAD * guiParams.lowerArm.y,
THREE.MathUtils.DEG2RAD * guiParams.lowerArm.z,
'ZYX',

);

cube.position.x = 2.0 * Math.sin( clock.elapsedTime );
constraint.weight = guiParams.weight;

constraintManager.update();

Expand Down
32 changes: 29 additions & 3 deletions packages/three-vrm-node-constraint/examples/importer.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@
<script src="https://unpkg.com/three@0.137.4/build/three.js"></script>
<script src="https://unpkg.com/three@0.137.4/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://unpkg.com/three@0.137.4/examples/js/controls/OrbitControls.js"></script>
<script src="https://unpkg.com/tweakpane@3.0"></script>
<script src="https://unpkg.com/@0b5vr/tweakpane-plugin-rotation@0.1"></script>
<script src="../lib/three-vrm-node-constraint.js"></script>
<script>
// gui
const guiParams = {

source: { x: 0.0, y: 0.0, z: 0.0 },

};

const pane = new Tweakpane.Pane();
pane.registerPlugin( TweakpaneRotationInputPlugin );

pane.addInput( guiParams, 'source', {

view: 'rotation',
rotationMode: 'euler',
unit: 'deg',

} );

// renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
Expand Down Expand Up @@ -112,10 +132,16 @@

if ( currentGltf ) {

const cubeA = currentGltf.scene.children.find( ( node ) => node.name === 'CubeA' );
const source = currentGltf.scene.children.find( ( node ) => node.name === 'CubeA' );

source.rotation.set(

THREE.MathUtils.DEG2RAD * guiParams.source.x,
THREE.MathUtils.DEG2RAD * guiParams.source.y,
THREE.MathUtils.DEG2RAD * guiParams.source.z,
'ZYX',

cubeA.rotation.x = Math.cos( clock.elapsedTime );
cubeA.rotation.y = Math.sin( clock.elapsedTime );
);

const constraintManager = currentGltf.userData.vrmNodeConstraintManager;
constraintManager.update();
Expand Down
8 changes: 6 additions & 2 deletions packages/three-vrm-node-constraint/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@

<body>
<h1>examples of <a href="https://github.com/pixiv/three-vrm/tree/dev/packages/three-vrm-node-constraint/">@pixiv/three-vrm-node-constraint</a></h1>
<p>
<a href="roll.html">roll.html</a><br />
Use roll constraint
</p>
<p>
<a href="aim.html">aim.html</a><br />
Use aim constraint
</p>
<p>
<a href="position.html">position.html</a><br />
Use position constraint
<a href="upper-arm.html">upper-arm.html</a><br />
Combine aim constraint and roll constraint to perform upper arm twist
</p>
<p>
<a href="rotation.html">rotation.html</a><br />
Expand Down
5 changes: 2 additions & 3 deletions packages/three-vrm-node-constraint/examples/models/cubes.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@
"VRMC_node_constraint": {
"specVersion": "1.0-draft",
"constraint": {
"rotation": {
"roll": {
Copy link
Contributor

Choose a reason for hiding this comment

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

MEMO

RollConstraintの指定
0番目のノードよりY軸回転の影響を受ける。

"source": 0,
"axes": [true, false, false],
"rollAxis": "Y",
"weight": 1.0
}
}
Expand Down Expand Up @@ -355,7 +355,6 @@
"constraint": {
"rotation": {
"source": 0,
"axes": [true, true, true],
"weight": 0.5
}
}
Expand Down
Loading