-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b752728
commit e425618
Showing
24 changed files
with
2,221 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title></title></head><body> | ||
<script type="module"> | ||
|
||
//#region IMPORTS | ||
import Starter, { THREE } from './_lib/Starter.js'; | ||
import ShapePointsMesh from './_lib/ShapePointsMesh.js'; | ||
import DynLineMesh from './_lib/DynLineMesh.js'; | ||
|
||
import { Gltf2 } from './_lib/UtilGltf2.js'; | ||
import UtilArm from './_lib/UtilArm.js'; | ||
|
||
import { BipedRig } from '../../src/ikrig/index'; | ||
//#endregion | ||
|
||
//#region MAIN | ||
let App; | ||
let debug = {}; | ||
let Ref = {}; | ||
|
||
function onRender( dt=0, et=0 ){} | ||
|
||
window.addEventListener( "load", async _=>{ | ||
App = new Starter( { webgl2:true, grid:true } ); | ||
App.setCamera( 0, 20, 4, [0,0.8,0] ); | ||
//App.onRender = onRender; | ||
|
||
App.add( ( debug.pnt = new ShapePointsMesh() ) ); | ||
App.add( ( debug.ln = new DynLineMesh() ) ); | ||
|
||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
const gltf = await Gltf2.fetch( '../_res/models/nabba/nabba.gltf' ); | ||
const arm = UtilArm.armFromGltf( gltf ); // Armature Setup Boiler Plate Abstracted | ||
const boneView = UtilArm.newBoneView( arm ); // BoneView for 3JS Boiler Plate Abstracted | ||
const mesh = UtilArm.skinMtxMesh( gltf, arm ); // Create a Skinned Mesh for 3JS Boiler Plate Abstracted | ||
const pose = arm.newPose(); // Working Pose to save IK Results | ||
|
||
App.add( boneView ); | ||
App.add( mesh ); | ||
|
||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
const rig = new BipedRig(); | ||
rig.autoRig( arm ); | ||
|
||
// When Skinning BindPose is not a TPose, Need to create or set it | ||
// somehow, then use that to load the rig | ||
// createOrLoad_TPose( pose ); | ||
// pose.updateWorld(); | ||
// rig.bindPose( pose ); | ||
// rig.useSolversForRetarget( pose ); | ||
|
||
// BUT if The Skin BindPose is a TPose, Can get away using Armature instead of pose. | ||
rig.bindPose( arm ); // Late Binding of TPose for the chains: Rigs only work with TPoses | ||
rig.useSolversForRetarget( arm ); // Use Default Solvers for known chains, Should Happen After Bind | ||
|
||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
const apos = [ 0.3, 0.6, -0.1 ]; | ||
const lpos = [ 0.2, 0.1, 0.1 ]; | ||
debug.pnt.add( apos, 0x00ff00, 1 ); | ||
debug.pnt.add( lpos, 0x00ffff, 1 ); | ||
|
||
// Set Solvers with IK Data | ||
rig.armL.solver.setTargetPos( apos ).setTargetPole( [0,0,-1] ); | ||
rig.legL.solver.setTargetPos( lpos ).setTargetPole( [0.5,0,0.5] ); | ||
rig.footL.solver.setTargetDir( [0,0,1], [0,1,0] ); | ||
rig.spine.solver.setEndDir( [0,1,0], [0,0,1] ).setEndDir( [0,1,0], [0.5,0,0.5] ); | ||
rig.head.solver.setTargetDir( [0,0.5,0.5], [0,1,0] ); | ||
|
||
rig.hip.solver | ||
.setMovePos( [0,-0.3,0], false ) | ||
.setTargetDir( [-0.5,0,0.5], [0,1,0] ); | ||
|
||
rig.resolveToPose( pose, debug ); // Run All Solvers, Store Results in a Pose | ||
boneView.updateFromPose( pose.updateWorld() ); // Update BoneView with new Pose | ||
arm.updateSkinFromPose( pose ); // Update Skinned Mesh with new Pose | ||
|
||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
App.render(); | ||
}); | ||
//#endregion | ||
|
||
</script> | ||
</body></html> |
Oops, something went wrong.