Skip to content

Commit

Permalink
updated to r101 core components and extensions
Browse files Browse the repository at this point in the history
    Scene: added dispose() and isScene
    bugfix
  • Loading branch information
Dmitrii Tikhomirov committed Feb 16, 2019
1 parent f9925a2 commit 60fba76
Show file tree
Hide file tree
Showing 13 changed files with 1,956 additions and 1,020 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/treblereel/gwt/three4g/scenes/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class Scene extends Object3D {
*/
public boolean autoUpdate;

/**
* Used to check whether this or derived classes are Scene. Default is true.
* <p>
* You should not change this, as it used internally for optimisation.
*/
public boolean isScene;

/**
* If not null, sets the background used when rendering the scene, and is always rendered first. Can be set to a Color which sets the clear color, a Texture covering the canvas, or a CubeTexture. Default is null.
*/
Expand All @@ -45,4 +52,9 @@ public Scene() {
*/
public native String toJSON();


/**
* Clears scene related data internally cached by WebGLRenderer.
*/
public native void dispose();
}
563 changes: 436 additions & 127 deletions core/src/main/resources/org/treblereel/gwt/three4g/resources/js/three.js

Large diffs are not rendered by default.

1,572 changes: 790 additions & 782 deletions core/src/main/resources/org/treblereel/gwt/three4g/resources/js/three.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class FirstPersonControls {


public double movementSpeed;

public double lookSpeed;

public FirstPersonControls(Camera camera) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
THREE.FirstPersonControls = function ( object, domElement ) {

this.object = object;
this.target = new THREE.Vector3( 0, 0, 0 );

this.domElement = ( domElement !== undefined ) ? domElement : document;

Expand Down Expand Up @@ -35,11 +34,6 @@ THREE.FirstPersonControls = function ( object, domElement ) {
this.mouseX = 0;
this.mouseY = 0;

this.lat = 0;
this.lon = 0;
this.phi = 0;
this.theta = 0;

this.moveForward = false;
this.moveBackward = false;
this.moveLeft = false;
Expand All @@ -50,6 +44,17 @@ THREE.FirstPersonControls = function ( object, domElement ) {
this.viewHalfX = 0;
this.viewHalfY = 0;

// private variables

var lat = 0;
var lon = 0;

var lookDirection = new THREE.Vector3();
var spherical = new THREE.Spherical();
var target = new THREE.Vector3();

//

if ( this.domElement !== document ) {

this.domElement.setAttribute( 'tabindex', - 1 );
Expand Down Expand Up @@ -184,74 +189,97 @@ THREE.FirstPersonControls = function ( object, domElement ) {

};

this.update = function ( delta ) {

if ( this.enabled === false ) return;

if ( this.heightSpeed ) {
this.lookAt = function ( x, y, z ) {

var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
var heightDelta = y - this.heightMin;
if ( x.isVector3 ) {

this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
target.copy( x );

} else {

this.autoSpeedFactor = 0.0;
target.set( x, y, z );

}

var actualMoveSpeed = delta * this.movementSpeed;
this.object.lookAt( target );

if ( this.moveForward || ( this.autoForward && ! this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
setOrientation( this );

if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
return this;

if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
};

var actualLookSpeed = delta * this.lookSpeed;
this.update = function () {

if ( ! this.activeLook ) {
var targetPosition = new THREE.Vector3();

actualLookSpeed = 0;
return function update( delta ) {

}
if ( this.enabled === false ) return;

var verticalLookRatio = 1;
if ( this.heightSpeed ) {

if ( this.constrainVertical ) {
var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
var heightDelta = y - this.heightMin;

verticalLookRatio = Math.PI / ( this.verticalMax - this.verticalMin );
this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );

}
} else {

this.lon += this.mouseX * actualLookSpeed;
if ( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
this.autoSpeedFactor = 0.0;

this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
this.phi = THREE.Math.degToRad( 90 - this.lat );
}

this.theta = THREE.Math.degToRad( this.lon );
var actualMoveSpeed = delta * this.movementSpeed;

if ( this.constrainVertical ) {
if ( this.moveForward || ( this.autoForward && ! this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );

this.phi = THREE.Math.mapLinear( this.phi, 0, Math.PI, this.verticalMin, this.verticalMax );
if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
if ( this.moveRight ) this.object.translateX( actualMoveSpeed );

}
if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );

var targetPosition = this.target,
position = this.object.position;
var actualLookSpeed = delta * this.lookSpeed;

targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
targetPosition.y = position.y + 100 * Math.cos( this.phi );
targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
if ( ! this.activeLook ) {

this.object.lookAt( targetPosition );
actualLookSpeed = 0;

};
}

var verticalLookRatio = 1;

if ( this.constrainVertical ) {

verticalLookRatio = Math.PI / ( this.verticalMax - this.verticalMin );

}

lon -= this.mouseX * actualLookSpeed;
if ( this.lookVertical ) lat -= this.mouseY * actualLookSpeed * verticalLookRatio;

lat = Math.max( - 85, Math.min( 85, lat ) );

var phi = THREE.Math.degToRad( 90 - lat );
var theta = THREE.Math.degToRad( lon );

if ( this.constrainVertical ) {

phi = THREE.Math.mapLinear( phi, 0, Math.PI, this.verticalMin, this.verticalMax );

}

var position = this.object.position;

targetPosition.setFromSphericalCoords( 1, phi, theta ).add( position );

this.object.lookAt( targetPosition );

};

}();

function contextmenu( event ) {

Expand Down Expand Up @@ -295,6 +323,20 @@ THREE.FirstPersonControls = function ( object, domElement ) {

}

function setOrientation( controls ) {

var quaternion = controls.object.quaternion;

lookDirection.set( 0, 0, - 1 ).applyQuaternion( quaternion );
spherical.setFromVector3( lookDirection );

lat = 90 - THREE.Math.radToDeg( spherical.phi );
lon = THREE.Math.radToDeg( spherical.theta );

}

this.handleResize();

setOrientation( this );

};
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ THREE.OrbitControls = function ( object, domElement ) {

//console.log( 'handleKeyDown' );

// prevent the browser from scrolling on cursor up/down

event.preventDefault();

switch ( event.keyCode ) {

case scope.keys.UP:
Expand Down Expand Up @@ -673,8 +677,15 @@ THREE.OrbitControls = function ( object, domElement ) {

if ( scope.enabled === false ) return;

// Prevent the browser from scrolling.

event.preventDefault();

// Manually set the focus since calling preventDefault above
// prevents the browser from setting it automatically.

scope.domElement.focus ? scope.domElement.focus() : window.focus();

switch ( event.button ) {

case scope.mouseButtons.LEFT:
Expand Down
Loading

0 comments on commit 60fba76

Please sign in to comment.