提交 85d3e312 编写于 作者: M Mr.doob

Merge remote-tracking branch 'alteredq/dev' into dev

因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -18,13 +18,13 @@ THREE.CTMLoader.prototype = Object.create( THREE.Loader.prototype );
// Load multiple CTM parts defined in JSON
THREE.CTMLoader.prototype.loadParts = function( url, callback, useWorker, useBuffers, basePath ) {
THREE.CTMLoader.prototype.loadParts = function( url, callback, parameters ) {
var scope = this;
var xhr = new XMLHttpRequest();
basePath = basePath ? basePath : this.extractUrlBase( url );
var basePath = parameters.basePath ? parameters.basePath : this.extractUrlBase( url );
xhr.onreadystatechange = function() {
......@@ -62,7 +62,8 @@ THREE.CTMLoader.prototype.loadParts = function( url, callback, useWorker, useBuf
// load joined CTM file
var partUrl = basePath + jsonObject.data;
scope.load( partUrl, callbackFinal, useWorker, useBuffers, jsonObject.offsets );
var parametersPart = { useWorker: parameters.useWorker, useBuffers: parameters.useBuffers, offsets: jsonObject.offsets };
scope.load( partUrl, callbackFinal, parametersPart );
}
......@@ -82,11 +83,11 @@ THREE.CTMLoader.prototype.loadParts = function( url, callback, useWorker, useBuf
// - url (required)
// - callback (required)
THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers, offsets ) {
THREE.CTMLoader.prototype.load = function( url, callback, parameters ) {
var scope = this;
offsets = offsets !== undefined ? offsets : [ 0 ];
var offsets = parameters.offsets !== undefined ? parameters.offsets : [ 0 ];
var xhr = new XMLHttpRequest(),
callbackProgress = null;
......@@ -103,7 +104,7 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
//var s = Date.now();
if ( useWorker ) {
if ( parameters.useWorker ) {
var worker = new Worker( "js/loaders/ctm/CTMWorker.js" );
......@@ -115,7 +116,7 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
var ctmFile = files[ i ];
if ( useBuffers ) {
if ( parameters.useBuffers ) {
scope.createModelBuffers( ctmFile, callback );
......@@ -144,7 +145,7 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
var ctmFile = new CTM.File( stream );
if ( useBuffers ) {
if ( parameters.useBuffers ) {
scope.createModelBuffers( ctmFile, callback );
......
......@@ -36,7 +36,9 @@
"position" : [ -30, -5, 25 ],
"rotation" : [ 0, 0.8, 0 ],
"scale" : [ 1, 1, 1 ],
"visible" : true
"visible" : true,
"children" : {
}
},
"sphere_lambert" : {
......@@ -145,12 +147,21 @@
"walt" : {
"geometry" : "WaltHead",
"materials": [ "lambert_cube" ],
"position" : [ -45, 10, 0 ],
"rotation" : [ 0, 0, 0 ],
"position" : [ -75, 10, -30 ],
"rotation" : [ 0, 0.5, 0 ],
"scale" : [ 0.5, 0.5, 0.5 ],
"visible" : true
},
"ben" : {
"geometry" : "ben",
"materials": [ "phong_ben" ],
"position" : [ -45, -10, 0 ],
"rotation" : [ 0, 0.5, 0 ],
"scale" : [ 55, 55, 55 ],
"visible" : true
},
"ninja" : {
"geometry" : "NinjaLo",
"materials": [ "phong_normal" ],
......@@ -288,6 +299,13 @@
"url" : "obj/veyron/VeyronNoUv_bin.js"
},
"ben": {
"type": "ctm_mesh",
"url" : "models/ctm/ben.ctm",
"useWorkers" : true,
"useBuffers" : true
},
"colorcube": {
"type": "embedded_mesh",
"id" : "cube_fvc"
......@@ -355,9 +373,14 @@
"parameters": { "color": 16711680, "specular": 16711680, "shininess": 25, "bumpMap": "texture_bump", "bumpScale": -0.75 }
},
"phong_ben": {
"type": "MeshPhongMaterial",
"parameters": { "color": 1118481, "ambient": 1118481, "specular": 5601245, "shininess": 12, "bumpMap": "texture_bump_repeat", "bumpScale": 0.125, "envMaps": "cube_reflection", "reflectivity": 0.5 }
},
"phong_normal": {
"type": "MeshPhongMaterial",
"parameters": { "color": 1118481, "specular": 16777215, "shininess": 25, "envMap": "cube_reflection", "reflectivity": 0.1, "lightMap": "texture_ao", "normalMap": "texture_normal", "normalScale": [ 1, -1 ], "displacementMap": "texture_displacement", "displacementScale": 2.436143, "displacementBias": -0.428408 }
"parameters": { "color": 0, "specular": 16777215, "shininess": 25, "envMap": "cube_reflection", "reflectivity": 0.1, "lightMap": "texture_ao", "normalMap": "texture_normal", "normalScale": [ 1, -1 ], "displacementMap": "texture_displacement", "displacementScale": 2.436143, "displacementBias": -0.428408 }
},
"lambert_green": {
......@@ -465,6 +488,12 @@
"anisotropy": 4
},
"texture_bump_repeat": {
"url": "textures/water.jpg",
"repeat" : [ 20, 20 ],
"anisotropy": 4
},
"texture_normal": {
"url": "textures/normal/ninja/normal.jpg",
"anisotropy": 4
......@@ -518,15 +547,15 @@
"type" : "directional",
"direction" : [0,1,1],
"color" : 16777215,
"intensity" : 0.8
"intensity" : 1
},
"light2": {
"type" : "point",
"position": [0,0,0],
"color" : 16777215
"color" : 16777215,
"intensity" : 1.25
}
},
"fogs": {
......
......@@ -155,9 +155,7 @@
}
var useWorker = true;
var useBuffers = true;
var parameters = { useWorker: true, useBuffers: true };
var loader = new THREE.CTMLoader();
loader.load( "models/ctm/ben.ctm", function( geometry ) {
......@@ -166,7 +164,7 @@
callbackModel( geometry, 450, material, 0, -200, 0, 0, 0 );
checkTime();
}, useWorker, useBuffers );
}, parameters );
loader.load( "models/ctm/WaltHead.ctm", function( geometry ) {
......@@ -180,7 +178,7 @@
checkTime();
}, useWorker, useBuffers );
}, parameters );
loader.load( "models/ctm/LeePerry.ctm", function( geometry ) {
......@@ -222,7 +220,7 @@
callbackModel( geometry, 1300, material, 200, 50, 0, 0, 0 );
checkTime();
}, useWorker, useBuffers );
}, parameters );
}
......
......@@ -196,8 +196,7 @@
*/
// new way via CTMLoader and separate parts
var useWorker = true,
useBuffers = true;
var parameters = { useWorker: true, useBuffers: true };
loaderCTM = new THREE.CTMLoader( true );
document.body.appendChild( loaderCTM.statusDomElement );
......@@ -224,7 +223,7 @@
console.log( "load time:", end - start, "ms" );
}, useWorker, useBuffers );
}, parameters );
}
......
......@@ -149,6 +149,10 @@
<script src="../build/three.min.js"></script>
<script src="js/loaders/ctm/lzma.js"></script>
<script src="js/loaders/ctm/ctm.js"></script>
<script src="js/loaders/ctm/CTMLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......@@ -230,6 +234,10 @@
renderer.domElement.style.position = "relative";
container.appendChild( renderer.domElement );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.physicallyBasedShading = true;
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
......@@ -315,6 +323,8 @@
var loader = new THREE.SceneLoader();
loader.addGeometryHandler( "ctm_mesh", THREE.CTMLoader );
loader.callbackSync = callbackSync;
loader.callbackProgress = callbackProgress;
......
......@@ -11,11 +11,16 @@ THREE.SceneLoader = function () {
this.callbackSync = function () {};
this.callbackProgress = function () {};
this.geometryHandlerMap = {};
this.addGeometryHandler( "ascii_mesh", THREE.JSONLoader );
this.addGeometryHandler( "bin_mesh", THREE.BinaryLoader );
};
THREE.SceneLoader.prototype.constructor = THREE.SceneLoader;
THREE.SceneLoader.prototype.load = function( url, callbackFinished ) {
THREE.SceneLoader.prototype.load = function ( url, callbackFinished ) {
var scope = this;
......@@ -47,6 +52,12 @@ THREE.SceneLoader.prototype.load = function( url, callbackFinished ) {
};
THREE.SceneLoader.prototype.addGeometryHandler = function ( typeID, loaderClass ) {
this.geometryHandlerMap[ typeID ] = { "loaderClass": loaderClass };
};
THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
var scope = this;
......@@ -58,15 +69,20 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
geometry, material, camera, fog,
texture, images,
light,
data, binLoader, jsonLoader,
counter_models, counter_textures,
total_models, total_textures,
result;
data = json;
var data = json;
// async geometry loaders
for ( var typeID in this.geometryHandlerMap ) {
binLoader = new THREE.BinaryLoader();
jsonLoader = new THREE.JSONLoader();
var loaderClass = this.geometryHandlerMap[ typeID ][ "loaderClass" ];
this.geometryHandlerMap[ typeID ][ "loaderObject" ] = new loaderClass();
}
counter_models = 0;
counter_textures = 0;
......@@ -123,7 +139,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
};
// the toplevel loader function, delegates to handle_children
// toplevel loader function, delegates to handle_children
function handle_objects() {
......@@ -273,7 +289,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
if ( o.properties !== undefined) {
if ( o.properties !== undefined ) {
for ( var key in o.properties ) {
......@@ -495,7 +511,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
g = data.geometries[ dg ];
if ( g.type == "bin_mesh" || g.type == "ascii_mesh" ) {
if ( g.type in this.geometryHandlerMap ) {
counter_models += 1;
......@@ -541,13 +557,21 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
geometry = new THREE.IcosahedronGeometry( g.radius, g.subdivisions );
result.geometries[ dg ] = geometry;
} else if ( g.type === "bin_mesh" ) {
} else if ( g.type in this.geometryHandlerMap ) {
var loaderParameters = {};
for ( var parType in g ) {
if ( parType !== "type" && parType !== "url" ) {
binLoader.load( get_url( g.url, data.urlBaseType ), create_callback( dg ) );
loaderParameters[ parType ] = g[ parType ];
} else if ( g.type === "ascii_mesh" ) {
}
}
jsonLoader.load( get_url( g.url, data.urlBaseType ), create_callback( dg ) );
var loader = this.geometryHandlerMap[ g.type ][ "loaderObject" ];
loader.load( get_url( g.url, data.urlBaseType ), create_callback( dg ), loaderParameters );
} else if ( g.type === "embedded_mesh" ) {
......@@ -560,6 +584,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( modelJson ) {
var jsonLoader = this.geometryHandlerMap[ "ascii_mesh" ][ "loaderObject" ];
jsonLoader.createModel( modelJson, create_callback_embed( dg ), texture_path );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册