Skip to content

Commit

Permalink
Merge pull request #19942 from Mugen87/dev46
Browse files Browse the repository at this point in the history
Examples: Clean up.
  • Loading branch information
mrdoob committed Jul 28, 2020
2 parents 2f741c0 + 33d85af commit 743258c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
19 changes: 9 additions & 10 deletions examples/jsm/webxr/XRHandModelFactory.js
@@ -1,14 +1,14 @@
import {
Object3D
} from "../../../build/three.module.js";
} from '../../../build/three.module.js';

import {
XRHandPrimitiveModel
} from "./XRHandPrimitiveModel.js";
} from './XRHandPrimitiveModel.js';

import {
XRHandOculusMeshModel
} from "./XRHandOculusMeshModel.js";
} from './XRHandOculusMeshModel.js';

function XRHandModel( controller ) {

Expand Down Expand Up @@ -40,7 +40,7 @@ XRHandModel.prototype = Object.assign( Object.create( Object3D.prototype ), {
} );


var XRHandModelFactory = ( function () {
const XRHandModelFactory = ( function () {

function XRHandModelFactory() {

Expand All @@ -62,7 +62,6 @@ var XRHandModelFactory = ( function () {
createHandModel: function ( controller, profile, options ) {

const handModel = new XRHandModel( controller );
let scene = null;

controller.addEventListener( 'connected', ( event ) => {

Expand All @@ -74,15 +73,15 @@ var XRHandModelFactory = ( function () {
handModel.xrInputSource = xrInputSource;

// @todo Detect profile if not provided
if ( profile === undefined || profile === "spheres" ) {
if ( profile === undefined || profile === 'spheres' ) {

handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: "sphere" } );
handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: 'sphere' } );

} else if ( profile === "boxes" ) {
} else if ( profile === 'boxes' ) {

handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: "box" } );
handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: 'box' } );

} else if ( profile === "oculus" ) {
} else if ( profile === 'oculus' ) {

handModel.motionController = new XRHandOculusMeshModel( handModel, controller, this.path, xrInputSource.handedness, options );

Expand Down
16 changes: 8 additions & 8 deletions examples/jsm/webxr/XRHandOculusMeshModel.js
@@ -1,4 +1,4 @@
import { FBXLoader } from "../loaders/FBXLoader.js";
import { FBXLoader } from '../loaders/FBXLoader.js';

class XRHandOculusMeshModel {

Expand All @@ -8,17 +8,17 @@ class XRHandOculusMeshModel {
this.handModel = handModel;

this.bones = [];
var loader = new FBXLoader();
const low = options && options.model === "lowpoly" ? "_low" : "";
const loader = new FBXLoader();
const low = options && options.model === 'lowpoly' ? '_low' : '';

loader.setPath( path );
loader.load( `OculusHand_${handedness === "right" ? "R" : "L"}${low}.fbx`, object => {
loader.load( `OculusHand_${handedness === 'right' ? 'R' : 'L'}${low}.fbx`, object => {

this.handModel.add( object );
// Hack because of the scale of the skinnedmesh
object.scale.setScalar( 0.01 );

const mesh = object.getObjectByProperty( "type", "SkinnedMesh" );
const mesh = object.getObjectByProperty( 'type', 'SkinnedMesh' );
mesh.frustumCulled = false;
mesh.castShadow = true;
mesh.receiveShadow = true;
Expand Down Expand Up @@ -59,7 +59,7 @@ class XRHandOculusMeshModel {

if ( boneName ) {

const bone = object.getObjectByName( boneName.replace( "%", handedness === "right" ? "r" : "l" ) );
const bone = object.getObjectByName( boneName.replace( /%/g, handedness === 'right' ? 'r' : 'l' ) );
this.bones.push( bone );

} else {
Expand All @@ -78,7 +78,7 @@ class XRHandOculusMeshModel {

// XR Joints
const XRJoints = this.controller.joints;
for ( var i = 0; i < this.bones.length; i ++ ) {
for ( let i = 0; i < this.bones.length; i ++ ) {

const bone = this.bones[ i ];
const XRJoint = XRJoints[ i ];
Expand All @@ -93,7 +93,7 @@ class XRHandOculusMeshModel {

bone.position.copy( position.clone().multiplyScalar( 100 ) );
bone.quaternion.copy( XRJoint.quaternion );
// bone.scale.setScalar( XRJoint.jointRadius || defaultRadius );
// bone.scale.setScalar( XRJoint.jointRadius || defaultRadius );

}

Expand Down
28 changes: 15 additions & 13 deletions examples/jsm/webxr/XRHandPrimitiveModel.js
Expand Up @@ -4,7 +4,7 @@ import {
MeshStandardMaterial,
Mesh,
Group
} from "../../../build/three.module.js";
} from '../../../build/three.module.js';

class XRHandPrimitiveModel {

Expand All @@ -20,28 +20,29 @@ class XRHandPrimitiveModel {

if ( window.XRHand ) {

var geometry;
if ( ! options || ! options.primitive || options.primitive === "sphere" ) {
let geometry;

if ( ! options || ! options.primitive || options.primitive === 'sphere' ) {

geometry = new SphereBufferGeometry( 1, 10, 10 );

} else if ( options.primitive === "box" ) {
} else if ( options.primitive === 'box' ) {

geometry = new BoxBufferGeometry( 1, 1, 1 );

}

var jointMaterial = new MeshStandardMaterial( { color: 0xffffff, roughness: 1, metalness: 0 } );
var tipMaterial = new MeshStandardMaterial( { color: 0x999999, roughness: 1, metalness: 0 } );
const jointMaterial = new MeshStandardMaterial( { color: 0xffffff, roughness: 1, metalness: 0 } );
const tipMaterial = new MeshStandardMaterial( { color: 0x999999, roughness: 1, metalness: 0 } );

const tipIndexes = [
XRHand.THUMB_PHALANX_TIP,
XRHand.INDEX_PHALANX_TIP,
XRHand.MIDDLE_PHALANX_TIP,
XRHand.RING_PHALANX_TIP,
XRHand.LITTLE_PHALANX_TIP
window.XRHand.THUMB_PHALANX_TIP,
window.XRHand.INDEX_PHALANX_TIP,
window.XRHand.MIDDLE_PHALANX_TIP,
window.XRHand.RING_PHALANX_TIP,
window.XRHand.LITTLE_PHALANX_TIP
];
for ( let i = 0; i <= XRHand.LITTLE_PHALANX_TIP; i ++ ) {
for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {

var cube = new Mesh( geometry, tipIndexes.indexOf( i ) !== - 1 ? tipMaterial : jointMaterial );
cube.castShadow = true;
Expand All @@ -61,7 +62,8 @@ class XRHandPrimitiveModel {

// XR Joints
const XRJoints = this.controller.joints;
for ( var i = 0; i < objects.length; i ++ ) {

for ( let i = 0; i < objects.length; i ++ ) {

const jointMesh = objects[ i ];
const XRJoint = XRJoints[ i ];
Expand Down

0 comments on commit 743258c

Please sign in to comment.