Professional Documents
Culture Documents
PROJECT
ITE401
you use, but the underlying theory is the same for all packages. Each
bone affects each vertex, using a weight from 0 to 1. When the
weight is at 0, the vertex is unaffected by the bone. When the weight
is at 1, the bone completely controls the motion of the vertex, and
the vertex is said to be fully affected. Weights in the middle of the
range allow multiple bones to affect a vertex.
Techniques
Laplacian Deformation on Abstract Graphs
Suppose G = (P,E) is a graph, where P is a set of N point
positions
P = {pi R3|1 i N}, and E = {(i, j)| pi is connected to pj}
is the set of edges. The Laplacian of a graph is analogous to
the Laplace operator on manifolds [Chung 1997] and computes
the difference between each point pi in the graph G and a linear
combination of its neighboring points:
To review this method, let C(u) and C(u) be the original and
deformed control curves respectively, parameterized by arc
length u [0,1]. Given some neighboring point p R3, let up
[0,1] be the parameter value minimizing distance between p
and the curve C(u). The deformation maps p to p such that C
maps to C and points nearby move analogously:
Working on three.js
Three.js is a cross-browser JavaScript library/API used to create and
display animated 3D computer graphics in a web browser. Three.js
uses WebGL. The source code is hosted in a repository on GitHub.
Three.js allows the creation of GPU-accelerated 3D animations using
the JavaScript language as part of a website without relying on
proprietary browser plugins.This is possible thanks to the advent of
WebGL.High-level libraries such as Three.js or GLGE, SceneJS, PhiloGL
or a number of other libraries make it possible to author complex 3D
computer animations that display in the browser without the effort
required for a traditional standalone application or a plugin.
The Three.js library is a single JavaScript file. It can be included within
a web page by linking to a local or remote copy.
Effects: Anaglyph, cross-eyed and parallax barrier.
Scenes: add and remove objects at run-time; fog
Cameras: perspective and orthographic; controllers: trackball,
FPS, path and more
Animation: armatures, forward kinematics, inverse kinematics,
morph and keyframe
Lights: ambient, direction, point and spot lights; shadows: cast
and receive
Materials: Lambert, Phong, smooth shading, textures and more
Shaders: access to full OpenGL Shading Language (GLSL)
capabilities: lens flare, depth pass and extensive postprocessing library
Objects: meshes, particles, sprites, lines, ribbons, bones and
more - all with Level of detail
Geometry: plane, cube, sphere, torus, 3D text and more;
modifiers: lathe, extrude and tube
Data loaders: binary, image, JSON and scene
Utilities: full set of time and 3D math functions including
frustum, matrix, quaternion, UVs and more
2. Creating a Scene
To actually be able to display anything with Three.js, we need
three things: A scene, a camera, and a renderer so we can
render the scene with the camera.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75,
window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
Last but not least, we add the renderer element to our HTML
document. This is a <canvas> element the renderer uses to display the
scene to us.
function render() {
requestAnimationFrame( render );
renderer.render( scene, camera );
}
render();
This will create a loop that causes the renderer to draw the scene 60
times per second. If you're new to writing games in the browser, you
might say "why don't we just create a setInterval? The thing is - we
could, but requestAnimationFrame has a number of advantages.
Perhaps the most important one is that it pauses when the user
navigates to another browser tab, hence not wasting their precious
processing power and battery life.
Complete Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CGM Project</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, userscalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #111;
color: #fff;
margin: 0px;
overflow: hidden;
}
a { color: #f00 }
</style>
</head>
<body>
<script src="three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
var container, stats;
var camera, scene, renderer;
var mixers = [];
var clock = new THREE.Clock();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = 'CGM Project based on
threejs<br>By:<br>Rishab Mittal (13BIT0058)<br>Roopendra
shading: THREE.FlatShading
} );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = - 150;
mesh.position.y = 150;
mesh.scale.set( 1.5, 1.5, 1.5 );
scene.add( mesh );
var mixer = new THREE.AnimationMixer( mesh );
mixer.clipAction( geometry.animations[ 0 ] ).setDuration( 1
).play();
mixers.push( mixer );
} );
loader.load( "models/animated/flamingo.js", function(
geometry ) {
geometry.computeVertexNormals();
geometry.computeMorphNormals();
var material = new THREE.MeshPhongMaterial( {
color: 0xffffff,
morphTargets: true,
morphNormals: true,
vertexColors: THREE.FaceColors,
shading: THREE.SmoothShading
} );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = 150;
mesh.position.y = 150;
mesh.scale.set( 1.5, 1.5, 1.5 );
scene.add( mesh );
var mixer = new THREE.AnimationMixer( mesh );
mixer.clipAction( geometry.animations[ 0 ] ).setDuration( 1
).play();
mixers.push( mixer );
} );
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( renderer.domElement );
//
stats = new Stats();
container.appendChild( stats.dom );
//
window.addEventListener( 'resize', onWindowResize, false );
}
//
function onWindowResize( event ) {
SCREEN_WIDTH = window.innerWidth;
SCREEN_HEIGHT = window.innerHeight;
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
camera.aspect = 0.5 * SCREEN_WIDTH / SCREEN_HEIGHT;
camera.updateProjectionMatrix();
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
var radius = 600;
var theta = 0;
function render() {
theta += 0.1;
camera.position.x = radius * Math.sin(
THREE.Math.degToRad( theta ) );
camera.position.z = radius * Math.cos(
THREE.Math.degToRad( theta ) );
camera.lookAt( camera.target );
var delta = clock.getDelta();
for ( var i = 0; i < mixers.length; i ++ ) {
mixers[ i ].update( delta );
}
renderer.clear();
renderer.render( scene, camera );
}
</script>
</body>
</html>
Output
Conclusion
The Bird Mesh Modeling using Three.JS was completed successfully
by the team. The code is working perfectly and shows the actual bird
model along with the mesh model.
In the future more advanced features can be added such as freehand movement of model, hollow mesh model etc.