verify.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - OBJLoader2/OBJLoader verification</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. font-family: Monospace;
  10. background-color: #000;
  11. color: #fff;
  12. margin: 0 0 0 0;
  13. padding: 0 0 0 0;
  14. border: none;
  15. cursor: default;
  16. }
  17. #info {
  18. color: #fff;
  19. position: absolute;
  20. top: 10px;
  21. width: 100%;
  22. text-align: center;
  23. z-index: 100;
  24. display:block;
  25. }
  26. #info a {
  27. color: #f00;
  28. font-weight: bold;
  29. text-decoration: underline;
  30. cursor: pointer
  31. }
  32. #glFullscreen {
  33. width: 100%;
  34. height: 100vh;
  35. min-width: 640px;
  36. min-height: 360px;
  37. position: relative;
  38. overflow: hidden;
  39. z-index: 0;
  40. }
  41. #example {
  42. width: 100%;
  43. height: 100%;
  44. top: 0;
  45. left: 0;
  46. background-color: #000000;
  47. }
  48. #feedback {
  49. color: darkorange;
  50. }
  51. #dat {
  52. user-select: none;
  53. position: absolute;
  54. left: 0;
  55. top: 0;
  56. z-Index: 200;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div id="glFullscreen">
  62. <canvas id="example"></canvas>
  63. </div>
  64. <div id="dat">
  65. </div>
  66. <div id="info">
  67. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - OBJLoader2/OBJLoader verification
  68. <div id="feedback"></div>
  69. </div>
  70. <script src="../../../js/Detector.js"></script>
  71. <script src="../../../../build/three.js"></script>
  72. <script src="../../../js/controls/TrackballControls.js"></script>
  73. <script src="../../../js/loaders/MTLLoader.js"></script>
  74. <script src="../../../js/loaders/OBJLoader.js"></script>
  75. <script src="../../../js/libs/dat.gui.min.js"></script>
  76. <script src="../../../js/loaders/LoaderSupport.js"></script>
  77. <script src="../../../js/loaders/OBJLoader2.js"></script>
  78. <script>
  79. 'use strict';
  80. var OBJLoaderVerify = (function () {
  81. var Validator = THREE.LoaderSupport.Validator;
  82. function OBJLoaderVerify( elementToBindTo ) {
  83. this.renderer = null;
  84. this.canvas = elementToBindTo;
  85. this.aspectRatio = 1;
  86. this.recalcAspectRatio();
  87. this.scene = null;
  88. this.cameraDefaults = {
  89. posCamera: new THREE.Vector3( 0.0, 175.0, 500.0 ),
  90. posCameraTarget: new THREE.Vector3( 0, 0, 0 ),
  91. near: 0.1,
  92. far: 10000,
  93. fov: 45
  94. };
  95. this.camera = null;
  96. this.cameraTarget = this.cameraDefaults.posCameraTarget;
  97. this.controls = null;
  98. }
  99. OBJLoaderVerify.prototype.initGL = function () {
  100. this.renderer = new THREE.WebGLRenderer( {
  101. canvas: this.canvas,
  102. antialias: true,
  103. autoClear: true
  104. } );
  105. this.renderer.setClearColor( 0x050505 );
  106. this.scene = new THREE.Scene();
  107. this.camera = new THREE.PerspectiveCamera( this.cameraDefaults.fov, this.aspectRatio, this.cameraDefaults.near, this.cameraDefaults.far );
  108. this.resetCamera();
  109. this.controls = new THREE.TrackballControls( this.camera, this.renderer.domElement );
  110. var ambientLight = new THREE.AmbientLight( 0x404040 );
  111. var directionalLight1 = new THREE.DirectionalLight( 0xC0C090 );
  112. var directionalLight2 = new THREE.DirectionalLight( 0xC0C090 );
  113. directionalLight1.position.set( -100, -50, 100 );
  114. directionalLight2.position.set( 100, 50, -100 );
  115. this.scene.add( directionalLight1 );
  116. this.scene.add( directionalLight2 );
  117. this.scene.add( ambientLight );
  118. var helper = new THREE.GridHelper( 1200, 60, 0xFF4444, 0x404040 );
  119. this.scene.add( helper );
  120. };
  121. OBJLoaderVerify.prototype.initContent = function () {
  122. var modelName = 'verificationCubes';
  123. this._reportProgress( { detail: { text: 'Loading: ' + modelName } } );
  124. var scope = this;
  125. var objLoader2 = new THREE.OBJLoader2();
  126. var callbackOnLoad = function ( event ) {
  127. scope.scene.add( event.detail.loaderRootNode );
  128. console.log( 'Loading complete: ' + event.detail.modelName );
  129. scope._reportProgress( { detail: { text: '' } } );
  130. };
  131. var onLoadMtl = function ( materials, materialCreator ) {
  132. var objLoader = new THREE.OBJLoader();
  133. objLoader.setMaterials( materialCreator );
  134. objLoader.load( './verify.obj', function ( object ) {
  135. object.position.y = -100;
  136. scope.scene.add( object );
  137. } );
  138. objLoader2.setModelName( modelName );
  139. objLoader2.setMaterials( materials );
  140. objLoader2.setLogging( true, false );
  141. objLoader2.setUseOAsMesh( true );
  142. objLoader2.load( './verify.obj', callbackOnLoad, null, null, null, false );
  143. };
  144. objLoader2.loadMtl( './verify.mtl', null, onLoadMtl );
  145. };
  146. OBJLoaderVerify.prototype._reportProgress = function( event ) {
  147. var output = Validator.verifyInput( event.detail.text, '' );
  148. console.log( 'Progress: ' + output );
  149. document.getElementById( 'feedback' ).innerHTML = output;
  150. };
  151. OBJLoaderVerify.prototype.resizeDisplayGL = function () {
  152. this.controls.handleResize();
  153. this.recalcAspectRatio();
  154. this.renderer.setSize( this.canvas.offsetWidth, this.canvas.offsetHeight, false );
  155. this.updateCamera();
  156. };
  157. OBJLoaderVerify.prototype.recalcAspectRatio = function () {
  158. this.aspectRatio = ( this.canvas.offsetHeight === 0 ) ? 1 : this.canvas.offsetWidth / this.canvas.offsetHeight;
  159. };
  160. OBJLoaderVerify.prototype.resetCamera = function () {
  161. this.camera.position.copy( this.cameraDefaults.posCamera );
  162. this.cameraTarget.copy( this.cameraDefaults.posCameraTarget );
  163. this.updateCamera();
  164. };
  165. OBJLoaderVerify.prototype.updateCamera = function () {
  166. this.camera.aspect = this.aspectRatio;
  167. this.camera.lookAt( this.cameraTarget );
  168. this.camera.updateProjectionMatrix();
  169. };
  170. OBJLoaderVerify.prototype.render = function () {
  171. if ( ! this.renderer.autoClear ) this.renderer.clear();
  172. this.controls.update();
  173. this.renderer.render( this.scene, this.camera );
  174. };
  175. return OBJLoaderVerify;
  176. })();
  177. var app = new OBJLoaderVerify( document.getElementById( 'example' ) );
  178. var resizeWindow = function () {
  179. app.resizeDisplayGL();
  180. };
  181. var render = function () {
  182. requestAnimationFrame( render );
  183. app.render();
  184. };
  185. window.addEventListener( 'resize', resizeWindow, false );
  186. console.log( 'Starting initialisation phase...' );
  187. app.initGL();
  188. app.resizeDisplayGL();
  189. app.initContent();
  190. render();
  191. </script>
  192. </body>
  193. </html>