merging with r29

This commit is contained in:
George Profenza
2010-11-30 13:45:00 +00:00
parent 774b5e843d
commit caf2c2000f
14 changed files with 146 additions and 330 deletions
+5 -5
View File
File diff suppressed because one or more lines are too long
+9 -16
View File
@@ -32,7 +32,7 @@
var scene;
var renderer;
var model,material;
var model;
var targetRotation = 0;
var targetRotationOnMouseDown = 0;
@@ -68,10 +68,7 @@
scene = new THREE.Scene();
//model
initBitmapMaterial('geometry/dice.gif');
var geom = new Dice249UV()
model = new THREE.Mesh( new Dice249UV(), material );
model = new THREE.Mesh( new Dice249UV(), new THREE.MeshBasicMaterial( { map: loadImage( 'geometry/dice.gif' ) } ) );
model.rotation.x = Math.PI * .5;
model.rotation.z = Math.PI * .25;
model.scale = new THREE.Vector3(70,70,70);
@@ -161,20 +158,16 @@
renderer.render(scene, camera);
stats.update();
}
function initBitmapMaterial(url) {
function loadImage( path ) {
texture = document.createElement( 'canvas' );
texture.width = 128;
texture.height = 128;
var image = document.createElement( 'img' );
var texture = new THREE.Texture( image, THREE.UVMapping )
material = new THREE.MeshBitmapMaterial( texture );
image.onload = function () { texture.loaded = true; };
image.src = path;
return texture;
var temp = new Image();
temp.onload = function () {
material.bitmap = this;
renderer.render(scene, camera);
};
temp.src = url;
}
</script>
-16
View File
@@ -69,7 +69,6 @@
scene = new THREE.Scene();
//model
initBitmapMaterial('geometry/Dice.jpg');
var geometry = new Box6();
geometry.autoColor();
model = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
@@ -159,21 +158,6 @@
renderer.render(scene, camera);
stats.update();
}
function initBitmapMaterial(url) {
texture = document.createElement( 'canvas' );
texture.width = 128;
texture.height = 128;
material = new THREE.MeshBitmapMaterial( texture );
var temp = new Image();
temp.onload = function () {
material.bitmap = this;
renderer.render(scene, camera);
};
temp.src = url;
}
</script>
+92 -245
View File
@@ -1,287 +1,134 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>three.js - Lights test</title>
<title>three.js - nano with point light</title>
<meta charset="utf-8">
<style type="text/css">
body {
background:#fff;
padding:0;
margin:0;
overflow:hidden;
font-family:georgia;
text-align:center;
background-color: #000000;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
color: #ffffff;
padding: 5px;
font-family: Monospace;
font-size: 13px;
text-align: center;
}
a {
color: #FF8628;
text-decoration: none;
}
a:hover {
color: #FFAB4C;
}
h1 { }
a { color:skyblue }
canvas { pointer-events:none; z-index:10; position:relative; }
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
#d { text-align:center; margin:1em 0 -15.7em 0; z-index:0; position:relative; display:block }
.button { background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer }
.inactive { background:#999; color:#eee }
</style>
</head>
<body>
<div id="d">
<h1>Lights test on Nano</h1>
<body>
<span id="rcanvas" class="button inactive">2d canvas renderer</span>
<span id="rwebgl" class="button">WebGL renderer</span>
<br/>
<p>Using a modified version of <a href="http://github.com/alteredq/three.js">Three.js</a> by mrdoob.
<br />
<p>Model design by <a href="http://www.deltainc.nl/">DeltaInc</a></p>
<br/>
<p>Best viewed in Chrome 7/8 or Firefox 4 using WebGL renderer.
<p>Canvas renderer is very slow on anything other than Chrome.
</div>
<div id="log"></div>
<div id="container"></div>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - point lights demo.<br />
Nano design by <a href="http://deltainc.nl" target="_blank">DeltaInc</a><br />
<small>Based on pointlights example</small>
</div>
<!--
<script type="text/javascript" src="../build/Three.js"></script>
-->
<script type="text/javascript" src="../src/Three.js"></script>
<script type="text/javascript" src="../src/core/Color.js"></script>
<script type="text/javascript" src="../src/core/Vector2.js"></script>
<script type="text/javascript" src="../src/core/Vector3.js"></script>
<script type="text/javascript" src="../src/core/Vector4.js"></script>
<script type="text/javascript" src="../src/core/Rectangle.js"></script>
<script type="text/javascript" src="../src/core/Matrix3.js"></script>
<script type="text/javascript" src="../src/core/Matrix4.js"></script>
<script type="text/javascript" src="../src/core/Vertex.js"></script>
<script type="text/javascript" src="../src/core/Face3.js"></script>
<script type="text/javascript" src="../src/core/Face4.js"></script>
<script type="text/javascript" src="../src/core/UV.js"></script>
<script type="text/javascript" src="../src/core/Geometry.js"></script>
<script type="text/javascript" src="../src/cameras/Camera.js"></script>
<script type="text/javascript" src="../src/lights/Light.js"></script>
<script type="text/javascript" src="../src/lights/AmbientLight.js"></script>
<script type="text/javascript" src="../src/lights/DirectionalLight.js"></script>
<script type="text/javascript" src="../src/lights/PointLight.js"></script>
<script type="text/javascript" src="../src/objects/Object3D.js"></script>
<script type="text/javascript" src="../src/objects/Mesh.js"></script>
<script type="text/javascript" src="../src/objects/Particle.js"></script>
<script type="text/javascript" src="../src/objects/Line.js"></script>
<script type="text/javascript" src="../src/materials/LineColorMaterial.js"></script>
<script type="text/javascript" src="../src/materials/MeshPhongMaterial.js"></script>
<script type="text/javascript" src="../src/materials/MeshBitmapMaterial.js"></script>
<script type="text/javascript" src="../src/materials/MeshColorFillMaterial.js"></script>
<script type="text/javascript" src="../src/materials/MeshColorStrokeMaterial.js"></script>
<script type="text/javascript" src="../src/materials/MeshFaceMaterial.js"></script>
<script type="text/javascript" src="../src/materials/ParticleCircleMaterial.js"></script>
<script type="text/javascript" src="../src/materials/ParticleBitmapMaterial.js"></script>
<script type="text/javascript" src="../src/scenes/Scene.js"></script>
<script type="text/javascript" src="../src/renderers/Projector.js"></script>
<script type="text/javascript" src="../src/renderers/CanvasRenderer.js"></script>
<script type="text/javascript" src="../src/renderers/SVGRenderer.js"></script>
<script type="text/javascript" src="../src/renderers/WebGLRenderer.js"></script>
<script type="text/javascript" src="../src/renderers/renderables/RenderableFace3.js"></script>
<script type="text/javascript" src="../src/renderers/renderables/RenderableFace4.js"></script>
<script type="text/javascript" src="../src/renderers/renderables/RenderableParticle.js"></script>
<script type="text/javascript" src="../src/renderers/renderables/RenderableLine.js"></script>
<!--
-->
<script type="text/javascript" src="geometry/primitives/Sphere.js"></script>
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="obj/nano/Nano.js"></script>
<script type="text/javascript">
var SCREEN_WIDTH = window.innerWidth/2;
var SCREEN_HEIGHT = window.innerHeight;
var FLOOR = -250;
var container;
var stats;
var camera;
var scene;
var canvasRenderer, webglRenderer;
var mesh, zmesh, lightMesh, geometry;
var directionalLight, pointLight;
var mouseX = 0;
var mouseY = 0;
var windowHalfX = window.innerWidth >> 1;
var windowHalfY = window.innerHeight >> 1;
var render_canvas = 1, render_gl = 1;
var has_gl = 0;
var bcanvas = document.getElementById("rcanvas");
var bwebgl = document.getElementById("rwebgl");
document.addEventListener('mousemove', onDocumentMouseMove, false);
var camera, scene, renderer,
particle1, particle2, particle2,
light1, light2, light3,
object;
init();
loop();
//render_canvas = !has_gl;
bwebgl.style.display = has_gl ? "inline" : "none";
bcanvas.className = render_canvas ? "button" : "button inactive";
setInterval(loop, 1000/60);
setInterval( loop, 1000 / 60 );
function init() {
container = document.createElement('div');
document.body.appendChild(container);
var container = document.getElementById( 'container' );
camera = new THREE.Camera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 100000 );
camera.position.z = 500;
camera.updateMatrix();
camera = new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 100;
scene = new THREE.Scene();
// LIGHTS
var ambient = new THREE.AmbientLight( 0x101010 );
scene.addLight( ambient );
object = new THREE.Mesh( new Nano(), new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading } ) );
object.overdraw = true;
object.scale = new THREE.Vector3(.25,.25,.25);
scene.addObject( object );
directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position.y = -70;
directionalLight.position.z = 100;
directionalLight.position.normalize();
scene.addLight( directionalLight );
particle1 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xFC0007 } ) );
particle1.scale.x = particle1.scale.y = particle1.scale.z = 0.5;
scene.addObject( particle1 );
pointLight = new THREE.PointLight( 0xffaa00 );
pointLight.position.x = 0;
pointLight.position.y = 0;
pointLight.position.z = 0;
scene.addLight( pointLight );
particle2 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xC8EBF1 } ) );
particle2.scale.x = particle2.scale.y = particle2.scale.z = 0.5;
scene.addObject( particle2 );
if( render_canvas ) {
canvasRenderer = new THREE.CanvasRenderer();
canvasRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( canvasRenderer.domElement );
}
particle3 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xFE8101 } ) );
particle3.scale.x = particle3.scale.y = particle3.scale.z = 0.5;
scene.addObject( particle3 );
if ( render_gl ) {
try {
webglRenderer = new THREE.WebGLRenderer();
webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
container.appendChild( webglRenderer.domElement );
has_gl = 1;
}
catch (e) {
}
}
scene.addLight( new THREE.AmbientLight( 0x00020 ) );
light1 = new THREE.PointLight( 0xFC0007 );
scene.addLight( light1 );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
bcanvas.addEventListener("click", toggleCanvas, false);
bwebgl.addEventListener("click", toggleWebGL, false);
light2 = new THREE.PointLight( 0xC8EBF1 );
scene.addLight( light2 );
function createModel() {
// MESH
geometry = new Nano( );
zmesh = new THREE.Mesh( geometry, new THREE.MeshColorFillMaterial( 0x5E3B1A ) );
zmesh.position.x = 0;
zmesh.position.z = 0;
zmesh.position.y = -100;
// zmesh.scale.x = zmesh.scale.y = zmesh.scale.z = 1.5;
zmesh.overdraw = true;
zmesh.updateMatrix();
scene.addObject(zmesh);
}
light3 = new THREE.PointLight( 0xFE8101 );
scene.addLight( light3 );
loadAsync( "obj/nano/Nano.js", createModel);
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
}
function loadAsync( url, callback ) {
var el = document.createElement( 'script' );
el.type = 'text/javascript';
el.onload = callback;
el.src = url;
document.getElementsByTagName("head")[0].appendChild(el);
}
function onDocumentMouseMove(event) {
mouseX = ( event.clientX - windowHalfX );
mouseY = ( event.clientY - windowHalfY );
}
var r = 0;
function loop() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
camera.updateMatrix();
r += 0.1;
var time = new Date().getTime() * 0.0005;
pointLight.position.x = 200*Math.cos(r);
pointLight.position.z = 200*Math.sin(r);
if ( render_canvas ) canvasRenderer.render( scene, camera );
if ( render_gl && has_gl ) webglRenderer.render( scene, camera );
object.rotation.y -= 0.01;
stats.update();
particle1.position.x = Math.sin( time * 0.7 ) * 30;
particle1.position.y = Math.cos( time * 0.5 ) * 40;
particle1.position.z = Math.cos( time * 0.3 ) * 30;
light1.position.x = particle1.position.x;
light1.position.y = particle1.position.y;
light1.position.z = particle1.position.z;
particle2.position.x = Math.cos( time * 0.3 ) * 30;
particle2.position.y = Math.sin( time * 0.5 ) * 40;
particle2.position.z = Math.sin( time * 0.7 ) * 30;
light2.position.x = particle2.position.x;
light2.position.y = particle2.position.y;
light2.position.z = particle2.position.z;
particle3.position.x = Math.sin( time * 0.7 ) * 30;
particle3.position.y = Math.cos( time * 0.3 ) * 40;
particle3.position.z = Math.sin( time * 0.5 ) * 30;
light3.position.x = particle3.position.x;
light3.position.y = particle3.position.y;
light3.position.z = particle3.position.z;
renderer.render(scene, camera);
}
function log(text) {
var e = document.getElementById("log");
e.innerHTML = text + "<br/>" + e.innerHTML;
}
function toggleCanvas() {
render_canvas = !render_canvas;
bcanvas.className = render_canvas ? "button" : "button inactive";
render_gl = !render_canvas;
bwebgl.className = render_gl ? "button" : "button inactive";
if( has_gl )
webglRenderer.domElement.style.display = render_gl ? "block" : "none";
canvasRenderer.domElement.style.display = render_canvas ? "block" : "none";
}
function toggleWebGL() {
render_gl = !render_gl;
bwebgl.className = render_gl ? "button" : "button inactive";
render_canvas = !render_gl;
bcanvas.className = render_canvas ? "button" : "button inactive";
if( has_gl )
webglRenderer.domElement.style.display = render_gl ? "block" : "none";
canvasRenderer.domElement.style.display = render_canvas ? "block" : "none";
}
</script>
</body>
</html>
+8 -15
View File
@@ -67,10 +67,7 @@
scene = new THREE.Scene();
//model
initBitmapMaterial('geometry/dice.gif');
geom = new Dice();
//geom.autoColor();
model = new THREE.Mesh( geom, material );
model = new THREE.Mesh( new Dice(), new THREE.MeshBasicMaterial( { map: loadImage( 'geometry/dice.gif' ) } ) );
model.rotation.x = Math.PI * .5;
model.scale = new THREE.Vector3(.75,.75,.75);
scene.addObject(model);
@@ -158,20 +155,16 @@
renderer.render(scene, camera);
stats.update();
}
function initBitmapMaterial(url) {
function loadImage( path ) {
texture = document.createElement( 'canvas' );
texture.width = 128;
texture.height = 128;
var image = document.createElement( 'img' );
var texture = new THREE.Texture( image, THREE.UVMapping )
material = new THREE.MeshBitmapMaterial( texture );
image.onload = function () { texture.loaded = true; };
image.src = path;
return texture;
var temp = new Image();
temp.onload = function () {
material.bitmap = this;
renderer.render(scene, camera);
};
temp.src = url;
}
</script>
+4 -2
View File
@@ -67,7 +67,7 @@
//model
var geometry = new DodecaEdges();
for (var i = 0; i < geometry.faces.length; i++) geometry.faces[i].material = [ new THREE.MeshColorFillMaterial( Math.random() * 0xffffff, 1 ) ];
for (var i = 0; i < geometry.faces.length; i++) geometry.faces[i].material = [ new THREE.MeshBasicMaterial( {color:Math.random() * 0xffffff} ) ];
model = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
var s = 3;
model.scale = new THREE.Vector3(s,s,s);
@@ -79,10 +79,12 @@
model3 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
model3.scale = new THREE.Vector3(s*3.2216,s*3.2216,s*3.2216);
scene.addObject(model3);
scene.addObject(model2);
scene.addObject(model);
renderer = new THREE.CanvasRenderer();
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
Executable → Regular
+1 -1
View File
@@ -115,7 +115,7 @@ var BotArmL = function () {
scope.autoColor = function(){
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [new THREE.MeshBasicMaterial({color:this.colors[s]})];
}
}
Executable → Regular
+1 -1
View File
@@ -143,7 +143,7 @@ var BotArmR = function () {
scope.autoColor = function(){
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [new THREE.MeshBasicMaterial({color:this.colors[s]})];
}
}
+1 -1
View File
@@ -516,7 +516,7 @@ var BotLowerBody = function () {
scope.autoColor = function(){
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [new THREE.MeshBasicMaterial({color:this.colors[s]})];
}
}
+1 -1
View File
@@ -873,7 +873,7 @@ var BotUpperBody = function () {
scope.autoColor = function(){
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [new THREE.MeshBasicMaterial({color:this.colors[s]})];
}
}
+2 -2
View File
@@ -42,8 +42,8 @@ var Box6 = function () {
scope.colors["right"] = 0xb2b200;
scope.autoColor = function(){
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
for(var s in this.selections){
for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshBasicMaterial( { color: this.colors[s], wireframe: false } ) ];
}
}
BIN
View File
Binary file not shown.
+21 -24
View File
@@ -912,44 +912,41 @@ var Nano = function ( urlbase ) {
function create_material( m ) {
var material;
/*
if( m.map_diffuse && urlbase ) {
var texture = document.createElement( 'canvas' );
material = new THREE.MeshBitmapMaterial( texture );
var image = new Image();
// material = new THREE.MeshBitmapMaterial( texture );
material = new THREE.MeshBasicMaterial( { map: loadImage( urlbase ) }
function loadImage( path ) {
var image = document.createElement( 'img' );
var texture = new THREE.Texture( image, THREE.UVMapping )
image.onload = function () { texture.loaded = true; };
image.src = path;
return texture;
}
image.onload = function () {
if ( !is_pow2(this.width) || !is_pow2(this.height) ) {
var w = nearest_pow2( this.width );
var h = nearest_pow2( this.height );
material.bitmap.width = w;
material.bitmap.height = h;
material.bitmap.getContext("2d").drawImage( this, 0, 0, w, h );
}
else {
material.bitmap = this;
}
material.loaded = 1;
};
image.src = urlbase + "/" + m.map_diffuse;
}
else if( m.col_diffuse ) {
else */
if( m.col_diffuse ) {
var color = (m.col_diffuse[0]*255 << 16) + (m.col_diffuse[1]*255 << 8) + m.col_diffuse[2]*255;
material = new THREE.MeshColorFillMaterial( color, m.transparency );
material = new THREE.MeshBasicMaterial( {color:color, opacity:m.transparency} );
}
else if( m.a_dbg_color ) {
material = new THREE.MeshColorFillMaterial( m.a_dbg_color );
material = new THREE.MeshBasicMaterial( {color:m.a_dbg_color} );
}
else {
material = new THREE.MeshColorFillMaterial( 0xffeeeeee );
material = new THREE.MeshBasicMaterial( {color:0xffeeeeee} );
}
return material;
}
}
Nano.prototype = new THREE.Geometry();
@@ -134,7 +134,7 @@ def Export():
code += '\n\tscope.autoColor = function(){\n'
code += '\t\tfor(var s in this.selections){\n'
code += '\t\t\tfor(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];\n'
code += '\t\t\tfor(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [new THREE.MeshBasicMaterial({color:this.colors[s]})];\n'
code += '\t\t}\n\t}\n'
# model position, rotation, scale rotation x,y,z = H,P,B => three.js x,y,z is P,H,B => y,x,z