Skip to content

Commit

Permalink
v.0.6.0, final
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos M committed Jul 18, 2016
1 parent 6f565f4 commit c866d61
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build/MOD3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/mod3.bundle.js

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions examples/OSG/Bend.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
var mstack, mod;

// dynamic update
osg.Geometry.enableVAO = true;
//osg.Geometry.enableVAO = true;

function SimpleUpdateCallback( ){ }
SimpleUpdateCallback.prototype = {
constructor: SimpleUpdateCallback,

angle: 0,

update: function ( node, nv ) {
Expand All @@ -50,10 +48,10 @@
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.force < 1.8 )
if ( mod.force <= 1.8 )
{
mstack.apply( );
mod.force += 0.1;
mod.force += 0.01;
}
return true;
}
Expand Down Expand Up @@ -149,9 +147,8 @@
rotate.addUpdateCallback( new SimpleUpdateCallback() );
viewer.getCamera( ).setClearColor( [ 0.7, 0.7, 0.7, 0.0 ] );
viewer.setSceneData( rotate );
//viewer._requestContinousUpdate = true;
viewer.setupManipulator();
viewer.getManipulator().computeHomePosition();
//viewer.setupManipulator();
//viewer.getManipulator().computeHomePosition();
viewer.run( );

} catch ( er ) {
Expand Down
156 changes: 156 additions & 0 deletions examples/OSG/Bloat.html
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>
24 changes: 9 additions & 15 deletions examples/OSG/Perlin.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
</body>

<script type="text/javascript">

var OSG = window.OSG;
var osg = OSG.osg;
var osgAnimation = OSG.osgAnimation;
var osgViewer = OSG.osgViewer;
var cube, mstack, mod, rotate;
!function( window ){
var OSG = window.OSG, osg = OSG.osg, osgAnimation = OSG.osgAnimation, osgViewer = OSG.osgViewer;
var mstack, mod;

function generate_noise2d( w, h, perlinNoise2d )
{
Expand All @@ -50,7 +47,6 @@

function SimpleUpdateCallback() {}
SimpleUpdateCallback.prototype = {
mod_force: 1,
angle: 0,

update: function ( node, nv ) {
Expand All @@ -59,12 +55,11 @@
if ( dt < 0 ) { return true; }
node._lastUpdate = t;

var m = rotate.getMatrix();
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;

mod.force = this.mod_force;
mstack.apply( );
return true;
}
Expand Down Expand Up @@ -131,11 +126,10 @@
function createScene()
{
var root = new osg.Node();
cube = createBox( -5, -5, 0.0, 10.0, 0.0, 0.0, 0.0, 10.0, 0, 100, 5 );
cube.addUpdateCallback( new SimpleUpdateCallback() );
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.Perlin( 20, generate_noise2d( 50, 50 ) );
mod = new MOD3.Perlin( 1.5, generate_noise2d( 50, 50 ) );
mstack.addModifier( mod );
return root;
}
Expand All @@ -152,13 +146,13 @@
} );
viewer.init();
var scene = createScene();
rotate = new osg.MatrixTransform();
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 ) {
Expand All @@ -167,6 +161,6 @@
}

window.addEventListener( 'load', main, true );

}( window );
</script>
</html>
Loading

0 comments on commit c866d61

Please sign in to comment.