Browse Source

Examples: Removed webgl_loader_prwm.

Mr.doob 2 years ago
parent
commit
45ef934fb9

+ 0 - 118
docs/examples/en/loaders/PRWMLoader.html

@@ -1,118 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<meta charset="utf-8" />
-		<base href="../../../" />
-		<script src="page.js"></script>
-		<link type="text/css" rel="stylesheet" href="page.css" />
-	</head>
-	<body>
-		[page:Loader] &rarr;
-
-		<h1>[name]</h1>
-
-		<p class="desc">A loader for loading a `.prwm` resource.<br />
-		Packed Raw WebGL Model is an open-source binary file format for nD geometries specifically designed for
-		JavaScript and WebGL with a strong focus on fast parsing (from 1ms to 0.1ms in Chrome 59
-		on a MBP Late 2013). The parsing of PRWM file is especially fast when the endianness of the file is
-		the same as the endianness of the client platform. More information
-		on this [link:https://github.com/kchapelier/PRWM here].
-		</p>
-
-		<h2>Import</h2>
-
-		<p>
-			[name] is an add-on, and must be imported explicitly.
-			See [link:#manual/introduction/Installation Installation / Addons].
-		</p>
-
-		<code>
-			import { PRWMLoader } from 'three/addons/loaders/PRWMLoader.js';
-		</code>
-
-		<h2>Code Example</h2>
-
-		<code>
-		// instantiate a loader
-		const loader = new PRWMLoader();
-
-		// load a resource
-		loader.load(
-			// resource URL
-			'models/nefertiti.le.prwm',
-			// called when resource is loaded
-			function ( bufferGeometry ) {
-
-				const object = new THREE.Mesh( bufferGeometry, new THREE.MeshNormalMaterial() );
-				scene.add( object );
-
-			},
-			// called when loading is in progresses
-			function ( xhr ) {
-
-				console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
-
-			},
-			// called when loading has errors
-			function ( error ) {
-
-				console.log( 'An error happened' );
-
-			}
-		);
-		</code>
-
-		<h2>Examples</h2>
-		<p>
-			[example:webgl_loader_prwm]
-		</p>
-
-		<h2>Constructor</h2>
-
-		<h3>[name]( [param:LoadingManager manager] )</h3>
-		<p>
-		[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
-		</p>
-		<p>
-		Creates a new [name].
-		</p>
-
-		<h2>Properties</h2>
-		<p>See the base [page:Loader] class for common properties.</p>
-
-		<h2>Methods</h2>
-		<p>See the base [page:Loader] class for common methods.</p>
-
-		<h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
-		<p>
-		[page:String url] — A string containing the path/URL of the `.prwm` file. Any `*` character in the URL will be automatically replaced by `le` or `be` depending on the platform endianness.<br />
-		[page:Function onLoad] — (optional) A function to be called after the loading is successfully completed. The function receives the loaded [page:BufferGeometry] as an argument.<br />
-		[page:Function onProgress] — (optional) 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. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
-		[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
-		</p>
-		<p>
-		Begin loading from url and call onLoad with the parsed response content.
-		</p>
-
-		<h3>[method:BufferGeometry parse]( [param:ArrayBuffer arrayBuffer] )</h3>
-		<p>
-		[page:ArrayBuffer arrayBuffer] — ArrayBuffer containing the `prwm` data.
-		</p>
-		<p>
-		Parse a `prwm` file passed as an ArrayBuffer and directly return an instance of [page:BufferGeometry].
-		</p>
-
-		<h3>PRWMLoader.isBigEndianPlatform( )</h3>
-
-		<p>
-		Return true if the endianness of the platform is Big Endian, false otherwise.
-		</p>
-
-		<h2>Source</h2>
-
-		<p>
-			[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PRWMLoader.js examples/jsm/loaders/PRWMLoader.js]
-		</p>
-
-	</body>
-</html>

+ 0 - 2
docs/list.json

@@ -373,7 +373,6 @@
 				"OBJLoader": "examples/en/loaders/OBJLoader",
 				"OBJLoader": "examples/en/loaders/OBJLoader",
 				"PCDLoader": "examples/en/loaders/PCDLoader",
 				"PCDLoader": "examples/en/loaders/PCDLoader",
 				"PDBLoader": "examples/en/loaders/PDBLoader",
 				"PDBLoader": "examples/en/loaders/PDBLoader",
-				"PRWMLoader": "examples/en/loaders/PRWMLoader",
 				"SVGLoader": "examples/en/loaders/SVGLoader",
 				"SVGLoader": "examples/en/loaders/SVGLoader",
 				"TGALoader": "examples/en/loaders/TGALoader"
 				"TGALoader": "examples/en/loaders/TGALoader"
 			},
 			},
@@ -1997,7 +1996,6 @@
 				"OBJLoader": "examples/en/loaders/OBJLoader",
 				"OBJLoader": "examples/en/loaders/OBJLoader",
 				"PCDLoader": "examples/en/loaders/PCDLoader",
 				"PCDLoader": "examples/en/loaders/PCDLoader",
 				"PDBLoader": "examples/en/loaders/PDBLoader",
 				"PDBLoader": "examples/en/loaders/PDBLoader",
-				"PRWMLoader": "examples/en/loaders/PRWMLoader",
 				"SVGLoader": "examples/en/loaders/SVGLoader",
 				"SVGLoader": "examples/en/loaders/SVGLoader",
 				"TGALoader": "examples/en/loaders/TGALoader"
 				"TGALoader": "examples/en/loaders/TGALoader"
 			},
 			},

+ 0 - 1
examples/files.json

@@ -111,7 +111,6 @@
 		"webgl_loader_pcd",
 		"webgl_loader_pcd",
 		"webgl_loader_pdb",
 		"webgl_loader_pdb",
 		"webgl_loader_ply",
 		"webgl_loader_ply",
-		"webgl_loader_prwm",
 		"webgl_loader_stl",
 		"webgl_loader_stl",
 		"webgl_loader_svg",
 		"webgl_loader_svg",
 		"webgl_loader_tilt",
 		"webgl_loader_tilt",

+ 0 - 299
examples/jsm/loaders/PRWMLoader.js

@@ -1,299 +0,0 @@
-import {
-	BufferAttribute,
-	BufferGeometry,
-	FileLoader,
-	Loader
-} from 'three';
-
-/**
- * See https://github.com/kchapelier/PRWM for more informations about this file format
- */
-
-let bigEndianPlatform = null;
-
-/**
-	 * Check if the endianness of the platform is big-endian (most significant bit first)
-	 * @returns {boolean} True if big-endian, false if little-endian
-	 */
-function isBigEndianPlatform() {
-
-	if ( bigEndianPlatform === null ) {
-
-		const buffer = new ArrayBuffer( 2 ),
-			uint8Array = new Uint8Array( buffer ),
-			uint16Array = new Uint16Array( buffer );
-
-		uint8Array[ 0 ] = 0xAA; // set first byte
-		uint8Array[ 1 ] = 0xBB; // set second byte
-		bigEndianPlatform = ( uint16Array[ 0 ] === 0xAABB );
-
-	}
-
-	return bigEndianPlatform;
-
-}
-
-// match the values defined in the spec to the TypedArray types
-const InvertedEncodingTypes = [
-	null,
-	Float32Array,
-	null,
-	Int8Array,
-	Int16Array,
-	null,
-	Int32Array,
-	Uint8Array,
-	Uint16Array,
-	null,
-	Uint32Array
-];
-
-// define the method to use on a DataView, corresponding the TypedArray type
-const getMethods = {
-	Uint16Array: 'getUint16',
-	Uint32Array: 'getUint32',
-	Int16Array: 'getInt16',
-	Int32Array: 'getInt32',
-	Float32Array: 'getFloat32',
-	Float64Array: 'getFloat64'
-};
-
-
-function copyFromBuffer( sourceArrayBuffer, viewType, position, length, fromBigEndian ) {
-
-	const bytesPerElement = viewType.BYTES_PER_ELEMENT;
-	let result;
-
-	if ( fromBigEndian === isBigEndianPlatform() || bytesPerElement === 1 ) {
-
-		result = new viewType( sourceArrayBuffer, position, length );
-
-	} else {
-
-		const readView = new DataView( sourceArrayBuffer, position, length * bytesPerElement ),
-			getMethod = getMethods[ viewType.name ],
-			littleEndian = ! fromBigEndian;
-
-		result = new viewType( length );
-
-		for ( let i = 0; i < length; i ++ ) {
-
-			result[ i ] = readView[ getMethod ]( i * bytesPerElement, littleEndian );
-
-		}
-
-	}
-
-	return result;
-
-}
-
-
-function decodePrwm( buffer ) {
-
-	const array = new Uint8Array( buffer ),
-		version = array[ 0 ];
-
-	let flags = array[ 1 ];
-
-	const indexedGeometry = !! ( flags >> 7 & 0x01 ),
-		indicesType = flags >> 6 & 0x01,
-		bigEndian = ( flags >> 5 & 0x01 ) === 1,
-		attributesNumber = flags & 0x1F;
-
-	let valuesNumber = 0,
-		indicesNumber = 0;
-
-	if ( bigEndian ) {
-
-		valuesNumber = ( array[ 2 ] << 16 ) + ( array[ 3 ] << 8 ) + array[ 4 ];
-		indicesNumber = ( array[ 5 ] << 16 ) + ( array[ 6 ] << 8 ) + array[ 7 ];
-
-	} else {
-
-		valuesNumber = array[ 2 ] + ( array[ 3 ] << 8 ) + ( array[ 4 ] << 16 );
-		indicesNumber = array[ 5 ] + ( array[ 6 ] << 8 ) + ( array[ 7 ] << 16 );
-
-	}
-
-	/** PRELIMINARY CHECKS **/
-
-	if ( version === 0 ) {
-
-		throw new Error( 'PRWM decoder: Invalid format version: 0' );
-
-	} else if ( version !== 1 ) {
-
-		throw new Error( 'PRWM decoder: Unsupported format version: ' + version );
-
-	}
-
-	if ( ! indexedGeometry ) {
-
-		if ( indicesType !== 0 ) {
-
-			throw new Error( 'PRWM decoder: Indices type must be set to 0 for non-indexed geometries' );
-
-		} else if ( indicesNumber !== 0 ) {
-
-			throw new Error( 'PRWM decoder: Number of indices must be set to 0 for non-indexed geometries' );
-
-		}
-
-	}
-
-	/** PARSING **/
-
-	let pos = 8;
-
-	const attributes = {};
-
-	for ( let i = 0; i < attributesNumber; i ++ ) {
-
-		let attributeName = '';
-
-		while ( pos < array.length ) {
-
-			const char = array[ pos ];
-			pos ++;
-
-			if ( char === 0 ) {
-
-				break;
-
-			} else {
-
-				attributeName += String.fromCharCode( char );
-
-			}
-
-		}
-
-		flags = array[ pos ];
-
-		const attributeType = flags >> 7 & 0x01;
-		const cardinality = ( flags >> 4 & 0x03 ) + 1;
-		const encodingType = flags & 0x0F;
-		const arrayType = InvertedEncodingTypes[ encodingType ];
-
-		pos ++;
-
-		// padding to next multiple of 4
-		pos = Math.ceil( pos / 4 ) * 4;
-
-		const values = copyFromBuffer( buffer, arrayType, pos, cardinality * valuesNumber, bigEndian );
-
-		pos += arrayType.BYTES_PER_ELEMENT * cardinality * valuesNumber;
-
-		attributes[ attributeName ] = {
-			type: attributeType,
-			cardinality: cardinality,
-			values: values
-		};
-
-	}
-
-	pos = Math.ceil( pos / 4 ) * 4;
-
-	let indices = null;
-
-	if ( indexedGeometry ) {
-
-		indices = copyFromBuffer(
-			buffer,
-			indicesType === 1 ? Uint32Array : Uint16Array,
-			pos,
-			indicesNumber,
-			bigEndian
-		);
-
-	}
-
-	return {
-		version: version,
-		attributes: attributes,
-		indices: indices
-	};
-
-}
-
-// Define the public interface
-
-class PRWMLoader extends Loader {
-
-	constructor( manager ) {
-
-		super( manager );
-
-	}
-
-	load( url, onLoad, onProgress, onError ) {
-
-		const scope = this;
-
-		const loader = new FileLoader( scope.manager );
-		loader.setPath( scope.path );
-		loader.setResponseType( 'arraybuffer' );
-		loader.setRequestHeader( scope.requestHeader );
-		loader.setWithCredentials( scope.withCredentials );
-
-		url = url.replace( /\*/g, isBigEndianPlatform() ? 'be' : 'le' );
-
-		loader.load( url, function ( arrayBuffer ) {
-
-			try {
-
-				onLoad( scope.parse( arrayBuffer ) );
-
-			} catch ( e ) {
-
-				if ( onError ) {
-
-					onError( e );
-
-				} else {
-
-					console.error( e );
-
-				}
-
-				scope.manager.itemError( url );
-
-			}
-
-		}, onProgress, onError );
-
-	}
-
-	parse( arrayBuffer ) {
-
-		const data = decodePrwm( arrayBuffer ),
-			attributesKey = Object.keys( data.attributes ),
-			bufferGeometry = new BufferGeometry();
-
-		for ( let i = 0; i < attributesKey.length; i ++ ) {
-
-			const attribute = data.attributes[ attributesKey[ i ] ];
-			bufferGeometry.setAttribute( attributesKey[ i ], new BufferAttribute( attribute.values, attribute.cardinality, attribute.normalized ) );
-
-		}
-
-		if ( data.indices !== null ) {
-
-			bufferGeometry.setIndex( new BufferAttribute( data.indices, 1 ) );
-
-		}
-
-		return bufferGeometry;
-
-	}
-
-	static isBigEndianPlatform() {
-
-		return isBigEndianPlatform();
-
-	}
-
-}
-
-export { PRWMLoader };

BIN
examples/models/prwm/faceted-nefertiti.be.prwm


BIN
examples/models/prwm/faceted-nefertiti.le.prwm


BIN
examples/models/prwm/smooth-suzanne.be.prwm


BIN
examples/models/prwm/smooth-suzanne.le.prwm


BIN
examples/models/prwm/vive-controller.be.prwm


BIN
examples/models/prwm/vive-controller.le.prwm


BIN
examples/screenshots/webgl_loader_prwm.jpg


+ 0 - 218
examples/webgl_loader_prwm.html

@@ -1,218 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<title>three.js webgl - loaders - PRWM loader</title>
-		<meta charset="utf-8">
-		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-		<link type="text/css" rel="stylesheet" href="main.css">
-		<style>
-			.notes {
-				position: fixed;
-				text-align: left;
-				bottom: 10px;
-				font-family: "Arial", "Helvetica Neue", "Helvetica", sans-serif;
-			}
-		</style>
-	</head>
-	<body>
-
-		<div id="info">
-			<strong>Models</strong>:
-			<a class="model" href="models/prwm/faceted-nefertiti.*.prwm">Faceted Nefertiti</a>,
-			<a class="model" href="models/prwm/smooth-suzanne.*.prwm">Smooth Suzanne</a>,
-			<a class="model" href="models/prwm/vive-controller.*.prwm">Vive Controller</a>
-			<div class="notes">
-				The parsing of PRWM file is especially fast when the endianness of the file is the same as the endianness of the client platform.
-				The loader will automatically replace the <strong>*</strong> in the model url by either <strong>le</strong> or <strong>be</strong> depending on the client platform's endianness to download the most appropriate file. <a href="https://github.com/kchapelier/PRWM" target="_blank" rel="noopener noreferrer">Specifications and implementations</a><br><br>
-				This platform endianness is <strong id="endianness"></strong>.<br>
-				See your console for stats.
-			</div>
-		</div>
-
-		<!-- Import maps polyfill -->
-		<!-- Remove this when import maps will be widely supported -->
-		<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
-
-		<script type="importmap">
-			{
-				"imports": {
-					"three": "../build/three.module.js",
-					"three/addons/": "./jsm/"
-				}
-			}
-		</script>
-
-		<script type="module">
-
-			import * as THREE from 'three';
-
-			import { PRWMLoader } from 'three/addons/loaders/PRWMLoader.js';
-
-			let camera, scene, renderer;
-
-			let mouseX = 0, mouseY = 0;
-
-			let windowHalfX = window.innerWidth / 2;
-			let windowHalfY = window.innerHeight / 2;
-
-			init();
-			animate();
-
-
-			function init() {
-
-				document.getElementById( 'endianness' ).innerHTML = PRWMLoader.isBigEndianPlatform() ? 'big-endian' : 'little-endian';
-				const container = document.createElement( 'div' );
-				document.body.appendChild( container );
-
-				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
-				camera.position.z = 250;
-
-				// scene
-
-				scene = new THREE.Scene();
-
-				const ambient = new THREE.AmbientLight( 0x101030 );
-				scene.add( ambient );
-
-				const directionalLight = new THREE.DirectionalLight( 0xffeedd );
-				directionalLight.position.set( 0, 0, 1 );
-				scene.add( directionalLight );
-
-				// model
-
-				const loader = new PRWMLoader();
-				const material = new THREE.MeshPhongMaterial( {} );
-				let busy = false;
-				let mesh = null;
-
-				const onProgress = function ( xhr ) {
-
-					if ( xhr.lengthComputable ) {
-
-						const percentComplete = xhr.loaded / xhr.total * 100;
-						console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
-
-						if ( xhr.loaded === xhr.total ) {
-
-							console.log( 'File size: ' + ( xhr.total / 1024 ).toFixed( 2 ) + 'kB' );
-							console.timeEnd( 'Download' );
-
-						}
-
-					}
-
-				};
-
-				const onError = function () {
-
-					busy = false;
-
-				};
-
-				function loadGeometry( url ) {
-
-					if ( busy ) return;
-
-					busy = true;
-
-					if ( mesh !== null ) {
-
-						scene.remove( mesh );
-						mesh.geometry.dispose();
-
-					}
-
-					console.log( '-- Loading', url );
-					console.time( 'Download' );
-
-					loader.load( url, function ( geometry ) {
-
-						mesh = new THREE.Mesh( geometry, material );
-						mesh.scale.set( 50, 50, 50 );
-						scene.add( mesh );
-
-						console.log( geometry.index ? 'indexed geometry' : 'non-indexed geometry' );
-						console.log( '# of vertices: ' + geometry.attributes.position.count );
-						console.log( '# of polygons: ' + ( geometry.index ? geometry.index.count / 3 : geometry.attributes.position.count / 3 ) );
-						busy = false;
-
-					}, onProgress, onError );
-
-				}
-
-				//
-
-				renderer = new THREE.WebGLRenderer( { antialias: true } );
-				renderer.setPixelRatio( window.devicePixelRatio );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				container.appendChild( renderer.domElement );
-
-				document.addEventListener( 'mousemove', onDocumentMouseMove );
-
-				//
-
-				document.querySelectorAll( 'a.model' ).forEach( function ( anchor ) {
-
-					anchor.addEventListener( 'click', function ( e ) {
-
-						e.preventDefault();
-
-						loadGeometry( anchor.href );
-
-					} );
-
-				} );
-
-				//
-
-				// * is automatically replaced by 'le' or 'be' depending on the client platform's endianness
-				loadGeometry( './models/prwm/smooth-suzanne.*.prwm' );
-
-				window.addEventListener( 'resize', onWindowResize );
-
-			}
-
-			function onWindowResize() {
-
-				windowHalfX = window.innerWidth / 2;
-				windowHalfY = window.innerHeight / 2;
-
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
-
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
-			}
-
-			function onDocumentMouseMove( event ) {
-
-				mouseX = ( event.clientX - windowHalfX ) / 2;
-				mouseY = ( event.clientY - windowHalfY ) / 2;
-
-			}
-
-			//
-
-			function animate() {
-
-				requestAnimationFrame( animate );
-				render();
-
-			}
-
-			function render() {
-
-				camera.position.x += ( mouseX - camera.position.x ) * .05;
-				camera.position.y += ( - mouseY - camera.position.y ) * .05;
-
-				camera.lookAt( scene.position );
-
-				renderer.render( scene, camera );
-
-			}
-
-		</script>
-
-	</body>
-</html>