未验证 提交 d649e79f 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #15060 from kaisalmen/OBJLoader2_V250

OBJLoader2 V2.5.0
此差异已折叠。
......@@ -83,34 +83,31 @@
'use strict';
var OBJLoader2Example = ( function () {
var Validator = THREE.LoaderSupport.Validator;
function OBJLoader2Example( elementToBindTo ) {
this.renderer = null;
this.canvas = elementToBindTo;
this.aspectRatio = 1;
this.recalcAspectRatio();
this.scene = null;
this.cameraDefaults = {
posCamera: new THREE.Vector3( 0.0, 175.0, 500.0 ),
posCameraTarget: new THREE.Vector3( 0, 0, 0 ),
near: 0.1,
far: 10000,
fov: 45
};
this.camera = null;
this.cameraTarget = this.cameraDefaults.posCameraTarget;
var OBJLoader2Example = function ( elementToBindTo ) {
this.renderer = null;
this.canvas = elementToBindTo;
this.aspectRatio = 1;
this.recalcAspectRatio();
this.scene = null;
this.cameraDefaults = {
posCamera: new THREE.Vector3( 0.0, 175.0, 500.0 ),
posCameraTarget: new THREE.Vector3( 0, 0, 0 ),
near: 0.1,
far: 10000,
fov: 45
};
this.camera = null;
this.cameraTarget = this.cameraDefaults.posCameraTarget;
this.controls = null;
this.controls = null;
};
}
OBJLoader2Example.prototype = {
OBJLoader2Example.prototype.initGL = function () {
constructor: OBJLoader2Example,
initGL: function () {
this.renderer = new THREE.WebGLRenderer( {
canvas: this.canvas,
antialias: true,
......@@ -128,8 +125,8 @@
var directionalLight1 = new THREE.DirectionalLight( 0xC0C090 );
var directionalLight2 = new THREE.DirectionalLight( 0xC0C090 );
directionalLight1.position.set( - 100, - 50, 100 );
directionalLight2.position.set( 100, 50, - 100 );
directionalLight1.position.set( -100, -50, 100 );
directionalLight2.position.set( 100, 50, -100 );
this.scene.add( directionalLight1 );
this.scene.add( directionalLight2 );
......@@ -137,103 +134,78 @@
var helper = new THREE.GridHelper( 1200, 60, 0xFF4444, 0x404040 );
this.scene.add( helper );
},
};
OBJLoader2Example.prototype.initContent = function () {
initContent: function () {
var modelName = 'female02';
this._reportProgress( { detail: { text: 'Loading: ' + modelName } } );
var scope = this;
var objLoader = new THREE.OBJLoader2();
var callbackOnLoad = function ( event ) {
scope.scene.add( event.detail.loaderRootNode );
console.log( 'Loading complete: ' + event.detail.modelName );
scope._reportProgress( { detail: { text: '' } } );
};
var onLoadMtl = function ( materials ) {
objLoader.setModelName( modelName );
objLoader.setMaterials( materials );
objLoader.setLogging( true, true );
objLoader.load( 'models/obj/female02/female02.obj', callbackOnLoad, null, null, null, false );
};
objLoader.loadMtl( 'models/obj/female02/female02.mtl', null, onLoadMtl );
},
};
OBJLoader2Example.prototype._reportProgress = function ( event ) {
var output = Validator.verifyInput( event.detail.text, '' );
_reportProgress: function( event ) {
var output = THREE.LoaderSupport.Validator.verifyInput( event.detail.text, '' );
console.log( 'Progress: ' + output );
document.getElementById( 'feedback' ).innerHTML = output;
},
};
OBJLoader2Example.prototype.resizeDisplayGL = function () {
resizeDisplayGL: function () {
this.controls.handleResize();
this.recalcAspectRatio();
this.renderer.setSize( this.canvas.offsetWidth, this.canvas.offsetHeight, false );
this.updateCamera();
},
};
OBJLoader2Example.prototype.recalcAspectRatio = function () {
recalcAspectRatio: function () {
this.aspectRatio = ( this.canvas.offsetHeight === 0 ) ? 1 : this.canvas.offsetWidth / this.canvas.offsetHeight;
},
};
OBJLoader2Example.prototype.resetCamera = function () {
resetCamera: function () {
this.camera.position.copy( this.cameraDefaults.posCamera );
this.cameraTarget.copy( this.cameraDefaults.posCameraTarget );
this.updateCamera();
},
};
OBJLoader2Example.prototype.updateCamera = function () {
updateCamera: function () {
this.camera.aspect = this.aspectRatio;
this.camera.lookAt( this.cameraTarget );
this.camera.updateProjectionMatrix();
},
};
OBJLoader2Example.prototype.render = function () {
render: function () {
if ( ! this.renderer.autoClear ) this.renderer.clear();
this.controls.update();
this.renderer.render( this.scene, this.camera );
}
};
return OBJLoader2Example;
} )();
};
var app = new OBJLoader2Example( document.getElementById( 'example' ) );
var resizeWindow = function () {
app.resizeDisplayGL();
};
var render = function () {
requestAnimationFrame( render );
app.render();
};
window.addEventListener( 'resize', resizeWindow, false );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册