|
@@ -1,7 +1,7 @@
|
|
<!DOCTYPE html>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<html lang="en">
|
|
<head>
|
|
<head>
|
|
- <title>three.js webgl - geometry - shapes</title>
|
|
|
|
|
|
+ <title>three.js webgl - geometry - spline extrusion</title>
|
|
<meta charset="utf-8">
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
<style>
|
|
@@ -16,6 +16,7 @@
|
|
<body>
|
|
<body>
|
|
|
|
|
|
<script src="../build/three.js"></script>
|
|
<script src="../build/three.js"></script>
|
|
|
|
+ <script src="js/controls/OrbitControls.js"></script>
|
|
|
|
|
|
<!-- where curves formulas are defined -->
|
|
<!-- where curves formulas are defined -->
|
|
<script src="js/CurveExtras.js"></script>
|
|
<script src="js/CurveExtras.js"></script>
|
|
@@ -43,16 +44,30 @@
|
|
var normal = new THREE.Vector3();
|
|
var normal = new THREE.Vector3();
|
|
|
|
|
|
|
|
|
|
- var pipeSpline = new THREE.CatmullRomCurve3([
|
|
|
|
- new THREE.Vector3(0, 10, -10), new THREE.Vector3(10, 0, -10), new THREE.Vector3(20, 0, 0), new THREE.Vector3(30, 0, 10), new THREE.Vector3(30, 0, 20), new THREE.Vector3(20, 0, 30), new THREE.Vector3(10, 0, 30), new THREE.Vector3(0, 0, 30), new THREE.Vector3(-10, 10, 30), new THREE.Vector3(-10, 20, 30), new THREE.Vector3(0, 30, 30), new THREE.Vector3(10, 30, 30), new THREE.Vector3(20, 30, 15), new THREE.Vector3(10, 30, 10), new THREE.Vector3(0, 30, 10), new THREE.Vector3(-10, 20, 10), new THREE.Vector3(-10, 10, 10), new THREE.Vector3(0, 0, 10), new THREE.Vector3(10, -10, 10), new THREE.Vector3(20, -15, 10), new THREE.Vector3(30, -15, 10), new THREE.Vector3(40, -15, 10), new THREE.Vector3(50, -15, 10), new THREE.Vector3(60, 0, 10), new THREE.Vector3(70, 0, 0), new THREE.Vector3(80, 0, 0), new THREE.Vector3(90, 0, 0), new THREE.Vector3(100, 0, 0)]);
|
|
|
|
-
|
|
|
|
- var sampleClosedSpline = new THREE.CatmullRomCurve3([
|
|
|
|
- new THREE.Vector3(0, -40, -40),
|
|
|
|
- new THREE.Vector3(0, 40, -40),
|
|
|
|
- new THREE.Vector3(0, 140, -40),
|
|
|
|
- new THREE.Vector3(0, 40, 40),
|
|
|
|
- new THREE.Vector3(0, -40, 40),
|
|
|
|
- ]);
|
|
|
|
|
|
+ var pipeSpline = new THREE.CatmullRomCurve3( [
|
|
|
|
+ new THREE.Vector3( 0, 10, -10 ), new THREE.Vector3( 10, 0, -10 ),
|
|
|
|
+ new THREE.Vector3( 20, 0, 0 ), new THREE.Vector3( 30, 0, 10 ),
|
|
|
|
+ new THREE.Vector3( 30, 0, 20 ), new THREE.Vector3( 20, 0, 30 ),
|
|
|
|
+ new THREE.Vector3( 10, 0, 30 ), new THREE.Vector3( 0, 0, 30 ),
|
|
|
|
+ new THREE.Vector3( -10, 10, 30 ), new THREE.Vector3( -10, 20, 30 ),
|
|
|
|
+ new THREE.Vector3( 0, 30, 30 ), new THREE.Vector3( 10, 30, 30 ),
|
|
|
|
+ new THREE.Vector3( 20, 30, 15 ), new THREE.Vector3( 10, 30, 10 ),
|
|
|
|
+ new THREE.Vector3( 0, 30, 10 ), new THREE.Vector3( -10, 20, 10 ),
|
|
|
|
+ new THREE.Vector3( -10, 10, 10 ), new THREE.Vector3( 0, 0, 10 ),
|
|
|
|
+ new THREE.Vector3( 10, -10, 10 ), new THREE.Vector3( 20, -15, 10 ),
|
|
|
|
+ new THREE.Vector3( 30, -15, 10 ), new THREE.Vector3( 40, -15, 10 ),
|
|
|
|
+ new THREE.Vector3( 50, -15, 10 ), new THREE.Vector3( 60, 0, 10 ),
|
|
|
|
+ new THREE.Vector3( 70, 0, 0 ), new THREE.Vector3( 80, 0, 0 ),
|
|
|
|
+ new THREE.Vector3( 90, 0, 0 ), new THREE.Vector3( 100, 0, 0 )
|
|
|
|
+ ] );
|
|
|
|
+
|
|
|
|
+ var sampleClosedSpline = new THREE.CatmullRomCurve3( [
|
|
|
|
+ new THREE.Vector3( 0, -40, -40 ),
|
|
|
|
+ new THREE.Vector3( 0, 40, -40 ),
|
|
|
|
+ new THREE.Vector3( 0, 140, -40 ),
|
|
|
|
+ new THREE.Vector3( 0, 40, 40 ),
|
|
|
|
+ new THREE.Vector3( 0, -40, 40 ),
|
|
|
|
+ ] );
|
|
|
|
|
|
sampleClosedSpline.type = 'catmullrom';
|
|
sampleClosedSpline.type = 'catmullrom';
|
|
sampleClosedSpline.closed = true;
|
|
sampleClosedSpline.closed = true;
|
|
@@ -60,14 +75,14 @@
|
|
// Keep a dictionary of Curve instances
|
|
// Keep a dictionary of Curve instances
|
|
var splines = {
|
|
var splines = {
|
|
GrannyKnot: new THREE.Curves.GrannyKnot(),
|
|
GrannyKnot: new THREE.Curves.GrannyKnot(),
|
|
- HeartCurve: new THREE.Curves.HeartCurve(3.5),
|
|
|
|
- VivianiCurve: new THREE.Curves.VivianiCurve(70),
|
|
|
|
|
|
+ HeartCurve: new THREE.Curves.HeartCurve( 3.5 ),
|
|
|
|
+ VivianiCurve: new THREE.Curves.VivianiCurve( 70 ),
|
|
KnotCurve: new THREE.Curves.KnotCurve(),
|
|
KnotCurve: new THREE.Curves.KnotCurve(),
|
|
HelixCurve: new THREE.Curves.HelixCurve(),
|
|
HelixCurve: new THREE.Curves.HelixCurve(),
|
|
TrefoilKnot: new THREE.Curves.TrefoilKnot(),
|
|
TrefoilKnot: new THREE.Curves.TrefoilKnot(),
|
|
- TorusKnot: new THREE.Curves.TorusKnot(20),
|
|
|
|
- CinquefoilKnot: new THREE.Curves.CinquefoilKnot(20),
|
|
|
|
- TrefoilPolynomialKnot: new THREE.Curves.TrefoilPolynomialKnot(14),
|
|
|
|
|
|
+ TorusKnot: new THREE.Curves.TorusKnot( 20 ),
|
|
|
|
+ CinquefoilKnot: new THREE.Curves.CinquefoilKnot( 20 ),
|
|
|
|
+ TrefoilPolynomialKnot: new THREE.Curves.TrefoilPolynomialKnot( 14 ),
|
|
FigureEightPolynomialKnot: new THREE.Curves.FigureEightPolynomialKnot(),
|
|
FigureEightPolynomialKnot: new THREE.Curves.FigureEightPolynomialKnot(),
|
|
DecoratedTorusKnot4a: new THREE.Curves.DecoratedTorusKnot4a(),
|
|
DecoratedTorusKnot4a: new THREE.Curves.DecoratedTorusKnot4a(),
|
|
DecoratedTorusKnot4b: new THREE.Curves.DecoratedTorusKnot4b(),
|
|
DecoratedTorusKnot4b: new THREE.Curves.DecoratedTorusKnot4b(),
|
|
@@ -77,17 +92,16 @@
|
|
SampleClosedSpline: sampleClosedSpline
|
|
SampleClosedSpline: sampleClosedSpline
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
extrudePath = new THREE.Curves.TrefoilKnot();
|
|
extrudePath = new THREE.Curves.TrefoilKnot();
|
|
|
|
|
|
var dropdown = '<select id="dropdown" onchange="addTube(this.value)">';
|
|
var dropdown = '<select id="dropdown" onchange="addTube(this.value)">';
|
|
|
|
|
|
var s;
|
|
var s;
|
|
for ( s in splines ) {
|
|
for ( s in splines ) {
|
|
|
|
+
|
|
dropdown += '<option value="' + s + '"';
|
|
dropdown += '<option value="' + s + '"';
|
|
dropdown += '>' + s + '</option>';
|
|
dropdown += '>' + s + '</option>';
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
dropdown += '</select>';
|
|
dropdown += '</select>';
|
|
@@ -101,27 +115,27 @@
|
|
|
|
|
|
function addTube() {
|
|
function addTube() {
|
|
|
|
|
|
- var value = document.getElementById('dropdown').value;
|
|
|
|
|
|
+ var value = document.getElementById( 'dropdown' ).value;
|
|
|
|
|
|
- var segments = parseInt(document.getElementById('segments').value);
|
|
|
|
- closed2 = document.getElementById('closed').checked;
|
|
|
|
|
|
+ var segments = parseInt( document.getElementById( 'segments' ).value );
|
|
|
|
+ closed2 = document.getElementById( 'closed' ).checked;
|
|
|
|
|
|
- var radiusSegments = parseInt(document.getElementById('radiusSegments').value);
|
|
|
|
|
|
+ var radiusSegments = parseInt( document.getElementById( 'radiusSegments' ).value );
|
|
|
|
|
|
- if (tubeMesh) parent.remove(tubeMesh);
|
|
|
|
|
|
+ if ( tubeMesh !== undefined ) parent.remove( tubeMesh );
|
|
|
|
|
|
- extrudePath = splines[value];
|
|
|
|
|
|
+ extrudePath = splines[ value ];
|
|
|
|
|
|
- tube = new THREE.TubeGeometry(extrudePath, segments, 2, radiusSegments, closed2);
|
|
|
|
|
|
+ tube = new THREE.TubeBufferGeometry( extrudePath, segments, 2, radiusSegments, closed2 );
|
|
|
|
|
|
- addGeometry(tube, 0xff00ff);
|
|
|
|
|
|
+ addGeometry( tube, 0xff00ff );
|
|
setScale();
|
|
setScale();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function setScale() {
|
|
function setScale() {
|
|
|
|
|
|
- scale = parseInt( document.getElementById('scale').value );
|
|
|
|
|
|
+ scale = parseInt( document.getElementById( 'scale' ).value );
|
|
tubeMesh.scale.set( scale, scale, scale );
|
|
tubeMesh.scale.set( scale, scale, scale );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -132,15 +146,15 @@
|
|
// 3d shape
|
|
// 3d shape
|
|
|
|
|
|
tubeMesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [
|
|
tubeMesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [
|
|
- new THREE.MeshLambertMaterial({
|
|
|
|
|
|
+ new THREE.MeshLambertMaterial( {
|
|
color: color
|
|
color: color
|
|
- }),
|
|
|
|
- new THREE.MeshBasicMaterial({
|
|
|
|
|
|
+ } ),
|
|
|
|
+ new THREE.MeshBasicMaterial( {
|
|
color: 0x000000,
|
|
color: 0x000000,
|
|
opacity: 0.3,
|
|
opacity: 0.3,
|
|
wireframe: true,
|
|
wireframe: true,
|
|
transparent: true
|
|
transparent: true
|
|
- })]);
|
|
|
|
|
|
+ } ) ] );
|
|
|
|
|
|
parent.add( tubeMesh );
|
|
parent.add( tubeMesh );
|
|
|
|
|
|
@@ -148,31 +162,31 @@
|
|
|
|
|
|
function animateCamera( toggle ) {
|
|
function animateCamera( toggle ) {
|
|
|
|
|
|
- if ( toggle ) {
|
|
|
|
|
|
+ if ( toggle === true ) {
|
|
|
|
|
|
animation = animation === false;
|
|
animation = animation === false;
|
|
- document.getElementById('animation').value = 'Camera Spline Animation View: ' + (animation? 'ON': 'OFF');
|
|
|
|
|
|
+ document.getElementById( 'animation' ).value = 'Camera Spline Animation View: ' + ( animation ? 'ON' : 'OFF' );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- lookAhead = document.getElementById('lookAhead').checked;
|
|
|
|
|
|
+ lookAhead = document.getElementById( 'lookAhead' ).checked;
|
|
|
|
|
|
- showCameraHelper = document.getElementById('cameraHelper').checked;
|
|
|
|
|
|
+ showCameraHelper = document.getElementById( 'cameraHelper' ).checked;
|
|
|
|
|
|
cameraHelper.visible = showCameraHelper;
|
|
cameraHelper.visible = showCameraHelper;
|
|
cameraEye.visible = showCameraHelper;
|
|
cameraEye.visible = showCameraHelper;
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
init();
|
|
init();
|
|
animate();
|
|
animate();
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
|
|
|
- container = document.createElement('div');
|
|
|
|
- document.body.appendChild(container);
|
|
|
|
|
|
+ container = document.createElement( 'div' );
|
|
|
|
+ document.body.appendChild( container );
|
|
|
|
|
|
- var info = document.createElement('div');
|
|
|
|
|
|
+ var info = document.createElement( 'div' );
|
|
info.style.position = 'absolute';
|
|
info.style.position = 'absolute';
|
|
info.style.top = '10px';
|
|
info.style.top = '10px';
|
|
info.style.width = '100%';
|
|
info.style.width = '100%';
|
|
@@ -188,12 +202,12 @@
|
|
|
|
|
|
info.innerHTML += '<br/><br/><input id="animation" type="button" onclick="animateCamera(true)" value="Camera Spline Animation View: OFF"/><br/> Look Ahead <input id="lookAhead" type="checkbox" onchange="animateCamera()" /> Camera Helper <input id="cameraHelper" type="checkbox" onchange="animateCamera()" />';
|
|
info.innerHTML += '<br/><br/><input id="animation" type="button" onclick="animateCamera(true)" value="Camera Spline Animation View: OFF"/><br/> Look Ahead <input id="lookAhead" type="checkbox" onchange="animateCamera()" /> Camera Helper <input id="cameraHelper" type="checkbox" onchange="animateCamera()" />';
|
|
|
|
|
|
- container.appendChild(info);
|
|
|
|
|
|
+ container.appendChild( info );
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
- camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.01, 1000);
|
|
|
|
- camera.position.set(0, 50, 500);
|
|
|
|
|
|
+ camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 10000 );
|
|
|
|
+ camera.position.set( 0, 50, 500 );
|
|
|
|
|
|
scene = new THREE.Scene();
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
@@ -202,7 +216,6 @@
|
|
scene.add( light );
|
|
scene.add( light );
|
|
|
|
|
|
parent = new THREE.Object3D();
|
|
parent = new THREE.Object3D();
|
|
- parent.position.y = 100;
|
|
|
|
scene.add( parent );
|
|
scene.add( parent );
|
|
|
|
|
|
splineCamera = new THREE.PerspectiveCamera( 84, window.innerWidth / window.innerHeight, 0.01, 1000 );
|
|
splineCamera = new THREE.PerspectiveCamera( 84, window.innerWidth / window.innerHeight, 0.01, 1000 );
|
|
@@ -213,7 +226,7 @@
|
|
|
|
|
|
addTube();
|
|
addTube();
|
|
|
|
|
|
- // Debug point
|
|
|
|
|
|
+ // debug camera
|
|
|
|
|
|
cameraEye = new THREE.Mesh( new THREE.SphereGeometry( 5 ), new THREE.MeshBasicMaterial( { color: 0xdddddd } ) );
|
|
cameraEye = new THREE.Mesh( new THREE.SphereGeometry( 5 ), new THREE.MeshBasicMaterial( { color: 0xdddddd } ) );
|
|
parent.add( cameraEye );
|
|
parent.add( cameraEye );
|
|
@@ -232,9 +245,9 @@
|
|
stats = new Stats();
|
|
stats = new Stats();
|
|
container.appendChild( stats.dom );
|
|
container.appendChild( stats.dom );
|
|
|
|
|
|
- renderer.domElement.addEventListener( 'mousedown', onDocumentMouseDown, false );
|
|
|
|
- renderer.domElement.addEventListener( 'touchstart', onDocumentTouchStart, false );
|
|
|
|
- renderer.domElement.addEventListener( 'touchmove', onDocumentTouchMove, false );
|
|
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ controls = new THREE.OrbitControls( camera, renderer.domElement );
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
@@ -256,71 +269,6 @@
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
- function onDocumentMouseDown(event) {
|
|
|
|
-
|
|
|
|
- event.preventDefault();
|
|
|
|
-
|
|
|
|
- renderer.domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
- renderer.domElement.addEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
|
|
- renderer.domElement.addEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
|
|
-
|
|
|
|
- mouseXOnMouseDown = event.clientX - windowHalfX;
|
|
|
|
- targetRotationOnMouseDown = targetRotation;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function onDocumentMouseMove(event) {
|
|
|
|
-
|
|
|
|
- mouseX = event.clientX - windowHalfX;
|
|
|
|
-
|
|
|
|
- targetRotation = targetRotationOnMouseDown + (mouseX - mouseXOnMouseDown) * 0.02;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function onDocumentMouseUp(event) {
|
|
|
|
-
|
|
|
|
- renderer.domElement.removeEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
- renderer.domElement.removeEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
|
|
- renderer.domElement.removeEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function onDocumentMouseOut(event) {
|
|
|
|
-
|
|
|
|
- renderer.domElement.removeEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
- renderer.domElement.removeEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
|
|
- renderer.domElement.removeEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function onDocumentTouchStart(event) {
|
|
|
|
-
|
|
|
|
- if (event.touches.length == 1) {
|
|
|
|
-
|
|
|
|
- event.preventDefault();
|
|
|
|
-
|
|
|
|
- mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
|
|
|
|
- targetRotationOnMouseDown = targetRotation;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function onDocumentTouchMove(event) {
|
|
|
|
-
|
|
|
|
- if (event.touches.length == 1) {
|
|
|
|
-
|
|
|
|
- event.preventDefault();
|
|
|
|
-
|
|
|
|
- mouseX = event.touches[ 0 ].pageX - windowHalfX;
|
|
|
|
- targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //
|
|
|
|
-
|
|
|
|
function animate() {
|
|
function animate() {
|
|
|
|
|
|
requestAnimationFrame( animate );
|
|
requestAnimationFrame( animate );
|
|
@@ -362,23 +310,16 @@
|
|
splineCamera.position.copy( pos );
|
|
splineCamera.position.copy( pos );
|
|
cameraEye.position.copy( pos );
|
|
cameraEye.position.copy( pos );
|
|
|
|
|
|
-
|
|
|
|
- // Camera Orientation 1 - default look at
|
|
|
|
- // splineCamera.lookAt( lookAt );
|
|
|
|
-
|
|
|
|
// Using arclength for stablization in look ahead.
|
|
// Using arclength for stablization in look ahead.
|
|
var lookAt = tube.parameters.path.getPointAt( ( t + 30 / tube.parameters.path.getLength() ) % 1 ).multiplyScalar( scale );
|
|
var lookAt = tube.parameters.path.getPointAt( ( t + 30 / tube.parameters.path.getLength() ) % 1 ).multiplyScalar( scale );
|
|
|
|
|
|
// Camera Orientation 2 - up orientation via normal
|
|
// Camera Orientation 2 - up orientation via normal
|
|
- if (!lookAhead)
|
|
|
|
- lookAt.copy( pos ).add( dir );
|
|
|
|
|
|
+ if ( !lookAhead ) lookAt.copy( pos ).add( dir );
|
|
splineCamera.matrix.lookAt(splineCamera.position, lookAt, normal);
|
|
splineCamera.matrix.lookAt(splineCamera.position, lookAt, normal);
|
|
splineCamera.rotation.setFromRotationMatrix( splineCamera.matrix, splineCamera.rotation.order );
|
|
splineCamera.rotation.setFromRotationMatrix( splineCamera.matrix, splineCamera.rotation.order );
|
|
|
|
|
|
cameraHelper.update();
|
|
cameraHelper.update();
|
|
|
|
|
|
- parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
|
|
|
|
-
|
|
|
|
renderer.render( scene, animation === true ? splineCamera : camera );
|
|
renderer.render( scene, animation === true ? splineCamera : camera );
|
|
|
|
|
|
}
|
|
}
|