Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/TSL.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ It's possible use `xyzw`, `rgba` or `stpq`.
| Name | Description |
| -- | -- |
| `.add( node \| value, ... )` | Return the addition of two or more value. |
| `.sub( node \| value )` | Return the subraction of two or more value. |
| `.sub( node \| value )` | Return the subtraction of two or more value. |
| `.mul( node \| value )` | Return the multiplication of two or more value. |
| `.div( node \| value )` | Return the division of two or more value. |
| `.mod( node \| value )` | Computes the remainder of dividing the first node by the second. |
Expand Down
2 changes: 1 addition & 1 deletion editor/examples/arkanoid.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"31517222-A9A7-4EAF-B5F6-60751C0BABA3": [
{
"name": "Game Logic",
"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = - 0.5;\ndirection.normalize();\n\nvar speed = new THREE.Vector3();\n\n//\n\nvar group = new THREE.Group();\nthis.add( group );\n\nvar paddle = this.getObjectByName( 'Paddle' );\npaddle.material.visible = false;\ngroup.add( paddle );\n\nvar brick = this.getObjectByName( 'Brick' );\n\nfor ( var j = 0; j < 8; j ++ ) {\n\n\tvar material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );\n\n\tfor ( var i = 0; i < 12; i ++ ) {\n\t\t\n\t\tvar object = brick.clone();\n\t\tobject.position.x = i * 2.2 - 12;\n\t\tobject.position.z = j * 1.4 - 12;\n\t\tgroup.add( object );\n\n\t\tvar cylinder = object.getObjectByName( 'Cylinder' );\n\t\tcylinder.material = material;\n\n\t}\n\t\n}\n\nbrick.visible = false;\nbrick.material.visible = false;\n\n//\n\nvar raycaster = new THREE.Raycaster();\n\nfunction update( event ) {\n\t\n\tif ( ball.position.x < - 15 || ball.position.x > 15 ) direction.x = - direction.x;\n\tif ( ball.position.z < - 20 || ball.position.z > 20 ) direction.z = - direction.z;\n\n\tball.position.x = Math.max( - 15, Math.min( 15, ball.position.x ) );\n\tball.position.z = Math.max( - 20, Math.min( 20, ball.position.z ) );\n\t\t\n\traycaster.set( ball.position, direction );\n\t\n\tvar intersections = raycaster.intersectObjects( group.children );\n\t\n\tif ( intersections.length > 0 ) {\n\t\n\t\tvar intersection = intersections[ 0 ];\n\t\t\n\t\tif ( intersection.distance < 0.5 ) {\n\t\t\t\n\t\t\tif ( intersection.object !== paddle ) {\n\n\t\t\t\tgroup.remove( intersection.object );\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tdirection.reflect( intersection.face.normal );\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n\tball.position.add( speed.copy( direction ).multiplyScalar( event.delta / 40 ) );\n\t\n}"
"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = - 0.5;\ndirection.normalize();\n\n//\n\nvar group = new THREE.Group();\nthis.add( group );\n\nvar paddle = this.getObjectByName( 'Paddle' );\npaddle.material.visible = false;\ngroup.add( paddle );\n\nvar brick = this.getObjectByName( 'Brick' );\n\nfor ( var j = 0; j < 8; j ++ ) {\n\n\tvar material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );\n\n\tfor ( var i = 0; i < 12; i ++ ) {\n\t\t\n\t\tvar object = brick.clone();\n\t\tobject.position.x = i * 2.2 - 12;\n\t\tobject.position.z = j * 1.4 - 12;\n\t\tgroup.add( object );\n\n\t\tvar cylinder = object.getObjectByName( 'Cylinder' );\n\t\tcylinder.material = material;\n\n\t}\n\t\n}\n\nbrick.visible = false;\nbrick.material.visible = false;\n\n//\n\nvar radius = 0.5;\n\nvar box = new THREE.Box3();\nvar closest = new THREE.Vector3();\nvar normal = new THREE.Vector3();\n\nfunction collide( object ) {\n\n\tbox.setFromObject( object );\n\tbox.clampPoint( ball.position, closest );\n\n\tif ( closest.distanceToSquared( ball.position ) >= radius * radius ) return false;\n\n\tif ( closest.equals( ball.position ) ) {\n\n\t\tnormal.copy( direction ).negate();\n\n\t} else {\n\n\t\tnormal.subVectors( ball.position, closest ).setY( 0 ).normalize();\n\n\t}\n\n\tdirection.reflect( normal );\n\n\tbox.clampPoint( ball.position, closest );\n\tball.position.copy( closest ).addScaledVector( normal, radius );\n\n\treturn true;\n\n}\n\nfunction update( event ) {\n\n\tvar distance = event.delta / 40;\n\tvar steps = Math.max( 1, Math.ceil( distance / radius ) );\n\tvar delta = distance / steps;\n\n\tfor ( var s = 0; s < steps; s ++ ) {\n\n\t\tball.position.addScaledVector( direction, delta );\n\n\t\tif ( ball.position.x < - 15 || ball.position.x > 15 ) {\n\n\t\t\tdirection.x = - direction.x;\n\t\t\tball.position.x = Math.max( - 15, Math.min( 15, ball.position.x ) );\n\n\t\t}\n\n\t\tif ( ball.position.z < - 20 || ball.position.z > 20 ) {\n\n\t\t\tdirection.z = - direction.z;\n\t\t\tball.position.z = Math.max( - 20, Math.min( 20, ball.position.z ) );\n\n\t\t}\n\n\t\tfor ( var i = group.children.length - 1; i >= 0; i -- ) {\n\n\t\t\tvar object = group.children[ i ];\n\n\t\t\tif ( collide( object ) ) {\n\n\t\t\t\tif ( object !== paddle ) group.remove( object );\n\t\t\t\tbreak;\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n}"
}]
}
}
66 changes: 38 additions & 28 deletions examples/jsm/loaders/DRACOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
LinearSRGBColorSpace,
SRGBColorSpace,
InterleavedBuffer,
InterleavedBufferAttribute
InterleavedBufferAttribute,
LoaderUtils
} from 'three';

const _taskCache = new WeakMap();
Expand All @@ -17,6 +18,11 @@ const WASM_BIN_URL = new URL( '../libs/draco/draco_decoder.wasm', import.meta.ur
const WASM_JS_URL = new URL( '../libs/draco/draco_wasm_wrapper.js', import.meta.url ).toString();
const JS_URL = new URL( '../libs/draco/draco_decoder.js', import.meta.url ).toString();

const DRACO_GLTF_CONFIG = {
js: new URL( '../libs/draco/gltf/draco_wasm_wrapper.js', import.meta.url ).toString(),
wasm: new URL( '../libs/draco/gltf/draco_decoder.wasm', import.meta.url ).toString(),
};

/**
* A loader for the Draco format.
*
Expand All @@ -38,12 +44,10 @@ const JS_URL = new URL( '../libs/draco/draco_decoder.js', import.meta.url ).toSt
*
* ```js
* const loader = new DRACOLoader();
* loader.setDecoderPath( '/examples/jsm/libs/draco/' );
*
* const geometry = await dracoLoader.loadAsync( 'models/draco/bunny.drc' );
* const geometry = await loader.loadAsync( 'models/draco/bunny.drc' );
* geometry.computeVertexNormals(); // optional
*
* dracoLoader.dispose();
* loader.dispose();
* ```
*
* @augments Loader
Expand All @@ -60,7 +64,11 @@ class DRACOLoader extends Loader {

super( manager );

this.decoderPath = '';
this.decoderPaths = {
js: WASM_JS_URL,
wasm: WASM_BIN_URL,
dep_js: JS_URL,
};
this.decoderConfig = {};
this.decoderBinary = null;
this.decoderPending = null;
Expand Down Expand Up @@ -88,12 +96,25 @@ class DRACOLoader extends Loader {
/**
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
*
* @param {string} path - The decoder path.
* @param {string|{js:string, wasm:string}} path - The decoder path, or a config object with explicit URLs for each decoder file.
* @return {DRACOLoader} A reference to this loader.
*/
setDecoderPath( path ) {

this.decoderPath = path;
const { decoderPaths } = this;
if ( typeof path === 'object' ) {

decoderPaths.js = path.js;
decoderPaths.wasm = path.wasm;
decoderPaths.dep_js = null;

} else {

decoderPaths.js = LoaderUtils.resolveURL( 'draco_wasm_wrapper.js', path );
decoderPaths.wasm = LoaderUtils.resolveURL( 'draco_decoder.wasm', path );
decoderPaths.dep_js = LoaderUtils.resolveURL( 'draco_decoder.js', path );

}

return this;

Expand Down Expand Up @@ -337,7 +358,6 @@ class DRACOLoader extends Loader {
_loadLibrary( url, responseType ) {

const loader = new FileLoader( this.manager );
loader.setPath( this.decoderPath );
loader.setResponseType( responseType );
loader.setWithCredentials( this.withCredentials );

Expand All @@ -364,31 +384,21 @@ class DRACOLoader extends Loader {
const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
const librariesPending = [];

if ( this.decoderPath === '' ) {
const { decoderPaths } = this;
if ( useJS ) {

if ( useJS ) {
if ( decoderPaths.dep_js === null ) {

librariesPending.push( this._loadLibrary( JS_URL, 'text' ) );

} else {

librariesPending.push( this._loadLibrary( WASM_JS_URL, 'text' ) );
librariesPending.push( this._loadLibrary( WASM_BIN_URL, 'arraybuffer' ) );
throw new Error( 'THREE.DRACOLoader: WebAssembly is required when using a custom decoder paths.' );

}

} else {

if ( useJS ) {

librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) );
librariesPending.push( this._loadLibrary( decoderPaths.dep_js, 'text' ) );

} else {

librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) );
librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) );
} else {

}
librariesPending.push( this._loadLibrary( decoderPaths.js, 'text' ) );
librariesPending.push( this._loadLibrary( decoderPaths.wasm, 'arraybuffer' ) );

}

Expand Down Expand Up @@ -759,4 +769,4 @@ function DRACOWorker() {

}

export { DRACOLoader };
export { DRACOLoader, DRACO_GLTF_CONFIG };
7 changes: 4 additions & 3 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,17 @@ class KTX2Loader extends Loader {

if ( typeof navigator !== 'undefined' &&
typeof navigator.platform !== 'undefined' && typeof navigator.userAgent !== 'undefined' &&
navigator.platform.indexOf( 'Linux' ) >= 0 && navigator.userAgent.indexOf( 'Firefox' ) >= 0 &&
navigator.platform.indexOf( 'Linux' ) >= 0 && navigator.userAgent.indexOf( 'Android' ) < 0 &&
this.workerConfig.astcSupported && this.workerConfig.etc2Supported &&
this.workerConfig.bptcSupported && this.workerConfig.dxtSupported ) {

// On Linux, Mesa drivers for AMD and Intel GPUs expose ETC2 and ASTC even though the hardware doesn't support these.
// On Linux, Mesa drivers for AMD and Intel GPUs expose ETC1,ETC2 and ASTC even though the hardware doesn't support these.
// Using these extensions will result in expensive software decompression on the main thread inside the driver, causing performance issues.
// When using ANGLE (e.g. via Chrome), these extensions are not exposed except for some specific Intel GPU models - however, Firefox doesn't perform this filtering.
// In general, browsers should not expose extensions for emulated formats, but Chrome and Firefox currently do so on Linux.
// Since a granular filter is a little too fragile and we can transcode into other GPU formats, disable formats that are likely to be emulated.

this.workerConfig.astcSupported = false;
this.workerConfig.etc1Supported = false;
this.workerConfig.etc2Supported = false;

}
Expand Down
4 changes: 2 additions & 2 deletions examples/webgl_animation_keyframes.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import { Sky } from 'three/addons/objects/Sky.js';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { DRACOLoader, DRACO_GLTF_CONFIG } from 'three/addons/loaders/DRACOLoader.js';

let mixer;

Expand Down Expand Up @@ -95,7 +95,7 @@
controls.update();

const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( 'jsm/libs/draco/gltf/' );
dracoLoader.setDecoderPath( DRACO_GLTF_CONFIG );

const loader = new GLTFLoader();
loader.setDRACOLoader( dracoLoader );
Expand Down
Loading
Loading