Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make importing stats.min.js optional in browser #206
- Removed stats.min.js in helloworld example
- Not serving test/lib/stats.min.js when running e2e test
- Remove <script src="/base/test/lib/stats.min.js"> from test/e2e/template.html
- Dynamically import stats-js
  • Loading branch information
BoTime committed Feb 11, 2019
1 parent 2123f49 commit fc4b107
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/helloworld/helloworld.html
Expand Up @@ -7,7 +7,7 @@

<script src="../lib/three.min.js"></script>
<script src="../lib/tween.min.js"></script>
<script src="../lib/stats.min.js"></script>
<!-- <script src="../lib/stats.min.js"></script> -->
<script src="../lib/tf.min.js"></script>
<script src="../lib/TrackballControls.js"></script>
<script src="../../dist/tensorspace.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.js
Expand Up @@ -30,7 +30,7 @@ module.exports = function(config) {

runInParent: false,

captureConsole: false
captureConsole: true
},

reporters: [ 'spec' ],
Expand All @@ -39,7 +39,7 @@ module.exports = function(config) {

{ pattern: 'test/lib/three.min.js', included: true },

{ pattern: 'test/lib/stats.min.js', included: true },
{ pattern: 'test/lib/stats.min.js', included: false, served: false },

{ pattern: 'test/lib/tween.min.js', included: true },

Expand Down
37 changes: 31 additions & 6 deletions src/scene/SceneInitializer.js
Expand Up @@ -4,7 +4,7 @@

import * as THREE from "three";
import * as TWEEN from "@tweenjs/tween.js";
import * as Stats from "stats-js";
// import * as Stats from "stats-js";
import * as TrackballControls from "three-trackballcontrols";
import { DefaultCameraPos, DefaultLayerDepth } from "../utils/Constant";

Expand Down Expand Up @@ -82,12 +82,37 @@ SceneInitializer.prototype = {
this.scene.background = new THREE.Color( this.backgroundColor );

if ( this.hasStats ) {
import('stats-js')
.then((module) => {

this.stats = new Stats();
this.stats.dom.style.position = "absolute";
this.stats.dom.style.zIndex = "1";
this.stats.showPanel( 0 );
this.container.appendChild( this.stats.dom );
this.stats = new module();
this.stats.dom.style.position = "absolute";
this.stats.dom.style.zIndex = "1";
this.stats.showPanel( 0 );
this.container.appendChild( this.stats.dom );

})
.catch(() => {

if ( typeof Stats !== 'undefined' ) {

this.stats = new Stats();
this.stats.dom.style.position = "absolute";
this.stats.dom.style.zIndex = "1";
this.stats.showPanel( 0 );
this.container.appendChild( this.stats.dom );

} else if ( typeof window === 'undefined' ) {

console.error('Please import stats-js');

} else {

console.error('Please include <script> tag');

}

});

}

Expand Down

0 comments on commit fc4b107

Please sign in to comment.