Skip to content

Commit

Permalink
Merge pull request #1448 from pixiv/extended-collider-2
Browse files Browse the repository at this point in the history
Feature: support `VRMC_springBone_extended_collider`
  • Loading branch information
0b5vr authored Aug 5, 2024
2 parents 2aa032e + 2ae829b commit 8248821
Show file tree
Hide file tree
Showing 30 changed files with 1,671 additions and 109 deletions.
30 changes: 9 additions & 21 deletions .github/workflows/inspect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defaults:
shell: bash

jobs:
fetch:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,26 +27,6 @@ jobs:
${{ runner.os }}-yarn-
- name: Fetch Deps
run: yarn install --frozen-lockfile

build:
runs-on: ubuntu-latest
needs: fetch
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: './.node-version'
- name: Cache Deps
uses: actions/cache@v4
with:
path: |
node_modules
packages/*/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Build
run: yarn build
- name: Upload Builds
Expand Down Expand Up @@ -76,6 +56,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Fetch Deps
run: yarn install --frozen-lockfile
- name: Download Builds
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -103,6 +85,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Fetch Deps
run: yarn install --frozen-lockfile
- name: Download Builds
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -130,6 +114,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Fetch Deps
run: yarn install --frozen-lockfile
- name: Download Builds
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -166,6 +152,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Fetch Deps
run: yarn install --frozen-lockfile
- name: Download Builds
uses: actions/download-artifact@v3
with:
Expand Down
10 changes: 9 additions & 1 deletion packages/three-vrm-springbone/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ <h1>examples of <a href="https://github.com/pixiv/three-vrm/">@pixiv/three-vrm-s
</p>
<p>
<a href="collider.html">collider.html</a><br />
An example with a node collider
An example with a collider
</p>
<p>
<a href="inside-collider.html">inside-collider.html</a><br />
An example with an inside collider
</p>
<p>
<a href="plane-collider.html">plane-collider.html</a><br />
An example with a plane collider
</p>
<p>
<a href="loader-plugin.html">loader-plugin.html</a><br />
Expand Down
166 changes: 166 additions & 0 deletions packages/three-vrm-springbone/examples/inside-collider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<title>three-vrm-springbone example - inside-collider</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<style>
body {
margin: 0;
}
canvas {
display: block;
}
</style>
</head>

<body>
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/",
"@pixiv/three-vrm-springbone": "../lib/three-vrm-springbone.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import {
VRMSpringBoneColliderShapeCapsule,
VRMSpringBoneColliderShapePlane,
VRMSpringBoneColliderShapeSphere,
VRMSpringBoneCollider,
VRMSpringBoneColliderHelper,
VRMSpringBoneManager,
VRMSpringBoneJoint,
VRMSpringBoneJointHelper
} from '@pixiv/three-vrm-springbone';

// renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );

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

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

// scene
const scene = new THREE.Scene();

// light
const light = new THREE.DirectionalLight( 0xffffff, Math.PI );
light.position.set( 1.0, 2.0, 3.0 ).normalize();
scene.add( light );

// objects
const geometry = new THREE.BoxGeometry( 0.4, 0.4, 0.4 );
const material = new THREE.MeshStandardMaterial( { color: 0xbbbbbb } );

const cubeA = new THREE.Mesh( geometry, material );
cubeA.name = 'cubeA';
cubeA.position.set( 0.0, 0.5, 0.0 );
scene.add( cubeA );

const cubeB = new THREE.Mesh( geometry, material );
cubeB.name = 'cubeB';
cubeB.position.set( 0.0, - 0.5, 0.0 );
cubeA.add( cubeB );

const cubeC = new THREE.Mesh( geometry, material );
cubeC.name = 'cubeC';
cubeC.position.set( 0.0, - 0.5, 0.0 );
cubeB.add( cubeC );

// helpers
const gridHelper = new THREE.GridHelper( 10, 10 );
scene.add( gridHelper );

const axesHelper = new THREE.AxesHelper( 5 );
scene.add( axesHelper );

// collider
const colliders = [];

const colliderShape = new VRMSpringBoneColliderShapeSphere( {

offset: new THREE.Vector3( 0.0, 0.0, 0.0 ),
radius: 0.5,
inside: true,

} );

const collider = new VRMSpringBoneCollider( colliderShape );
collider.position.y = - 0.5;
scene.add( collider );

colliders.push( collider );

// collider helper
const colliderHelper = new VRMSpringBoneColliderHelper( collider );
scene.add( colliderHelper );

// spring bone
const springBoneManager = new VRMSpringBoneManager();

const springBone = new VRMSpringBoneJoint( cubeB, cubeC, { hitRadius: 0.2 } );
springBone.colliderGroups = [ { colliders } ];
springBoneManager.addSpringBone( springBone );

// helpers
springBoneManager.springBones.forEach( ( bone ) => {

const helper = new VRMSpringBoneJointHelper( bone );
scene.add( helper );

} );

// init spring bones
springBoneManager.setInitState();

// animate
const clock = new THREE.Clock();
let shouldReset = true;

function animate() {

requestAnimationFrame( animate );

const deltaTime = clock.getDelta();

cubeA.position.x = Math.sin( Math.PI * clock.elapsedTime );

collider.position.x = Math.sin( Math.PI * clock.elapsedTime );

if ( shouldReset ) {

shouldReset = false;
springBoneManager.reset();

}

springBoneManager.update( deltaTime );

renderer.render( scene, camera );

}

animate();
</script>
</body>
</html>
53 changes: 43 additions & 10 deletions packages/three-vrm-springbone/examples/loader-plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { VRMSpringBoneLoaderPlugin } from "@pixiv/three-vrm-springbone";
import GUI from 'three/addons/libs/lil-gui.module.min.js';

// renderer
const renderer = new THREE.WebGLRenderer();
Expand All @@ -43,7 +44,7 @@

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

// camera controls
const controls = new OrbitControls( camera, renderer.domElement );
Expand All @@ -54,21 +55,23 @@
// scene
const scene = new THREE.Scene();

const helperRoot = new THREE.Group();
scene.add( helperRoot );

// light
const light = new THREE.DirectionalLight( 0xffffff, Math.PI );
light.position.set( 1.0, 1.0, 1.0 ).normalize();
scene.add( light );

// gltf and vrm
let currentGltf = null;
let currentSpringBoneManager = null;

const loader = new GLTFLoader();

const loaderPluginOptions = {

jointHelperRoot: scene,
colliderHelperRoot: scene,
jointHelperRoot: helperRoot,
colliderHelperRoot: helperRoot,

};

Expand All @@ -80,6 +83,13 @@

function load( url ) {

if ( currentGltf != null ) {

scene.remove( currentGltf.scene );
helperRoot.clear();

}

loader.crossOrigin = 'anonymous';
loader.load(

Expand All @@ -92,7 +102,7 @@

currentGltf = gltf;

const springBoneManager = gltf.vrmSpringBoneManager;
clock.start();

},

Expand All @@ -104,7 +114,7 @@

}

load( './models/cubes.gltf' );
load( './models/sphere-collider.gltf' );

// helpers
const gridHelper = new THREE.GridHelper( 10, 10 );
Expand Down Expand Up @@ -146,6 +156,29 @@

animate();

// gui
const gui = new GUI();

const params = {

model: 'sphere-collider.gltf',

};

const availableModels = [

'sphere-collider.gltf',
'inside-collider.gltf',
'plane-collider.gltf',

];

gui.add( params, 'model', availableModels ).onChange( ( value ) => {

load( `./models/${ value }` );

} );

// dnd handler
window.addEventListener( 'dragover', function ( event ) {

Expand All @@ -160,16 +193,16 @@
// read given file then convert it to blob url
const files = event.dataTransfer.files;
if ( ! files ) {

return;

}

const file = files[ 0 ];
if ( ! file ) {

return;

}

const blob = new Blob( [ file ], { type: "application/octet-stream" } );
Expand Down
Binary file not shown.
Loading

0 comments on commit 8248821

Please sign in to comment.