提交 65ff2d67 编写于 作者: M Mr.doob

Examples: Removed Assimp2JSONLoader. (Use AssimpLoader instead)

上级 0785d483
......@@ -78,7 +78,6 @@ var files = {
"webgl_loader_3mf_materials",
"webgl_loader_amf",
"webgl_loader_assimp",
"webgl_loader_assimp2json",
"webgl_loader_bvh",
"webgl_loader_collada",
"webgl_loader_collada_kinematics",
......
/**
* @author Alexander Gessler / http://www.greentoken.de/
* https://github.com/acgessler
*
* Loader for models imported with Open Asset Import Library (http://assimp.sf.net)
* through assimp2json (https://github.com/acgessler/assimp2json).
*
* Supports any input format that assimp supports, including 3ds, obj, dae, blend,
* fbx, x, ms3d, lwo (and many more).
*
* See webgl_loader_assimp2json example.
*/
THREE.AssimpJSONLoader = function ( manager ) {
THREE.Loader.call( this, manager );
};
THREE.AssimpJSONLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: THREE.AssimpJSONLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( scope.path === '' ) ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
var loader = new THREE.FileLoader( this.manager );
loader.setPath( scope.path );
loader.load( url, function ( text ) {
var json = JSON.parse( text );
var metadata = json.__metadata__;
// check if __metadata__ meta header is present
// this header is used to disambiguate between different JSON-based file formats
if ( typeof metadata !== 'undefined' ) {
// check if assimp2json at all
if ( metadata.format !== 'assimp2json' ) {
onError( 'THREE.AssimpJSONLoader: Not an assimp2json scene.' );
return;
// check major format version
} else if ( metadata.version < 100 && metadata.version >= 200 ) {
onError( 'THREE.AssimpJSONLoader: Unsupported assimp2json file format version.' );
return;
}
}
onLoad( scope.parse( json, path ) );
}, onProgress, onError );
},
parse: function ( json, path ) {
function parseList( json, handler ) {
var meshes = new Array( json.length );
for ( var i = 0; i < json.length; ++ i ) {
meshes[ i ] = handler.call( this, json[ i ] );
}
return meshes;
}
function parseMesh( json ) {
var geometry = new THREE.BufferGeometry();
var i, l, face;
var indices = [];
var vertices = json.vertices || [];
var normals = json.normals || [];
var uvs = json.texturecoords || [];
var colors = json.colors || [];
uvs = uvs[ 0 ] || []; // only support for a single set of uvs
for ( i = 0, l = json.faces.length; i < l; i ++ ) {
face = json.faces[ i ];
indices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
}
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
if ( normals.length > 0 ) {
geometry.setAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
}
if ( uvs.length > 0 ) {
geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
}
if ( colors.length > 0 ) {
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
}
geometry.computeBoundingSphere();
return geometry;
}
function parseMaterial( json ) {
var material = new THREE.MeshPhongMaterial();
for ( var i in json.properties ) {
var property = json.properties[ i ];
var key = property.key;
var value = property.value;
switch ( key ) {
case '$tex.file': {
var semantic = property.semantic;
// prop.semantic gives the type of the texture
// 1: diffuse
// 2: specular map
// 4: emissive map
// 5: height map (bumps)
// 6: normal map
// more values (i.e. environment, etc) are known by assimp and may be relevant
if ( semantic === 1 || semantic === 2 || semantic === 4 || semantic === 5 || semantic === 6 ) {
var keyname;
switch ( semantic ) {
case 1:
keyname = 'map';
break;
case 2:
keyname = 'specularMap';
break;
case 4:
keyname = 'emissiveMap';
break;
case 5:
keyname = 'bumpMap';
break;
case 6:
keyname = 'normalMap';
break;
}
var texture = textureLoader.load( value );
// TODO: read texture settings from assimp.
// Wrapping is the default, though.
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
material[ keyname ] = texture;
}
break;
}
case '?mat.name':
material.name = value;
break;
case '$clr.diffuse':
material.color.fromArray( value );
break;
case '$clr.specular':
material.specular.fromArray( value );
break;
case '$clr.emissive':
material.emissive.fromArray( value );
break;
case '$mat.shininess':
material.shininess = value;
break;
case '$mat.shadingm':
// aiShadingMode_Flat
material.flatShading = ( value === 1 ) ? true : false;
break;
case '$mat.opacity':
if ( value < 1 ) {
material.opacity = value;
material.transparent = true;
}
break;
}
}
return material;
}
function parseObject( json, node, meshes, materials ) {
var obj = new THREE.Object3D(), i, idx;
obj.name = node.name || '';
obj.matrix = new THREE.Matrix4().fromArray( node.transformation ).transpose();
obj.matrix.decompose( obj.position, obj.quaternion, obj.scale );
for ( i = 0; node.meshes && i < node.meshes.length; i ++ ) {
idx = node.meshes[ i ];
obj.add( new THREE.Mesh( meshes[ idx ], materials[ json.meshes[ idx ].materialindex ] ) );
}
for ( i = 0; node.children && i < node.children.length; i ++ ) {
obj.add( parseObject( json, node.children[ i ], meshes, materials ) );
}
return obj;
}
var textureLoader = new THREE.TextureLoader( this.manager );
textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
var meshes = parseList( json.meshes, parseMesh );
var materials = parseList( json.materials, parseMaterial );
return parseObject( json, json.rootnode, meshes, materials );
}
} );
import {
Object3D,
Loader,
LoadingManager
} from '../../../src/Three';
export class AssimpJSONLoader extends Loader {
constructor( manager?: LoadingManager );
load( url: string, onLoad: ( object: Object3D ) => void, onProgress?: ( event: ProgressEvent ) => void, onError?: ( event: ErrorEvent ) => void ) : void;
parse( json: object, path: string ) : Object3D;
}
/**
* @author Alexander Gessler / http://www.greentoken.de/
* https://github.com/acgessler
*
* Loader for models imported with Open Asset Import Library (http://assimp.sf.net)
* through assimp2json (https://github.com/acgessler/assimp2json).
*
* Supports any input format that assimp supports, including 3ds, obj, dae, blend,
* fbx, x, ms3d, lwo (and many more).
*
* See webgl_loader_assimp2json example.
*/
import {
BufferGeometry,
FileLoader,
Float32BufferAttribute,
Loader,
LoaderUtils,
Matrix4,
Mesh,
MeshPhongMaterial,
Object3D,
RepeatWrapping,
TextureLoader
} from "../../../build/three.module.js";
var AssimpJSONLoader = function ( manager ) {
Loader.call( this, manager );
};
AssimpJSONLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: AssimpJSONLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( scope.path === '' ) ? LoaderUtils.extractUrlBase( url ) : scope.path;
var loader = new FileLoader( this.manager );
loader.setPath( scope.path );
loader.load( url, function ( text ) {
var json = JSON.parse( text );
var metadata = json.__metadata__;
// check if __metadata__ meta header is present
// this header is used to disambiguate between different JSON-based file formats
if ( typeof metadata !== 'undefined' ) {
// check if assimp2json at all
if ( metadata.format !== 'assimp2json' ) {
onError( 'THREE.AssimpJSONLoader: Not an assimp2json scene.' );
return;
// check major format version
} else if ( metadata.version < 100 && metadata.version >= 200 ) {
onError( 'THREE.AssimpJSONLoader: Unsupported assimp2json file format version.' );
return;
}
}
onLoad( scope.parse( json, path ) );
}, onProgress, onError );
},
parse: function ( json, path ) {
function parseList( json, handler ) {
var meshes = new Array( json.length );
for ( var i = 0; i < json.length; ++ i ) {
meshes[ i ] = handler.call( this, json[ i ] );
}
return meshes;
}
function parseMesh( json ) {
var geometry = new BufferGeometry();
var i, l, face;
var indices = [];
var vertices = json.vertices || [];
var normals = json.normals || [];
var uvs = json.texturecoords || [];
var colors = json.colors || [];
uvs = uvs[ 0 ] || []; // only support for a single set of uvs
for ( i = 0, l = json.faces.length; i < l; i ++ ) {
face = json.faces[ i ];
indices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
}
geometry.setIndex( indices );
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
if ( normals.length > 0 ) {
geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
}
if ( uvs.length > 0 ) {
geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
}
if ( colors.length > 0 ) {
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
}
geometry.computeBoundingSphere();
return geometry;
}
function parseMaterial( json ) {
var material = new MeshPhongMaterial();
for ( var i in json.properties ) {
var property = json.properties[ i ];
var key = property.key;
var value = property.value;
switch ( key ) {
case '$tex.file': {
var semantic = property.semantic;
// prop.semantic gives the type of the texture
// 1: diffuse
// 2: specular map
// 4: emissive map
// 5: height map (bumps)
// 6: normal map
// more values (i.e. environment, etc) are known by assimp and may be relevant
if ( semantic === 1 || semantic === 2 || semantic === 4 || semantic === 5 || semantic === 6 ) {
var keyname;
switch ( semantic ) {
case 1:
keyname = 'map';
break;
case 2:
keyname = 'specularMap';
break;
case 4:
keyname = 'emissiveMap';
break;
case 5:
keyname = 'bumpMap';
break;
case 6:
keyname = 'normalMap';
break;
}
var texture = textureLoader.load( value );
// TODO: read texture settings from assimp.
// Wrapping is the default, though.
texture.wrapS = texture.wrapT = RepeatWrapping;
material[ keyname ] = texture;
}
break;
}
case '?mat.name':
material.name = value;
break;
case '$clr.diffuse':
material.color.fromArray( value );
break;
case '$clr.specular':
material.specular.fromArray( value );
break;
case '$clr.emissive':
material.emissive.fromArray( value );
break;
case '$mat.shininess':
material.shininess = value;
break;
case '$mat.shadingm':
// aiShadingMode_Flat
material.flatShading = ( value === 1 ) ? true : false;
break;
case '$mat.opacity':
if ( value < 1 ) {
material.opacity = value;
material.transparent = true;
}
break;
}
}
return material;
}
function parseObject( json, node, meshes, materials ) {
var obj = new Object3D(), i, idx;
obj.name = node.name || '';
obj.matrix = new Matrix4().fromArray( node.transformation ).transpose();
obj.matrix.decompose( obj.position, obj.quaternion, obj.scale );
for ( i = 0; node.meshes && i < node.meshes.length; i ++ ) {
idx = node.meshes[ i ];
obj.add( new Mesh( meshes[ idx ], materials[ json.meshes[ idx ].materialindex ] ) );
}
for ( i = 0; node.children && i < node.children.length; i ++ ) {
obj.add( parseObject( json, node.children[ i ], meshes, materials ) );
}
return obj;
}
var textureLoader = new TextureLoader( this.manager );
textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
var meshes = parseList( json.meshes, parseMesh );
var materials = parseList( json.materials, parseMaterial );
return parseObject( json, json.rootnode, meshes, materials );
}
} );
export { AssimpJSONLoader };
此差异已折叠。
Jeep designed, modelled and skinned by me, Psionic
FREE for use however you like, credits are appreciated!!!
It was modelled in Milkshape 3D and includes the MS3D files oriented for X or B3D format (BlitzBasic 3D), its 2032 polys with a 512x512 jpg texture map. There are two skin variations plus a UV template to help out if you want to create your own skin variations.
I'd love to see a few screenshots of it being used in-game so feel free to stop by my site and maybe drop by my forums and show us all what your doing with it!!!!!!!
Check out more of my work at:-
http://xu1productions.com/3dstudio/index.html - 3D Game Resources
http://www.psionicdesign.com - My Main 2D/3D Digital Art site
Psionic 2002
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - Open Asset Import Library (assimp) / assimp2json</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">
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> -
Jeep by Psionic, interior from
<a href="http://www.assimp.org/" target="_blank" rel="noopener">Assimp</a>
</div>
<script type="module">
import * as THREE from '../build/three.module.js';
import Stats from './jsm/libs/stats.module.js';
import { AssimpJSONLoader } from './jsm/loaders/AssimpJSONLoader.js';
/*
Simple demo for loading json files generated by assimp2json
https://github.com/acgessler/assimp2json
assimp2json uses assimp (http://assimp.sf.net) to import 40+ 3D file
formats, including 3ds, obj, dae, blend, fbx, x, ms3d, lwo (and many
more).
TODOs:
- assimp supports skeletal animations and assimp2son exports
them. This demo currently doesn't read them.
- not all material properties supported by assimp are currently
mapped to THREE.js
The sample files for this demo originate in assimp's repository,
and were converted using assimp2json 2.0. The interior file was
slightly edited to adjust for lower-case texture names.
*/
var container, stats, clock;
var camera, scene, renderer;
init();
animate();
//
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
scene = new THREE.Scene();
clock = new THREE.Clock();
// load jeep model
var loader = new AssimpJSONLoader();
loader.load( 'models/assimp/jeep/jeep.assimp.json', function ( object ) {
object.scale.multiplyScalar( 0.2 );
scene.add( object );
} );
// load interior model
loader.load( 'models/assimp/interior/interior.assimp.json', function ( object ) {
scene.add( object );
} );
//
var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( 0xeeeeee );
directionalLight.position.set( 1, 1, - 1 );
directionalLight.position.normalize();
scene.add( directionalLight );
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
//
stats = new Stats();
container.appendChild( stats.dom );
//
window.addEventListener( 'resize', onWindowResize, false );
}
//
function onWindowResize() {
renderer.setSize( window.innerWidth, window.innerHeight );
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
//
function render() {
var elapsedTime = clock.getElapsedTime();
camera.position.x = Math.cos( elapsedTime * 0.5 ) * 10;
camera.position.y = 4;
camera.position.z = Math.sin( elapsedTime * 0.5 ) * 10;
camera.lookAt( scene.position );
renderer.render( scene, camera );
}
</script>
</body>
</html>
......@@ -73,7 +73,6 @@ var files = [
{ path: 'loaders/deprecated/LegacyJSONLoader.js', dependencies: [], ignoreList: [ 'ObjectLoader' ] },
{ path: 'loaders/3MFLoader.js', dependencies: [], ignoreList: [] },
{ path: 'loaders/AMFLoader.js', dependencies: [], ignoreList: [] },
{ path: 'loaders/AssimpJSONLoader.js', dependencies: [], ignoreList: [] },
{ path: 'loaders/AssimpLoader.js', dependencies: [], ignoreList: [] },
{ path: 'loaders/BasisTextureLoader.js', dependencies: [], ignoreList: [] },
{ path: 'loaders/BVHLoader.js', dependencies: [], ignoreList: [ 'Bones' ] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册