mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-16 16:36:04 +10:00
Merge remote branch 'upstream/master'
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
@@ -57,8 +57,8 @@
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js - geometry - cube</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
||||
<style type="text/css">
|
||||
body
|
||||
{
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="../../build/three.js"></script>
|
||||
<script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var SCREEN_WIDTH = window.innerWidth;
|
||||
var SCREEN_HEIGHT = window.innerHeight;
|
||||
|
||||
var container;
|
||||
var stats;
|
||||
|
||||
var camera;
|
||||
var scene;
|
||||
var renderer;
|
||||
|
||||
var cube, plane;
|
||||
|
||||
var targetRotation = 0;
|
||||
var targetRotationOnMouseDown = 0;
|
||||
|
||||
var mouseX = 0;
|
||||
var mouseXOnMouseDown = 0;
|
||||
|
||||
var windowHalfX = window.innerWidth / 2;
|
||||
var windowHalfY = window.innerHeight / 2;
|
||||
|
||||
init();
|
||||
setInterval(loop, 1000/60);
|
||||
|
||||
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 = 'Drag to spin the cube';
|
||||
container.appendChild(info);
|
||||
|
||||
camera = new Camera(0, 150, 400);
|
||||
camera.focus = 300;
|
||||
camera.target.y = 150;
|
||||
camera.updateMatrix();
|
||||
|
||||
scene = new Scene();
|
||||
|
||||
// Cube
|
||||
|
||||
geometry = new Cube(200, 200, 200);
|
||||
|
||||
for (var i = 0; i < geometry.faces.length; i++)
|
||||
geometry.faces[i].color.setRGBA( Math.floor( Math.random() * 128), Math.floor( Math.random() * 128 + 128), Math.floor( Math.random() * 128 + 128), 255 );
|
||||
|
||||
cube = new Mesh(geometry, new FaceColorMaterial());
|
||||
cube.position.y = 150;
|
||||
cube.updateMatrix();
|
||||
scene.add(cube);
|
||||
|
||||
// Plane
|
||||
|
||||
plane = new Mesh(new Plane(200, 200), new ColorMaterial(0xe0e0e0));
|
||||
plane.rotation.x = 90 * (Math.PI / 180);
|
||||
plane.updateMatrix();
|
||||
scene.add(plane);
|
||||
|
||||
renderer = new CanvasRenderer();
|
||||
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
container.appendChild(renderer.viewport);
|
||||
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild(stats.domElement);
|
||||
|
||||
document.addEventListener('mousedown', onDocumentMouseDown, false);
|
||||
document.addEventListener('touchstart', onDocumentTouchStart, false);
|
||||
document.addEventListener('touchmove', onDocumentTouchMove, false);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function onDocumentMouseDown( event )
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
document.addEventListener('mousemove', onDocumentMouseMove, false);
|
||||
document.addEventListener('mouseup', onDocumentMouseUp, false);
|
||||
document.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 )
|
||||
{
|
||||
document.removeEventListener('mousemove', onDocumentMouseMove, false);
|
||||
document.removeEventListener('mouseup', onDocumentMouseUp, false);
|
||||
document.removeEventListener('mouseout', onDocumentMouseOut, false);
|
||||
}
|
||||
|
||||
function onDocumentMouseOut( event )
|
||||
{
|
||||
document.removeEventListener('mousemove', onDocumentMouseMove, false);
|
||||
document.removeEventListener('mouseup', onDocumentMouseUp, false);
|
||||
document.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 loop()
|
||||
{
|
||||
cube.rotation.y += (targetRotation - cube.rotation.y) * 0.05;
|
||||
cube.updateMatrix();
|
||||
|
||||
plane.rotation.z = -cube.rotation.y;
|
||||
plane.updateMatrix();
|
||||
|
||||
renderer.render(scene, camera);
|
||||
stats.update();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -16,23 +16,16 @@
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var SCREEN_WIDTH = window.innerWidth;
|
||||
var SCREEN_HEIGHT = window.innerHeight;
|
||||
var container, stats;
|
||||
|
||||
var container;
|
||||
var stats;
|
||||
|
||||
var camera;
|
||||
var scene;
|
||||
var renderer;
|
||||
var camera, scene, renderer;
|
||||
|
||||
var cube, plane;
|
||||
|
||||
@@ -61,7 +54,7 @@
|
||||
info.innerHTML = 'Drag to spin the cube';
|
||||
container.appendChild( info );
|
||||
|
||||
camera = new THREE.Camera( 70, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
|
||||
camera = new THREE.Camera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.y = 150;
|
||||
camera.position.z = 500;
|
||||
camera.target.position.y = 150;
|
||||
@@ -88,7 +81,7 @@
|
||||
scene.addObject( plane );
|
||||
|
||||
renderer = new THREE.CanvasRenderer();
|
||||
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
|
||||
container.appendChild( renderer.domElement );
|
||||
|
||||
|
||||
@@ -36,9 +36,8 @@
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@
|
||||
<pre id="log"></pre>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
<script type="text/javascript" src="js/ImprovedNoise.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - vr demo. skybox by <a href="http://www.zfight.com/" target="_blank">Jochum Skoglund</a></div>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
@@ -82,11 +82,9 @@
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -85,15 +85,15 @@
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var SCREEN_WIDTH = window.innerWidth/2;
|
||||
var SCREEN_WIDTH = window.innerWidth / 2;
|
||||
var SCREEN_HEIGHT = window.innerHeight;
|
||||
var FLOOR = -250;
|
||||
|
||||
@@ -105,9 +105,9 @@
|
||||
var canvasRenderer, webglRenderer;
|
||||
|
||||
var mesh, zmesh, lightMesh, geometry;
|
||||
|
||||
|
||||
var directionalLight, pointLight;
|
||||
|
||||
|
||||
var mouseX = 0;
|
||||
var mouseY = 0;
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<video id="video" autoplay style="display:none">
|
||||
<source src="textures/sintel.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
|
||||
|
||||
@@ -90,8 +90,8 @@
|
||||
-->
|
||||
|
||||
|
||||
<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="../src/extras/primitives/Sphere.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
+3
-3
@@ -56,9 +56,9 @@
|
||||
<script type="text/javascript" src="../src/renderers/renderables/RenderableLine.js"></script>
|
||||
|
||||
<script type="text/javascript" src="geometry/Qrcode.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="geometry/primitives/Cylinder.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
||||
<script type="text/javascript" src="../src/extras/primitives/Cylinder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
|
||||
+45
-44
@@ -4,26 +4,25 @@
|
||||
|
||||
THREE.Rectangle = function () {
|
||||
|
||||
var _x1, _y1, _x2, _y2,
|
||||
_width, _height,
|
||||
_isEmpty = true;
|
||||
var _left, _top, _right, _bottom,
|
||||
_width, _height, _isEmpty = true;
|
||||
|
||||
function resize() {
|
||||
|
||||
_width = _x2 - _x1;
|
||||
_height = _y2 - _y1;
|
||||
_width = _right - _left;
|
||||
_height = _bottom - _top;
|
||||
|
||||
}
|
||||
|
||||
this.getX = function () {
|
||||
|
||||
return _x1;
|
||||
return _left;
|
||||
|
||||
};
|
||||
|
||||
this.getY = function () {
|
||||
|
||||
return _y1;
|
||||
return _top;
|
||||
|
||||
};
|
||||
|
||||
@@ -39,36 +38,36 @@ THREE.Rectangle = function () {
|
||||
|
||||
};
|
||||
|
||||
this.getX1 = function() {
|
||||
this.getLeft = function() {
|
||||
|
||||
return _x1;
|
||||
return _left;
|
||||
|
||||
};
|
||||
|
||||
this.getY1 = function() {
|
||||
this.getTop = function() {
|
||||
|
||||
return _y1;
|
||||
return _top;
|
||||
|
||||
};
|
||||
|
||||
this.getX2 = function() {
|
||||
this.getRight = function() {
|
||||
|
||||
return _x2;
|
||||
return _right;
|
||||
|
||||
};
|
||||
|
||||
this.getY2 = function() {
|
||||
this.getBottom = function() {
|
||||
|
||||
return _y2;
|
||||
return _bottom;
|
||||
|
||||
};
|
||||
|
||||
this.set = function ( x1, y1, x2, y2 ) {
|
||||
this.set = function ( left, top, right, bottom ) {
|
||||
|
||||
_isEmpty = false;
|
||||
|
||||
_x1 = x1; _y1 = y1;
|
||||
_x2 = x2; _y2 = y2;
|
||||
_left = left; _top = top;
|
||||
_right = right; _bottom = bottom;
|
||||
|
||||
resize();
|
||||
|
||||
@@ -79,15 +78,15 @@ THREE.Rectangle = function () {
|
||||
if ( _isEmpty ) {
|
||||
|
||||
_isEmpty = false;
|
||||
_x1 = x; _y1 = y;
|
||||
_x2 = x; _y2 = y;
|
||||
_left = x; _top = y;
|
||||
_right = x; _bottom = y;
|
||||
|
||||
} else {
|
||||
|
||||
_x1 = Math.min( _x1, x );
|
||||
_y1 = Math.min( _y1, y );
|
||||
_x2 = Math.max( _x2, x );
|
||||
_y2 = Math.max( _y2, y );
|
||||
_left = Math.min( _left, x );
|
||||
_top = Math.min( _top, y );
|
||||
_right = Math.max( _right, x );
|
||||
_bottom = Math.max( _bottom, y );
|
||||
|
||||
}
|
||||
|
||||
@@ -100,15 +99,15 @@ THREE.Rectangle = function () {
|
||||
if ( _isEmpty ) {
|
||||
|
||||
_isEmpty = false;
|
||||
_x1 = r.getX1(); _y1 = r.getY1();
|
||||
_x2 = r.getX2(); _y2 = r.getY2();
|
||||
_left = r.getLeft(); _top = r.getTop();
|
||||
_right = r.getRight(); _bottom = r.getBottom();
|
||||
|
||||
} else {
|
||||
|
||||
_x1 = Math.min(_x1, r.getX1());
|
||||
_y1 = Math.min(_y1, r.getY1());
|
||||
_x2 = Math.max(_x2, r.getX2());
|
||||
_y2 = Math.max(_y2, r.getY2());
|
||||
_left = Math.min(_left, r.getLeft());
|
||||
_top = Math.min(_top, r.getTop());
|
||||
_right = Math.max(_right, r.getRight());
|
||||
_bottom = Math.max(_bottom, r.getBottom());
|
||||
|
||||
}
|
||||
|
||||
@@ -118,35 +117,37 @@ THREE.Rectangle = function () {
|
||||
|
||||
this.inflate = function ( v ) {
|
||||
|
||||
_x1 -= v; _y1 -= v;
|
||||
_x2 += v; _y2 += v;
|
||||
_left -= v; _top -= v;
|
||||
_right += v; _bottom += v;
|
||||
|
||||
resize();
|
||||
|
||||
};
|
||||
|
||||
this.minSelf = function( r ) {
|
||||
this.minSelf = function ( r ) {
|
||||
|
||||
_x1 = Math.max( _x1, r.getX1() );
|
||||
_y1 = Math.max( _y1, r.getY1() );
|
||||
_x2 = Math.min( _x2, r.getX2() );
|
||||
_y2 = Math.min( _y2, r.getY2() );
|
||||
_left = Math.max( _left, r.getLeft() );
|
||||
_top = Math.max( _top, r.getTop() );
|
||||
_right = Math.min( _right, r.getRight() );
|
||||
_bottom = Math.min( _bottom, r.getBottom() );
|
||||
|
||||
resize();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
this.containsPoint = function (x, y) {
|
||||
this.contains = function ( x, y ) {
|
||||
|
||||
return x > _x1 && x < _x2 && y > _y1 && y < _y2;
|
||||
return x > _left && x < _right && y > _top && y < _bottom;
|
||||
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
this.instersects = function ( r ) {
|
||||
|
||||
return Math.min( _x2, r.getX2() ) - Math.max( _x1, r.getX1() ) >= 0 && Math.min( _y2, r.getY2() ) - Math.max( _y1, r.getY1() ) >= 0;
|
||||
// return this.contains( r.getLeft(), r.getTop() ) || this.contains( r.getRight(), r.getTop() ) || this.contains( r.getLeft(), r.getBottom() ) || this.contains( r.getRight(), r.getBottom() );
|
||||
|
||||
return Math.min( _right, r.getRight() ) - Math.max( _left, r.getLeft() ) >= 0 && Math.min( _bottom, r.getBottom() ) - Math.max( _top, r.getTop() ) >= 0;
|
||||
|
||||
};
|
||||
|
||||
@@ -154,8 +155,8 @@ THREE.Rectangle = function () {
|
||||
|
||||
_isEmpty = true;
|
||||
|
||||
_x1 = 0; _y1 = 0;
|
||||
_x2 = 0; _y2 = 0;
|
||||
_left = 0; _top = 0;
|
||||
_right = 0; _bottom = 0;
|
||||
|
||||
resize();
|
||||
|
||||
@@ -169,7 +170,7 @@ THREE.Rectangle = function () {
|
||||
|
||||
this.toString = function () {
|
||||
|
||||
return "THREE.Rectangle (x1: " + _x1 + ", y1: " + _y2 + ", x2: " + _x2 + ", y1: " + _y1 + ", width: " + _width + ", height: " + _height + ")";
|
||||
return "THREE.Rectangle ( left: " + _left + ", right: " + _right + ", top: " + _top + ", bottom: " + _bottom + ", width: " + _width + ", height: " + _height + " )";
|
||||
|
||||
};
|
||||
|
||||
|
||||
+549
-510
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ def save(operator, context, filepath="", use_modifiers=True, use_normals=True, u
|
||||
# incase
|
||||
color = uvcoord = uvcoord_key = normal = normal_key = None
|
||||
|
||||
file.write('// Generated with Blender 2.54 exporter\n')
|
||||
file.write('// Generated with Blender exporter (compatible with Blender 2.54 / 2.55)\n')
|
||||
file.write('// http://github.com/mrdoob/three.js/tree/master/utils/exporters/blender\n\n')
|
||||
|
||||
file.write('var %s = function () {\n\n' % classname)
|
||||
|
||||
@@ -37,6 +37,9 @@ class ExportTHREEJSSlim(bpy.types.Operator, ExportHelper):
|
||||
use_modifiers = BoolProperty(name="Apply Modifiers", description="Apply modifiers to the exported mesh", default=True)
|
||||
use_normals = BoolProperty(name="Normals", description="Export normals", default=True)
|
||||
use_uv_coords = BoolProperty(name="UVs", description="Export texture coordinates", default=True)
|
||||
|
||||
align_types = [("None","None","None"), ("Center","Center","Center"), ("Bottom","Bottom","Bottom"), ("Top","Top","Top")]
|
||||
align_model = EnumProperty(name="Align model", description="Align model", items=align_types, default="Center")
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
@@ -57,9 +60,12 @@ class ExportTHREEJSSlim(bpy.types.Operator, ExportHelper):
|
||||
|
||||
row = layout.row()
|
||||
row.prop(self.properties, "use_modifiers")
|
||||
row = layout.row()
|
||||
row.prop(self.properties, "use_normals")
|
||||
row = layout.row()
|
||||
row.prop(self.properties, "use_uv_coords")
|
||||
row = layout.row()
|
||||
row.prop(self.properties, "align_model")
|
||||
|
||||
|
||||
def menu_func(self, context):
|
||||
|
||||
+126
-35
@@ -41,9 +41,6 @@ import random
|
||||
# #####################################################
|
||||
# Configuration
|
||||
# #####################################################
|
||||
ALIGN = "center" # center bottom top none
|
||||
SHADING = "smooth" # smooth flat
|
||||
TYPE = "ascii" # ascii binary
|
||||
|
||||
# default colors for debugging (each material gets one distinct color):
|
||||
# white, red, green, blue, yellow, cyan, magenta
|
||||
@@ -58,7 +55,7 @@ TEMPLATE_FILE_ASCII = """\
|
||||
// faces: %(nface)d
|
||||
// materials: %(nmaterial)d
|
||||
//
|
||||
// Generated with Blender 2.54 slim exporter
|
||||
// Generated with Blender slim exporter (compatible with Blender 2.54 / 2.55)
|
||||
// https://github.com/alteredq/three.js/tree/master/utils/exporters/blender/
|
||||
|
||||
|
||||
@@ -131,6 +128,84 @@ def get_uv_indices(f, uvs, mesh):
|
||||
uv.append( uvs[veckey2d(i)] )
|
||||
return uv
|
||||
|
||||
# #####################################################
|
||||
# Alignment
|
||||
# #####################################################
|
||||
def bbox(vertices):
|
||||
"""Compute bounding box of vertex array.
|
||||
"""
|
||||
|
||||
if len(vertices)>0:
|
||||
minx = maxx = vertices[0].co.x
|
||||
miny = maxy = vertices[0].co.y
|
||||
minz = maxz = vertices[0].co.z
|
||||
|
||||
for v in vertices[1:]:
|
||||
if v.co.x < minx:
|
||||
minx = v.co.x
|
||||
elif v.co.x > maxx:
|
||||
maxx = v.co.x
|
||||
|
||||
if v.co.y < miny:
|
||||
miny = v.co.y
|
||||
elif v.co.y > maxy:
|
||||
maxy = v.co.y
|
||||
|
||||
if v.co.z < minz:
|
||||
minz = v.co.z
|
||||
elif v.co.z > maxz:
|
||||
maxz = v.co.z
|
||||
|
||||
return { 'x':[minx,maxx], 'y':[miny,maxy], 'z':[minz,maxz] }
|
||||
|
||||
else:
|
||||
return { 'x':[0,0], 'y':[0,0], 'z':[0,0] }
|
||||
|
||||
def translate(vertices, t):
|
||||
"""Translate array of vertices by vector t.
|
||||
"""
|
||||
|
||||
for i in range(len(vertices)):
|
||||
vertices[i].co.x += t[0]
|
||||
vertices[i].co.y += t[1]
|
||||
vertices[i].co.z += t[2]
|
||||
|
||||
def center(vertices):
|
||||
"""Center model (middle of bounding box).
|
||||
"""
|
||||
|
||||
bb = bbox(vertices)
|
||||
|
||||
cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
|
||||
cy = bb['y'][0] + (bb['y'][1] - bb['y'][0])/2.0
|
||||
cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
|
||||
|
||||
translate(vertices, [-cx,-cy,-cz])
|
||||
|
||||
def top(vertices):
|
||||
"""Align top of the model with the floor (Y-axis) and center it around X and Z.
|
||||
"""
|
||||
|
||||
bb = bbox(vertices)
|
||||
|
||||
cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
|
||||
cy = bb['y'][1]
|
||||
cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
|
||||
|
||||
translate(vertices, [-cx,-cy,-cz])
|
||||
|
||||
def bottom(vertices):
|
||||
"""Align bottom of the model with the floor (Y-axis) and center it around X and Z.
|
||||
"""
|
||||
|
||||
bb = bbox(vertices)
|
||||
|
||||
cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
|
||||
cy = bb['y'][0]
|
||||
cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
|
||||
|
||||
translate(vertices, [-cx,-cy,-cz])
|
||||
|
||||
# #####################################################
|
||||
# Elements
|
||||
# #####################################################
|
||||
@@ -378,31 +453,32 @@ def extract_materials(mesh, scene):
|
||||
|
||||
materials = {}
|
||||
for m in mesh.materials:
|
||||
materials[m.name] = {}
|
||||
materials[m.name]['col_diffuse'] = [m.diffuse_intensity * m.diffuse_color[0],
|
||||
m.diffuse_intensity * m.diffuse_color[1],
|
||||
m.diffuse_intensity * m.diffuse_color[2]]
|
||||
|
||||
materials[m.name]['col_specular'] = [m.specular_intensity * m.specular_color[0],
|
||||
m.specular_intensity * m.specular_color[1],
|
||||
m.specular_intensity * m.specular_color[2]]
|
||||
|
||||
materials[m.name]['col_ambient'] = [m.ambient * world.ambient_color[0],
|
||||
m.ambient * world.ambient_color[1],
|
||||
m.ambient * world.ambient_color[2]]
|
||||
|
||||
materials[m.name]['transparency'] = m.alpha
|
||||
|
||||
# not sure about mapping values to Blinn-Phong shader
|
||||
# Blender uses INT from [1,511] with default 0
|
||||
# http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
|
||||
materials[m.name]["specular_coef"] = m.specular_hardness
|
||||
|
||||
if m.active_texture:
|
||||
fn = bpy.path.abspath(m.active_texture.image.filepath)
|
||||
fn = os.path.normpath(fn)
|
||||
fn_strip = os.path.basename(fn)
|
||||
materials[m.name]['map_diffuse'] = fn_strip
|
||||
if m:
|
||||
materials[m.name] = {}
|
||||
materials[m.name]['col_diffuse'] = [m.diffuse_intensity * m.diffuse_color[0],
|
||||
m.diffuse_intensity * m.diffuse_color[1],
|
||||
m.diffuse_intensity * m.diffuse_color[2]]
|
||||
|
||||
materials[m.name]['col_specular'] = [m.specular_intensity * m.specular_color[0],
|
||||
m.specular_intensity * m.specular_color[1],
|
||||
m.specular_intensity * m.specular_color[2]]
|
||||
|
||||
materials[m.name]['col_ambient'] = [m.ambient * world.ambient_color[0],
|
||||
m.ambient * world.ambient_color[1],
|
||||
m.ambient * world.ambient_color[2]]
|
||||
|
||||
materials[m.name]['transparency'] = m.alpha
|
||||
|
||||
# not sure about mapping values to Blinn-Phong shader
|
||||
# Blender uses INT from [1,511] with default 0
|
||||
# http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
|
||||
materials[m.name]["specular_coef"] = m.specular_hardness
|
||||
|
||||
if m.active_texture and m.active_texture.type == 'IMAGE':
|
||||
fn = bpy.path.abspath(m.active_texture.image.filepath)
|
||||
fn = os.path.normpath(fn)
|
||||
fn_strip = os.path.basename(fn)
|
||||
materials[m.name]['map_diffuse'] = fn_strip
|
||||
|
||||
return materials
|
||||
|
||||
@@ -411,8 +487,13 @@ def generate_materials_string(mesh, scene):
|
||||
random.seed(42) # to get well defined color order for debug materials
|
||||
|
||||
materials = {}
|
||||
for i, m in enumerate(mesh.materials):
|
||||
materials[m.name] = i
|
||||
if mesh.materials:
|
||||
for i, m in enumerate(mesh.materials):
|
||||
if m:
|
||||
materials[m.name] = i
|
||||
else:
|
||||
materials["undefined_dummy_%0d" % i] = i
|
||||
|
||||
|
||||
if not materials:
|
||||
materials = { 'default':0 }
|
||||
@@ -428,14 +509,24 @@ def generate_materials_string(mesh, scene):
|
||||
# #####################################################
|
||||
# ASCII exporter
|
||||
# #####################################################
|
||||
def generate_ascii_model(mesh, scene, use_normals, use_uv_coords):
|
||||
def generate_ascii_model(mesh, scene, use_normals, use_uv_coords, align_model):
|
||||
|
||||
vertices = mesh.vertices[:]
|
||||
|
||||
if align_model == 1:
|
||||
center(vertices)
|
||||
elif align_model == 2:
|
||||
bottom(vertices)
|
||||
elif align_model == 3:
|
||||
top(vertices)
|
||||
|
||||
sfaces = sort_faces(mesh.faces, use_normals, use_uv_coords)
|
||||
|
||||
normals = extract_vertex_normals(mesh, use_normals)
|
||||
uvs = extract_uvs(mesh, use_uv_coords)
|
||||
|
||||
text = TEMPLATE_FILE_ASCII % {
|
||||
"vertices" : ",".join(generate_vertex(v) for v in mesh.vertices),
|
||||
"vertices" : ",".join(generate_vertex(v) for v in vertices),
|
||||
|
||||
"triangles" : ",".join(generate_triangle(f) for f in sfaces['triangles_flat']),
|
||||
"triangles_n" : ",".join(generate_triangle_n(f, normals, mesh) for f in sfaces['triangles_smooth']),
|
||||
@@ -462,7 +553,7 @@ def generate_ascii_model(mesh, scene, use_normals, use_uv_coords):
|
||||
# #####################################################
|
||||
# Main
|
||||
# #####################################################
|
||||
def save(operator, context, filepath="", use_modifiers=True, use_normals=True, use_uv_coords=True):
|
||||
def save(operator, context, filepath="", use_modifiers=True, use_normals=True, use_uv_coords=True, align_model=1):
|
||||
|
||||
def rvec3d(v):
|
||||
return round(v[0], 6), round(v[1], 6), round(v[2], 6)
|
||||
@@ -508,7 +599,7 @@ def save(operator, context, filepath="", use_modifiers=True, use_normals=True, u
|
||||
if not active_uv_layer:
|
||||
use_uv_coords = False
|
||||
|
||||
text = generate_ascii_model(mesh, scene, use_normals, use_uv_coords)
|
||||
text = generate_ascii_model(mesh, scene, use_normals, use_uv_coords, align_model)
|
||||
file = open(filepath, 'w')
|
||||
file.write(text)
|
||||
file.close()
|
||||
|
||||
@@ -393,7 +393,7 @@ def bottom(vertices):
|
||||
cy = bb['y'][0]
|
||||
cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
|
||||
|
||||
translate(vertices, [-cx,cy,-cz])
|
||||
translate(vertices, [-cx,-cy,-cz])
|
||||
|
||||
def normalize(v):
|
||||
"""Normalize 3d vector"""
|
||||
|
||||
@@ -314,7 +314,7 @@ def bottom(vertices):
|
||||
cy = bb['y'][0]
|
||||
cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
|
||||
|
||||
translate(vertices, [-cx,cy,-cz])
|
||||
translate(vertices, [-cx,-cy,-cz])
|
||||
|
||||
def normalize(v):
|
||||
"""Normalize 3d vector"""
|
||||
|
||||
Reference in New Issue
Block a user