提交 a5904f61 编写于 作者: L Lewy Blue

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

......@@ -12980,9 +12980,9 @@
//
function Int8BufferAttribute( array, itemSize ) {
function Int8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int8Array( array ), itemSize );
BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
}
......@@ -12990,9 +12990,9 @@
Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
function Uint8BufferAttribute( array, itemSize ) {
function Uint8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8Array( array ), itemSize );
BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
}
......@@ -13000,9 +13000,9 @@
Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
function Uint8ClampedBufferAttribute( array, itemSize ) {
function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
}
......@@ -13010,9 +13010,9 @@
Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
function Int16BufferAttribute( array, itemSize ) {
function Int16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int16Array( array ), itemSize );
BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
}
......@@ -13020,9 +13020,9 @@
Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
function Uint16BufferAttribute( array, itemSize ) {
function Uint16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint16Array( array ), itemSize );
BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
}
......@@ -13030,9 +13030,9 @@
Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
function Int32BufferAttribute( array, itemSize ) {
function Int32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int32Array( array ), itemSize );
BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
}
......@@ -13040,9 +13040,9 @@
Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
function Uint32BufferAttribute( array, itemSize ) {
function Uint32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint32Array( array ), itemSize );
BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
}
......@@ -13050,9 +13050,9 @@
Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
function Float32BufferAttribute( array, itemSize ) {
function Float32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float32Array( array ), itemSize );
BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
}
......@@ -13060,9 +13060,9 @@
Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
function Float64BufferAttribute( array, itemSize ) {
function Float64BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float64Array( array ), itemSize );
BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
}
......@@ -15930,6 +15930,18 @@
this.drawMode = source.drawMode;
if ( source.morphTargetInfluences !== undefined ) {
this.morphTargetInfluences = source.morphTargetInfluences.slice();
}
if ( source.morphTargetDictionary !== undefined ) {
this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
}
return this;
},
......@@ -17691,21 +17703,29 @@
prefixVertex = [
customDefines,
'\n'
customDefines
].filter( filterEmptyLine ).join( '\n' );
if ( prefixVertex.length > 0 ) {
prefixVertex += '\n';
}
prefixFragment = [
customExtensions,
customDefines,
'\n'
customDefines
].filter( filterEmptyLine ).join( '\n' );
if ( prefixFragment.length > 0 ) {
prefixFragment += '\n';
}
} else {
prefixVertex = [
......@@ -18413,7 +18433,7 @@
function makePowerOfTwo( image ) {
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = _Math.floorPowerOfTwo( image.width );
......
此差异已折叠。
......@@ -12974,9 +12974,9 @@ Object.assign( BufferAttribute.prototype, {
//
function Int8BufferAttribute( array, itemSize ) {
function Int8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int8Array( array ), itemSize );
BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
}
......@@ -12984,9 +12984,9 @@ Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
function Uint8BufferAttribute( array, itemSize ) {
function Uint8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8Array( array ), itemSize );
BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
}
......@@ -12994,9 +12994,9 @@ Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
function Uint8ClampedBufferAttribute( array, itemSize ) {
function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
}
......@@ -13004,9 +13004,9 @@ Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype
Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
function Int16BufferAttribute( array, itemSize ) {
function Int16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int16Array( array ), itemSize );
BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
}
......@@ -13014,9 +13014,9 @@ Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
function Uint16BufferAttribute( array, itemSize ) {
function Uint16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint16Array( array ), itemSize );
BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
}
......@@ -13024,9 +13024,9 @@ Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
function Int32BufferAttribute( array, itemSize ) {
function Int32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int32Array( array ), itemSize );
BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
}
......@@ -13034,9 +13034,9 @@ Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
function Uint32BufferAttribute( array, itemSize ) {
function Uint32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint32Array( array ), itemSize );
BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
}
......@@ -13044,9 +13044,9 @@ Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
function Float32BufferAttribute( array, itemSize ) {
function Float32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float32Array( array ), itemSize );
BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
}
......@@ -13054,9 +13054,9 @@ Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
function Float64BufferAttribute( array, itemSize ) {
function Float64BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float64Array( array ), itemSize );
BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
}
......@@ -15924,6 +15924,18 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
this.drawMode = source.drawMode;
if ( source.morphTargetInfluences !== undefined ) {
this.morphTargetInfluences = source.morphTargetInfluences.slice();
}
if ( source.morphTargetDictionary !== undefined ) {
this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
}
return this;
},
......@@ -17685,21 +17697,29 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
prefixVertex = [
customDefines,
'\n'
customDefines
].filter( filterEmptyLine ).join( '\n' );
if ( prefixVertex.length > 0 ) {
prefixVertex += '\n';
}
prefixFragment = [
customExtensions,
customDefines,
'\n'
customDefines
].filter( filterEmptyLine ).join( '\n' );
if ( prefixFragment.length > 0 ) {
prefixFragment += '\n';
}
} else {
prefixVertex = [
......@@ -18407,7 +18427,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function makePowerOfTwo( image ) {
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = _Math.floorPowerOfTwo( image.width );
......
......@@ -244,7 +244,7 @@
<h3>[method:Box3 setFromCenterAndSize]( [page:Vector3 center], [page:Vector3 size] )</h3>
<div>
[page:Vector3 center] - Desired center position of the box ([page:Vector3]). <br>
[page:Vector3 size] - Desired x and y dimensions of the box ([page:Vector3]).<br /><br />
[page:Vector3 size] - Desired x, y and z dimensions of the box ([page:Vector3]).<br /><br />
Centers this box on [page:Vector3 center] and sets this box's width and height to the values specified
in [page:Vector3 size].
......
......@@ -14,24 +14,24 @@
<div class="desc">A loader for loading an <em>.obj</em> resource.</div>
<h2>Example</h2>
<h2>Example</h2>
<code>
// instantiate a loader
var loader = new THREE.OBJLoader();
<code>
// instantiate a loader
var loader = new THREE.OBJLoader();
// load a resource
loader.load(
// resource URL
'models/monster.obj',
// Function when resource is loaded
function ( object ) {
scene.add( object );
}
);
</code>
// load a resource
loader.load(
// resource URL
'models/monster.obj',
// Function when resource is loaded
function ( object ) {
scene.add( object );
}
);
</code>
[example:webgl_loader_obj]
[example:webgl_loader_obj]
<h2>Constructor</h2>
......@@ -51,10 +51,10 @@
<h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
<div>
[page:String url] — required<br />
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D].<br />
[page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
[page:Function onError] — Will be called when load errors.<br />
[page:String url] — A string representing the path to the obj file. Required.<br />
[page:Function onLoad] — A function to be called when the load completes. The function receives loaded [page:Object3D] as an argument.<br />
[page:Function onProgress] — A function to be called while the loading is in progress. The function receives a XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
[page:Function onError] — A function to be called if the request fails. The function receives the error.<br />
</div>
<div>
Begin loading from url and call onLoad with the parsed response content.
......@@ -67,7 +67,7 @@
<div>
Returns an [page:Object3D]. It contains the parsed meshes as [page:Mesh] and lines as [page:LineSegments].<br />
All geometry is created as [page:BufferGeometry]. Default materials are created as [page:MeshPhongMaterial].<br />
If an <em>obj</em> object or group uses multiple materials while declaring faces geometry groups and an array of materials are used.
If an <em>obj</em> object or group uses multiple materials while declaring faces, geometry groups and an array of materials are used.
</div>
<h2>Source</h2>
......
......@@ -299,6 +299,7 @@ var files = {
"webvr": [
"webvr_cubes",
"webvr_daydream",
"webvr_gearvr",
"webvr_panorama",
"webvr_rollercoaster",
"webvr_sandbox",
......
......@@ -1807,13 +1807,10 @@ THREE.GLTFLoader = ( function () {
] ).then( function ( dependencies ) {
return _each( json.meshes, function ( meshDef ) {
return _each( json.meshes, function ( meshDef, meshIndex ) {
var group = new THREE.Group();
if ( meshDef.name !== undefined ) group.name = meshDef.name;
if ( meshDef.extras ) group.userData = meshDef.extras;
var primitives = meshDef.primitives || [];
return scope.loadGeometries( primitives ).then( function ( geometries ) {
......@@ -1896,7 +1893,8 @@ THREE.GLTFLoader = ( function () {
}
mesh.name = group.name + '_' + i;
mesh.name = meshDef.name || ( 'mesh_' + meshIndex );
mesh.name += i > 0 ? ( '_' + i ) : '';
if ( primitive.targets !== undefined ) {
......@@ -2133,198 +2131,137 @@ THREE.GLTFLoader = ( function () {
} );
return _each( json.nodes, function ( node ) {
var matrix = new THREE.Matrix4();
var _node = node.isBone === true ? new THREE.Bone() : new THREE.Object3D();
return scope._withDependencies( [
if ( node.name !== undefined ) {
_node.name = THREE.PropertyBinding.sanitizeNodeName( node.name );
}
'meshes',
'skins',
'cameras'
if ( node.extras ) _node.userData = node.extras;
] ).then( function ( dependencies ) {
if ( node.matrix !== undefined ) {
return _each( json.nodes, function ( nodeDef ) {
matrix.fromArray( node.matrix );
_node.applyMatrix( matrix );
if ( nodeDef.isBone === true ) {
} else {
return new THREE.Bone();
if ( node.translation !== undefined ) {
} else if ( nodeDef.mesh !== undefined ) {
_node.position.fromArray( node.translation );
return dependencies.meshes[ nodeDef.mesh ].clone();
}
} else if ( nodeDef.camera !== undefined ) {
if ( node.rotation !== undefined ) {
return dependencies.cameras[ nodeDef.camera ];
_node.quaternion.fromArray( node.rotation );
} else if ( nodeDef.extensions
&& nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS ]
&& nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS ].light !== undefined ) {
}
var lights = extensions[ EXTENSIONS.KHR_LIGHTS ].lights;
return lights[ nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS ].light ];
if ( node.scale !== undefined ) {
} else {
_node.scale.fromArray( node.scale );
return new THREE.Object3D();
}
}
return _node;
} ).then( function ( __nodes ) {
return scope._withDependencies( [
'meshes',
'skins',
'cameras'
] ).then( function ( dependencies ) {
return _each( __nodes, function ( _node, nodeId ) {
var node = json.nodes[ nodeId ];
var mesh = node.mesh;
if ( mesh !== undefined ) {
} ).then( function ( __nodes ) {
var group = dependencies.meshes[ mesh ];
return _each( __nodes, function ( node, nodeIndex ) {
if ( group !== undefined ) {
var nodeDef = json.nodes[ nodeIndex ];
// do not clone children as they will be replaced anyway
var clonedgroup = group.clone( false );
if ( nodeDef.name !== undefined ) {
for ( var i = 0; i < group.children.length; i ++ ) {
node.name = THREE.PropertyBinding.sanitizeNodeName( nodeDef.name );
var child = group.children[ i ];
var originalChild = child;
// clone Mesh to add to _node
}
var originalMaterial = child.material;
var originalGeometry = child.geometry;
var originalInfluences = child.morphTargetInfluences;
var originalUserData = child.userData;
var originalName = child.name;
if ( nodeDef.extras ) node.userData = nodeDef.extras;
var material = originalMaterial;
if ( nodeDef.matrix !== undefined ) {
switch ( child.type ) {
var matrix = new THREE.Matrix4();
matrix.fromArray( nodeDef.matrix );
node.applyMatrix( matrix );
case 'LineSegments':
child = new THREE.LineSegments( originalGeometry, material );
break;
} else {
case 'LineLoop':
child = new THREE.LineLoop( originalGeometry, material );
break;
if ( nodeDef.translation !== undefined ) {
case 'Line':
child = new THREE.Line( originalGeometry, material );
break;
node.position.fromArray( nodeDef.translation );
case 'Points':
child = new THREE.Points( originalGeometry, material );
break;
}
default:
child = new THREE.Mesh( originalGeometry, material );
child.drawMode = originalChild.drawMode;
if ( nodeDef.rotation !== undefined ) {
}
node.quaternion.fromArray( nodeDef.rotation );
child.castShadow = true;
child.morphTargetInfluences = originalInfluences;
child.userData = originalUserData;
child.name = originalName;
}
var skinEntry;
if ( nodeDef.scale !== undefined ) {
if ( node.skin !== undefined ) {
node.scale.fromArray( nodeDef.scale );
skinEntry = dependencies.skins[ node.skin ];
}
}
}
// Replace Mesh with SkinnedMesh in library
if ( skinEntry ) {
if ( nodeDef.skin !== undefined ) {
var geometry = originalGeometry;
material = originalMaterial;
material.skinning = true;
var skinnedMeshes = [];
child = new THREE.SkinnedMesh( geometry, material );
child.castShadow = true;
child.userData = originalUserData;
child.name = originalName;
for ( var i = 0; i < node.children.length; i ++ ) {
var bones = [];
var boneInverses = [];
var skinEntry = dependencies.skins[ nodeDef.skin ];
for ( var i = 0, l = skinEntry.joints.length; i < l; i ++ ) {
// Replace Mesh with SkinnedMesh.
var geometry = node.children[ i ].geometry;
var material = node.children[ i ].material;
material.skinning = true;
var jointId = skinEntry.joints[ i ];
var jointNode = __nodes[ jointId ];
var child = new THREE.SkinnedMesh( geometry, material );
child.morphTargetInfluences = node.children[ i ].morphTargetInfluences;
child.userData = node.children[ i ].userData;
child.name = node.children[ i ].name;
if ( jointNode ) {
var bones = [];
var boneInverses = [];
bones.push( jointNode );
for ( var j = 0, l = skinEntry.joints.length; j < l; j ++ ) {
var m = skinEntry.inverseBindMatrices.array;
var mat = new THREE.Matrix4().fromArray( m, i * 16 );
boneInverses.push( mat );
var jointId = skinEntry.joints[ j ];
var jointNode = __nodes[ jointId ];
} else {
if ( jointNode ) {
console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', jointId );
bones.push( jointNode );
}
var m = skinEntry.inverseBindMatrices.array;
var mat = new THREE.Matrix4().fromArray( m, j * 16 );
boneInverses.push( mat );
}
} else {
child.bind( new THREE.Skeleton( bones, boneInverses ), child.matrixWorld );
console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', jointId );
}
clonedgroup.add( child );
}
_node.add( clonedgroup );
child.bind( new THREE.Skeleton( bones, boneInverses ), child.matrixWorld );
} else {
console.warn( 'THREE.GLTFLoader: Could not find node "' + mesh + '".' );
skinnedMeshes.push( child );
}
}
if ( node.camera !== undefined ) {
var camera = dependencies.cameras[ node.camera ];
_node.add( camera );
}
if ( node.extensions
&& node.extensions[ EXTENSIONS.KHR_LIGHTS ]
&& node.extensions[ EXTENSIONS.KHR_LIGHTS ].light !== undefined ) {
var lights = extensions[ EXTENSIONS.KHR_LIGHTS ].lights;
_node.add( lights[ node.extensions[ EXTENSIONS.KHR_LIGHTS ].light ] );
node.remove.apply( node, node.children );
node.add.apply( node, skinnedMeshes );
}
return _node;
return node;
} );
......
/**
* @author servinlp
*/
THREE.GearVRController = function () {
THREE.Object3D.call( this );
var scope = this;
var gamepad;
var axes = [ 0, 0 ];
var touchpadIsPressed = false;
var triggerIsPressed = false;
var angularVelocity = new THREE.Vector3();
this.matrixAutoUpdate = true;
function findGamepad() {
var gamepads = navigator.getGamepads && navigator.getGamepads();
for ( var i = 0; i < 4; i ++ ) {
var gamepad = gamepads[ i ];
if ( gamepad && ( gamepad.id === 'Gear VR Controller' ) ) {
return gamepad;
}
}
}
this.setHand = function ( hand = 'right' ) {
var handPos;
if ( hand === 'right' ) {
handPos = 0.3;
} else {
handPos = - 0.3;
}
this.translateX( handPos );
this.translateY( - 0.35 );
this.translateZ( - 0.4 );
};
this.getGamepad = function () {
return gamepad;
};
this.getTouchPadState = function () {
return touchpadIsPressed;
};
this.update = function () {
gamepad = findGamepad();
if ( gamepad !== undefined && gamepad.pose !== undefined ) {
var pose = gamepad.pose;
if ( pose === null ) return; // no user action yet
// orientation
if ( pose.orientation !== null ) scope.quaternion.fromArray( pose.orientation );
scope.updateMatrix();
scope.visible = true;
// angular velocity
if ( pose.angularVelocity !== null && ! angularVelocity.equals( pose.angularVelocity ) ) {
angularVelocity.fromArray( pose.angularVelocity );
scope.dispatchEvent( { type: 'angularvelocitychanged', angularVelocity: angularVelocity } );
}
// axes (touchpad)
if ( axes[ 0 ] !== gamepad.axes[ 0 ] || axes[ 1 ] !== gamepad.axes[ 1 ] ) {
axes[ 0 ] = gamepad.axes[ 0 ];
axes[ 1 ] = gamepad.axes[ 1 ];
scope.dispatchEvent( { type: 'axischanged', axes: axes } );
}
// button (touchpad)
if ( touchpadIsPressed !== gamepad.buttons[ 0 ].pressed ) {
touchpadIsPressed = gamepad.buttons[ 0 ].pressed;
scope.dispatchEvent( { type: touchpadIsPressed ? 'touchpaddown' : 'touchpadup', axes: axes } );
}
// trigger
if ( triggerIsPressed !== gamepad.buttons[ 1 ].pressed ) {
triggerIsPressed = gamepad.buttons[ 1 ].pressed;
scope.dispatchEvent( { type: triggerIsPressed ? 'triggerdown' : 'triggerup' } );
}
// app button not available, reserved for use by the browser
} else {
scope.visible = false;
}
};
};
THREE.GearVRController.prototype = Object.create( THREE.Object3D.prototype );
THREE.GearVRController.prototype.constructor = THREE.GearVRController;
The MIT License
Copyright © 2015-2017 A-Frame authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# Gear VR Controller MTL
newmtl Base
Kd 0.0911392 0.0911392 0.0911392
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
newmtl Touchpad
Kd 0.172688 0.172688 0.172688
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
newmtl Trigger
Kd 0.172688 0.172688 0.172688
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
......@@ -274,6 +274,12 @@
}
object.traverse( function ( node ) {
if ( node.isMesh ) node.castShadow = true;
} );
cameraIndex = 0;
cameras = [];
cameraNames = [];
......@@ -332,7 +338,11 @@
scene.add( object );
onWindowResize();
});
}, undefined, function ( error ) {
console.error( error );
} );
orbitControls = new THREE.OrbitControls(defaultCamera, renderer.domElement);
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webvr - gear vr</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style>
body {
font-family: Monospace;
background-color: #101010;
color: #fff;
margin: 0px;
overflow: hidden;
}
a {
color: #f00;
}
</style>
</head>
<body>
<script src="../build/three.js"></script>
<script src="js/loaders/MTLLoader.js"></script>
<script src="js/loaders/OBJLoader.js"></script>
<script src="js/vr/GearVRController.js"></script>
<script src="js/vr/WebVR.js"></script>
<script>
WEBVR.checkAvailability().catch( function ( message ) {
document.body.appendChild( WEBVR.getMessageContainer( message ) );
} );
var clock = new THREE.Clock();
var container;
var camera, camBox, scene, renderer;
var controller;
var room;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - gear vr';
container.appendChild( info );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x505050 );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
camBox = new THREE.Object3D();
camBox.position.y = 1.8;
camBox.add( camera );
scene.add( camBox );
room = new THREE.Mesh(
new THREE.BoxGeometry( 6, 6, 6, 8, 8, 8 ),
new THREE.MeshBasicMaterial( { color: 0x404040, wireframe: true } )
);
room.position.y = 3;
scene.add( room );
scene.add( new THREE.HemisphereLight( 0x606060, 0x404040 ) );
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 1, 1, 1 ).normalize();
scene.add( light );
var geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
for ( var i = 0; i < 200; i ++ ) {
var object = new THREE.Mesh(
geometry,
new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } )
);
object.position.x = Math.random() * 4 - 2;
object.position.y = Math.random() * 4 - 2;
object.position.z = Math.random() * 4 - 2;
object.rotation.x = Math.random() * 2 * Math.PI;
object.rotation.y = Math.random() * 2 * Math.PI;
object.rotation.z = Math.random() * 2 * Math.PI;
object.scale.x = Math.random() + 0.5;
object.scale.y = Math.random() + 0.5;
object.scale.z = Math.random() + 0.5;
object.userData.velocity = new THREE.Vector3();
object.userData.velocity.x = Math.random() * 0.01 - 0.005;
object.userData.velocity.y = Math.random() * 0.01 - 0.005;
object.userData.velocity.z = Math.random() * 0.01 - 0.005;
room.add( object );
}
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
renderer.vr.enabled = true;
controller = new THREE.GearVRController();
camBox.position.y = 1.8;
controller.setHand( 'right' );
camBox.add( controller );
var skyBox = {
front: 'textures/cube/Bridge2/posz.jpg',
back: 'textures/cube/Bridge2/negz.jpg',
left: 'textures/cube/Bridge2/posx.jpg',
right: 'textures/cube/Bridge2/negx.jpg',
up: 'textures/cube/Bridge2/posy.jpg',
down: 'textures/cube/Bridge2/negy.jpg'
};
if ( 'SamsungChangeSky' in window ) {
window.SamsungChangeSky( skyBox );
}
var MTL = new THREE.MTLLoader();
MTL.setPath( 'models/obj/gear_vr_controller/' );
MTL.load( 'gear_vr_controller.mtl', function ( materials ) {
materials.preload();
var OBJ = new THREE.OBJLoader();
OBJ.setMaterials( materials );
OBJ.setPath( 'models/obj/gear_vr_controller/' );
OBJ.load( 'gear_vr_controller.obj', function ( obj ) {
obj.translateZ( - 0.03 );
controller.add( obj );
} );
} );
WEBVR.getVRDisplay( function ( display ) {
renderer.vr.setDevice( display );
document.body.appendChild( WEBVR.getButton( display, renderer.domElement ) );
} );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
renderer.animate( render );
}
function render() {
var delta = clock.getDelta() * 60;
controller.update();
for ( var i = 0; i < room.children.length; i ++ ) {
var cube = room.children[ i ];
if ( cube.geometry instanceof THREE.BoxGeometry === false ) continue;
if ( cube.position.x < - 3 || cube.position.x > 3 ) {
cube.position.x = THREE.Math.clamp( cube.position.x, - 3, 3 );
cube.userData.velocity.x = - cube.userData.velocity.x;
}
if ( cube.position.y < - 3 || cube.position.y > 3 ) {
cube.position.y = THREE.Math.clamp( cube.position.y, - 3, 3 );
cube.userData.velocity.y = - cube.userData.velocity.y;
}
if ( cube.position.z < - 3 || cube.position.z > 3 ) {
cube.position.z = THREE.Math.clamp( cube.position.z, - 3, 3 );
cube.userData.velocity.z = - cube.userData.velocity.z;
}
cube.rotation.x += 0.01 * delta;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>
......@@ -342,9 +342,9 @@ Object.assign( BufferAttribute.prototype, {
//
function Int8BufferAttribute( array, itemSize ) {
function Int8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int8Array( array ), itemSize );
BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
}
......@@ -352,9 +352,9 @@ Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
function Uint8BufferAttribute( array, itemSize ) {
function Uint8BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8Array( array ), itemSize );
BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
}
......@@ -362,9 +362,9 @@ Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
function Uint8ClampedBufferAttribute( array, itemSize ) {
function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
}
......@@ -372,9 +372,9 @@ Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype
Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
function Int16BufferAttribute( array, itemSize ) {
function Int16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int16Array( array ), itemSize );
BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
}
......@@ -382,9 +382,9 @@ Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
function Uint16BufferAttribute( array, itemSize ) {
function Uint16BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint16Array( array ), itemSize );
BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
}
......@@ -392,9 +392,9 @@ Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
function Int32BufferAttribute( array, itemSize ) {
function Int32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Int32Array( array ), itemSize );
BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
}
......@@ -402,9 +402,9 @@ Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
function Uint32BufferAttribute( array, itemSize ) {
function Uint32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Uint32Array( array ), itemSize );
BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
}
......@@ -412,9 +412,9 @@ Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
function Float32BufferAttribute( array, itemSize ) {
function Float32BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float32Array( array ), itemSize );
BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
}
......@@ -422,9 +422,9 @@ Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
function Float64BufferAttribute( array, itemSize ) {
function Float64BufferAttribute( array, itemSize, normalized ) {
BufferAttribute.call( this, new Float64Array( array ), itemSize );
BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
}
......
......@@ -50,6 +50,18 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
this.drawMode = source.drawMode;
if ( source.morphTargetInfluences !== undefined ) {
this.morphTargetInfluences = source.morphTargetInfluences.slice();
}
if ( source.morphTargetDictionary !== undefined ) {
this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
}
return this;
},
......
......@@ -3,4 +3,5 @@ var define;
var module;
var exports;
var performance;
var ImageBitmap;
var WebGL2RenderingContext;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册