-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikos M
committed
Jul 18, 2016
1 parent
6f565f4
commit c866d61
Showing
12 changed files
with
505 additions
and
50 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Bloat demo and OSG.js</title> | ||
<link rel="stylesheet" type="text/css" href="./base.css"> | ||
|
||
<!-- Javascript --> | ||
<script type="text/javascript" src="./core.js"></script> | ||
<script type="text/javascript" src="./bluebird-2.10.2.js"></script> | ||
<script type="text/javascript" src="./hammer-2.0.4.js"></script> | ||
<!--<script type="text/javascript" src="./leap.js"></script>--> | ||
<script type="text/javascript" src="./OSG.js"></script> | ||
<script type="text/javascript" src="../../build/mod3.bundle.js"></script> | ||
<script type="text/javascript" src="../../src/plugins/OSG/OSG.js"></script> | ||
</head> | ||
|
||
|
||
|
||
<body class="osgjs-theme-dark"> | ||
|
||
<div id="ViewContainer" class="osgjs-fullpage"> | ||
<!-- very important change the size of the parent element instead--> | ||
<canvas id="View" style="height:100%;width:100%;" oncontextmenu="return false;"></canvas> | ||
</div> | ||
|
||
</body> | ||
|
||
<script type="text/javascript"> | ||
!function( window ){ | ||
var OSG = window.OSG, osg = OSG.osg, osgAnimation = OSG.osgAnimation, osgViewer = OSG.osgViewer; | ||
var mstack, mod; | ||
|
||
function SimpleUpdateCallback() {} | ||
SimpleUpdateCallback.prototype = { | ||
angle: 0, | ||
|
||
update: function ( node, nv ) { | ||
var t = nv.getFrameStamp().getSimulationTime(); | ||
var dt = t - node._lastUpdate; | ||
if ( dt < 0 ) { return true; } | ||
node._lastUpdate = t; | ||
|
||
var m = node.getMatrix(); | ||
osg.Matrix.makeRotate( -this.angle, 0.0, 1.0, 0.0, m ); | ||
osg.Matrix.setTrans( m, 0, 0, 10 ); | ||
this.angle += 0.02; | ||
|
||
if ( mod.radius <= 5 ) | ||
{ | ||
mstack.apply( ); | ||
mod.radius += 0.02; | ||
} | ||
return true; | ||
} | ||
}; | ||
|
||
function createBox( cx, cy, cz, wx, wy, wz, hx, hy, hz, res1, res2 ) | ||
{ | ||
cx = cx !== undefined ? cx : -0.5; | ||
cy = cy !== undefined ? cy : -0.5; | ||
cz = cz !== undefined ? cz : 0.0; | ||
|
||
wx = wx !== undefined ? wx : 1.0; | ||
wy = wy !== undefined ? wy : 0.0; | ||
wz = wz !== undefined ? wz : 0.0; | ||
|
||
hx = hx !== undefined ? hx : 0.0; | ||
hy = hy !== undefined ? hy : 1.0; | ||
hz = hz !== undefined ? hz : 0.0; | ||
|
||
res1 = res1 !== undefined ? res1 : 5; | ||
res2 = res2 !== undefined ? res2 : res1; | ||
res1 += 2; | ||
res2 += 2; | ||
|
||
var g = new osg.Geometry(); | ||
var vertices = new Float32Array( ( res1 /*+ res2*/ ) * 2 * 3 ); | ||
//var uv = new Float32Array( ( res1 + res2 ) * 2 * 2 ); | ||
//var normal = new Float32Array( vertices.length ); | ||
var i = 0; | ||
var j = 0, k; | ||
var sx = wx / ( res1 - 1 ); | ||
var sy = wy / ( res1 - 1 ); | ||
var sz = wz / ( res1 - 1 ); | ||
var ux = cx + wx + hx; | ||
var uy = cy + wy + hy; | ||
var uz = cz + wz + hz; | ||
for ( i = 0; i < res1; ++i ) { | ||
j = i * 6; k = i * 4; | ||
vertices[ j ] = cx + sx * i; | ||
vertices[ j + 1 ] = cy + sy * i; | ||
vertices[ j + 2 ] = cz + sz * i; | ||
vertices[ j + 3 ] = ux - sx * ( res1 - i - 1 ); | ||
vertices[ j + 4 ] = uy - sy * ( res1 - i - 1 ); | ||
vertices[ j + 5 ] = uz - sz * ( res1 - i - 1 ); | ||
} | ||
/*sx = hx / ( res2 - 1 ); | ||
sy = hy / ( res2 - 1 ); | ||
sz = hz / ( res2 - 1 ); | ||
for ( i = 0; i < res2; ++i ) { | ||
j = ( res1 + i ) * 6; | ||
vertices[ j ] = cx + sx * i; | ||
vertices[ j + 1 ] = cy + sy * i; | ||
vertices[ j + 2 ] = cz + sz * i; | ||
vertices[ j + 3 ] = ux - sx * ( res2 - i - 1 ); | ||
vertices[ j + 4 ] = uy - sy * ( res2 - i - 1 ); | ||
vertices[ j + 5 ] = uz - sz * ( res2 - i - 1 ); | ||
}*/ | ||
g.getAttributes().Vertex = new osg.BufferArray( osg.BufferArray.ARRAY_BUFFER, vertices, 3 ); | ||
var primitive = new osg.DrawArrays( osg.PrimitiveSet.LINES, 0, ( res1 /*+ res2*/ ) * 2 ); | ||
g.getPrimitives().push( primitive ); | ||
return g; | ||
} | ||
|
||
function createScene() | ||
{ | ||
var root = new osg.Node(); | ||
var cube = createBox( -5, -5, 0.0, 10.0, 0.0, 0.0, 0.0, 10.0, 0, 100, 5 ); | ||
root.addChild( cube ); | ||
mstack = new MOD3.ModifierStack( MOD3.LibraryOSG, cube ); | ||
mod = new MOD3.Bloat( ); | ||
mstack.addModifier( mod ); | ||
return root; | ||
} | ||
|
||
function main( ) | ||
{ | ||
var canvas = document.getElementById( 'View' ); | ||
|
||
var viewer; | ||
try { | ||
viewer = new osgViewer.Viewer( canvas, { | ||
antialias: true, | ||
alpha: true | ||
} ); | ||
viewer.init(); | ||
var scene = createScene(); | ||
var rotate = new osg.MatrixTransform(); | ||
rotate.addChild( scene ); | ||
rotate.addUpdateCallback( new SimpleUpdateCallback() ); | ||
viewer.getCamera().setClearColor( [ 0.7, 0.7, 0.7, 0.0 ] ); | ||
viewer.setSceneData( rotate ); | ||
//viewer.setupManipulator(); | ||
//viewer.getManipulator().computeHomePosition(); | ||
viewer.run(); | ||
|
||
} catch ( er ) { | ||
osg.log( 'exception in osgViewer ' + er ); | ||
} | ||
} | ||
|
||
window.addEventListener( 'load', main, true ); | ||
}( window ); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.