Skip to content

Commit

Permalink
fixes to ogf r11
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-armour committed Oct 4, 2016
1 parent ca1c9d6 commit aab0510
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 83 deletions.
2 changes: 1 addition & 1 deletion elevations-core3/d-ter-terrain/terrain-r1.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
// change to https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

// if ( MAP.initMapGeometry ) { MAP.initMapGeometry(); }
if ( MAP.drawMap ) { MAP.drawMap(); }
if ( MAP.drawMap ) { console.log( 'terrain', 456 );MAP.drawMap(); }

// change to KML

Expand Down
14 changes: 10 additions & 4 deletions elevations-core3/f-map-map/map-r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ console.timeEnd( 'timer0' );
MAP.material = new THREE.MeshBasicMaterial( { color: 0xffffff, map: texture, side: 2 } );

MAP.drawMap()

console.log( 'count', count );
}

};
Expand Down Expand Up @@ -158,17 +158,23 @@ console.timeEnd( 'timer0' );

THR.scene.add( MAP.groundPlane );

if ( THR.updateCamera === true ) { THR.viewObject( MAP.mesh ); }
if ( THR.updateCamera === true && !CAS.center ) { THR.viewObject( MAP.mesh ); }

if ( TERchkFog.checked === true ) { THR.toggleFog( true ) }

if ( CAS.center ) {

CAS.center = MAP.mesh.position.clone();
// CAS.center = MAP.mesh.position.clone();
CAS.cameraTrack();

} else {

console.log( 'no cas', 23 );

}

if ( TERchkFog.checked === true ) { THR.toggleFog( true ) }


// could be called by HTML file ?
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Expand Down
4 changes: 2 additions & 2 deletions elevations-core3/h-kml-kml/kml-r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@

if ( !place.points ) { return; }

TERinpVertical.value = place.verticalScale;
// TERinpVertical.value = place.verticalScale;

TER.TERinpVerticalOnChange();
// TER.TERinpVerticalOnChange();

pp = place.points;
points = [];
Expand Down
338 changes: 338 additions & 0 deletions elevations-core3/i-cas-camera-action-select/camera-action-select-r3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@

var CAS = CAS || {};

CAS.marker = 'Marker';

CAS.offsetStart = 0;
CAS.offsetEnd = 1;

// if ( SELselFiles.selectedIndex === 1 ) { index = CAS.offsetStart = 0.32; CAS.offsetEnd = 0.39; }
// if ( SELselFiles.selectedIndex === 3 ) { index = CAS.offsetStart = 0.25; CAS.offsetEnd = 0.76; }

CAS.actor = new THREE.Object3D();
CAS.cameraPoints = 25;
CAS.zoomScale = 1;
CAS.actorScale = 1;

var point = 0;
var index = 0;
var delta = 1;

var motion = false;
var follow = false;

var origin = v( 0, 0, 0 );
CAS.center = origin;
var target = origin;

CAS.cameraOffsetChase = v( 50 * CAS.zoomScale, 50 * CAS.zoomScale, 50 * CAS.zoomScale );
CAS.cameraOffsetInside = v( 0 * CAS.zoomScale, 20 * CAS.zoomScale, 0 * CAS.zoomScale );
CAS.cameraOffsetTrack = v( -80 * CAS.zoomScale, 10 * CAS.zoomScale, 10 * CAS.zoomScale );
CAS.cameraOffsetWorld = v( 80 * CAS.zoomScale, 80 * CAS.zoomScale, 80 * CAS.zoomScale );


// prevent default animate
// function animate() {}

CAS.getMenuDetailsCameraActions = function() {

var menuDetailsCameraActions =

'<details id=detailsMarkerActions open>' +

'<summary id=summaryCameraActions ><h3>' + CAS.marker + ' settings</h3></summary>' +

// slide to move actor to desired position

'<p><input type=checkbox id=CASchkMotion onclick=motion=!motion checked >' + CAS.marker + ' <i>en route</i></p>' +

'<p>' +
CAS.marker + ' speed: <output id=CHKoutSpeed >' + CAS.cameraPoints + '</output><br>' +
'<input type=range id=CASinpSpeed min=0 max=100 step=1 value=' + CAS.cameraPoints +
' oninput=CHKoutSpeed.value=CAS.cameraPoints=this.valueAsNumber title="0 to 10: OK" >' +
'</p>' +

'<p>' +
CAS.marker + ' location: <output id=CHKoutLocation >' + index + '</output><br>' +
'<input type=range id=CASinpLocation min=0 max=100 value=' + ( 100 * index ) +
' oninput=CHKoutLocation.value=index=this.valueAsNumber/100 title="0 to 10: OK" >' +
'</p>' +


'</details>' +

'<details id=detailsCameraActions open>' +

'<summary id=summaryCameraActions ><h3>Camera settings</h3></summary>' +

'<p><button onclick=CAS.cameraChase(); >camera chase</button><br>' +
'<small>Camera fixed a distance from actor, follows actor position and rotation</small>' +
'</p>' +

'<p><button onclick=CAS.cameraInside(); >camera inside</button><br>' +
'<small>Camera fixed inside actor, follows a point just ahead of the actor</small>' +
'</p>' +

'<p><button onclick=CAS.cameraTrack(); >camera track</button><br>' +
'<small>Camera fixed at position on ground, follows actor</small>' +
'</p>' +

'<p><button onclick=CAS.cameraWorld(); >camera world</button><br>' +
'<small>Camera fixed at position in the air, follows nothing</small></p>' + b +

'</details>';


return menuDetailsCameraActions;

}




// objects to play with - just in case


CAS.getActorTorusKnot = function() {

var geometry, material, mesh;

CAS.actor = new THREE.Object3D();

geometry = new THREE.TorusKnotGeometry( 5 * CAS.actorScale, 1 * CAS.actorScale, 80 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );

CAS.actor.add( mesh );
CAS.actor.mesh = mesh;

scene.add( CAS.actor );

}


CAS.getActorCylinder = function() {

var geometry, material, mesh;

CAS.actor = new THREE.Object3D();

geometry = new THREE.CylinderGeometry( 2 * CAS.actorScale, 5 * CAS.actorScale, 1 * CAS.actorScale, 20 );
// geometry.applyMatrix( new THREE.Matrix4().makeScale( 1, 0.1, 1 ) );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );

CAS.actor.add( mesh );

CAS.actor.mesh = mesh;

geometry = new THREE.BoxGeometry( 1 * CAS.actorScale, 2 * CAS.actorScale, 3 * CAS.actorScale );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0 * CAS.actorScale, 2 * CAS.actorScale, 3 * CAS.actorScale ) );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );

CAS.actor.add( mesh );

THR.scene.add( CAS.actor );

}


CAS.getActorBitmap = function( bitmap ) {

var loader, geometry, material, mesh;

CAS.actor = new THREE.Object3D();

loader = new THREE.TextureLoader();
loader.crossOrigin = '';
texture = loader.load( bitmap || '../bitmaps/j.gif' );

texture.minFilter = texture.magFilter = THREE.NearestFilter;
// texture.needsUpdate = true;
// geometry = new THREE.BoxGeometry( 1 * CAS.actorScale, 3 * CAS.actorScale, 1 * CAS.actorScale );
geometry = new THREE.PlaneBufferGeometry( 3 * CAS.actorScale, 3 * CAS.actorScale );
geometry.applyMatrix( new THREE.Matrix4().makeRotationY( -pi05 ) );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0 * CAS.actorScale, 2 * CAS.actorScale, 0 * CAS.actorScale ) );

material = new THREE.MeshBasicMaterial( { map: texture, side: THREE.DoubleSide, transparent: true } );
// material = new THREE.MeshNormalMaterial();

mesh = new THREE.Mesh( geometry, material );

CAS.actor.add( mesh );
CAS.actor.mesh = mesh;

THR.scene.add( CAS.actor );

}


CAS.getActorJSON = function( url ) {

var loader, geometry, material, mesh;

CAS.actor = new THREE.Object3D();
CAS.actor.file = url || 'https://fgx.github.io/fgx-aircraft/data/c172p/c172p.js';

loader = new THREE.JSONLoader();
loader.crossOrigin = 'anonymous';
loader.load( CAS.actor.file, function ( geometry ) {

// geometry.applyMatrix( new THREE.Matrix4().makeRotationX( pi05 ) );
geometry.applyMatrix( new THREE.Matrix4().makeRotationY( -pi05 ) );
geometry.applyMatrix( new THREE.Matrix4().makeScale( 0.001, 0.001, 0.001 ) );
material = new THREE.MeshNormalMaterial( { side: 2 } );
mesh = new THREE.Mesh( geometry, material );

CAS.actor.add( mesh );
CAS.actor.mesh = mesh;

} );

THR.scene.add( CAS.actor );

}


CAS.getNicePath = function( scale ) {

var segments = 20;
var points = 500;
var vertices, curve;
var geometry, material, line;

scale = scale || 30;
vertices = [];

for ( var i = 0; i < 2 * segments * Math.PI; i++ ) {

vertices.push( v( scale * sin( i * 7 / segments ), scale * cos( i * 3 / segments ), scale * sin( i * 2 / segments ) ) );

}

CAS.curve = new THREE.CatmullRomCurve3( vertices );
CAS.curve.closed = true;

geometry = new THREE.Geometry();
geometry.vertices = CAS.curve.getPoints( points );

material = new THREE.LineBasicMaterial( { color: 0xff0000 } );

line = new THREE.Line( geometry, material );

return line;

}


CAS.cameraChase = function() {

THR.controls.autoRotate = false;
CHKoutSpeed.value = CAS.cameraPoints = 20;
// CAS.actor.add( ttt );
CAS.actor.add( THR.camera );
THR.camera.position.copy( CAS.cameraOffsetChase );
target = origin.clone();
THR.controls.target.copy( target.clone() );
follow = true;

}


CAS.cameraInside = function() {

THR.controls.autoRotate = false;
CHKoutSpeed.value = CAS.cameraPoints = 10;
CAS.actor.mesh.add( THR.camera );
THR.camera.position.copy( origin.clone().add( CAS.cameraOffsetInside ) );
target = origin.clone();
THR.controls.target.copy( target );
follow = false;

}


CAS.cameraTrack = function() {

THR.controls.autoRotate = false;
CHKoutSpeed.value = CAS.cameraPoints = 25;
THR.scene.add( THR.camera );

if ( MAP.mesh ) {

THR.viewObject( MAP.mesh );

} else {

THR.camera.position.copy( origin.clone().add( CAS.cameraOffsetTrack ) );

}

THR.controls.target.copy( CAS.center.clone() );
target = CAS.actor.position;
THR.controls.target.copy( target );
follow = true;

}


CAS.cameraWorld = function() {

THR.controls.autoRotate = false;
CHKoutSpeed.value = CAS.cameraPoints = 25;
THR.scene.add( THR.camera );

if ( MAP.mesh !== undefined ) {

THR.viewObject( MAP.mesh );

} else {

THR.camera.position.copy( CAS.cameraOffsetWorld );

}

target = CAS.center.clone();
THR.controls.target.copy( target );
follow = false;

}



CAS.animatePlusLookAt = function() {

var point, dd;

THR.stats.update();

THR.controls.update();

THR.renderer.render( THR.scene, THR.camera );

requestAnimationFrame( CAS.animatePlusLookAt );

if ( !motion ) { return; }

dd = CAS.cameraPoints / 250000;

index += dd;

CHKoutLocation.value = (100 * index ).toFixed( 1 ) + '%';

CASinpLocation.value = 100 * index;

index = index <= CAS.offsetEnd ? index : dd + CAS.offsetStart;

CAS.actor.position.copy( CAS.curve.getPoint( index - dd ) );

CAS.actor.lookAt( CAS.curve.getPoint( index ) );

if ( follow === true ) {

THR.controls.target.copy( target );

}

}
Loading

0 comments on commit aab0510

Please sign in to comment.