This commit is contained in:
Thomas FORGIONE 2015-06-18 15:03:06 +02:00
parent 547162e9bb
commit 9c9232d57b
3 changed files with 81 additions and 45 deletions

View File

@ -169,24 +169,30 @@ geo.MeshStreamer.prototype.start = function(socket) {
geo.MeshStreamer.prototype.nextElements = function(_camera) { geo.MeshStreamer.prototype.nextElements = function(_camera) {
// Prepare camera (and scale to model) // Prepare camera (and scale to model)
var camera = { var camera = null;
position: {
x: _camera[0]*10, if (_camera !== null) {
y: _camera[1]*10,
z: _camera[2]*10 var camera = {
}, position: {
target: { x: _camera[0],
x: _camera[3]*10, y: _camera[1],
y: _camera[4]*10, z: _camera[2]
z: _camera[5]*10 },
} target: {
} x: _camera[3],
y: _camera[4],
z: _camera[5]
}
}
// Compute camera direction
var direction = {
x: camera.target.x - camera.position.x,
y: camera.target.y - camera.position.y,
z: camera.target.z - camera.position.z
}
// Compute camera direction
var direction = {
x: camera.target.x - camera.position.x,
y: camera.target.y - camera.position.y,
z: camera.target.z - camera.position.z
} }
var sent = 0; var sent = 0;
@ -239,31 +245,35 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
var vertex2 = this.vertices[currentFace.b]; var vertex2 = this.vertices[currentFace.b];
var vertex3 = this.vertices[currentFace.c]; var vertex3 = this.vertices[currentFace.c];
var v1 = { if (camera !== null) {
x: vertex1.x - camera.position.x,
y: vertex1.y - camera.position.y,
z: vertex1.z - camera.position.z
};
var v2 = { var v1 = {
x: vertex2.x - camera.position.x, x: vertex1.x - camera.position.x,
y: vertex2.y - camera.position.y, y: vertex1.y - camera.position.y,
z: vertex2.z - camera.position.z z: vertex1.z - camera.position.z
}; };
var v3 = { var v2 = {
x: vertex3.x - camera.position.x, x: vertex2.x - camera.position.x,
y: vertex3.y - camera.position.y, y: vertex2.y - camera.position.y,
z: vertex3.z - camera.position.z z: vertex2.z - camera.position.z
}; };
if ( var v3 = {
direction.x * v1.x + direction.y * v1.y + direction.z * v1.z < 0 && x: vertex3.x - camera.position.x,
direction.x * v2.x + direction.y * v2.y + direction.z * v2.z < 0 && y: vertex3.y - camera.position.y,
z: vertex3.z - camera.position.z
};
if (
direction.x * v1.x + direction.y * v1.y + direction.z * v1.z < 0 &&
direction.x * v2.x + direction.y * v2.y + direction.z * v2.z < 0 &&
direction.x * v3.x + direction.y * v3.y + direction.z * v3.z < 0 direction.x * v3.x + direction.y * v3.y + direction.z * v3.z < 0
) { ) {
continue; continue;
}
} }

View File

@ -13,7 +13,7 @@ function addLight(scene) {
function initPeachCastle(scene, collidableObjects, loader, camera) { function initPeachCastle(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader( var loader = new ProgressiveLoaderGeometry(
'/static/data/castle/princess peaches castle (outside).obj', '/static/data/castle/princess peaches castle (outside).obj',
scene, scene,
camera, camera,
@ -164,10 +164,10 @@ function createPeachCameras(width, height) {
function initBobombScene(scene, collidableObjects, loader, camera) { function initBobombScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader( var loader = new ProgressiveLoaderGeometry(
static_path + 'data/bobomb/bobomb battlefeild.obj', static_path + 'data/bobomb/bobomb battlefeild.obj',
scene, scene,
camera, null,
function(object) { function(object) {
object.raycastable = true; object.raycastable = true;
if (object.material.name === 'Material.071_574B138E_c.bmp' || if (object.material.name === 'Material.071_574B138E_c.bmp' ||
@ -310,10 +310,10 @@ function initBobomb(camera, scene, static_path, coins) {
function initWhompScene(scene, collidableObjects, loader, camera) { function initWhompScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader( var loader = new ProgressiveLoaderGeometry(
static_path + 'data/whomp/Whomps Fortress.obj', static_path + 'data/whomp/Whomps Fortress.obj',
scene, scene,
camera, null,
function(object) { function(object) {
if (object.material.name === 'Shape_088' || if (object.material.name === 'Shape_088' ||
object.material.name === 'Shape_089') { object.material.name === 'Shape_089') {
@ -336,6 +336,18 @@ function initWhompScene(scene, collidableObjects, loader, camera) {
loader.obj.rotation.x = -Math.PI/2; loader.obj.rotation.x = -Math.PI/2;
loader.obj.rotation.z = Math.PI/2; loader.obj.rotation.z = Math.PI/2;
loader.obj.scale.set(0.1,0.1,0.1); loader.obj.scale.set(0.1,0.1,0.1);
loader.getCamera = function() {
return [
loader.camera.position.z * 10,
loader.camera.position.x * 10,
loader.camera.position.y * 10,
loader.camera.target.z * 10,
loader.camera.target.x * 10,
loader.camera.target.y * 10
];
}
collidableObjects.push(loader.obj); collidableObjects.push(loader.obj);
loader.obj.raycastable = true; loader.obj.raycastable = true;
} }
@ -461,10 +473,10 @@ function initWhomp(camera, scene, static_path, coins) {
function initMountainScene(scene, collidableObjects, loader, camera) { function initMountainScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader( var loader = new ProgressiveLoaderGeometry(
static_path + 'data/mountain/coocoolmountain.obj', static_path + 'data/mountain/coocoolmountain.obj',
scene, scene,
camera, null,
function(object) { function(object) {
// object.rotation.x = -Math.PI/2; // object.rotation.x = -Math.PI/2;
// object.rotation.z = Math.PI/2; // object.rotation.z = Math.PI/2;
@ -628,11 +640,25 @@ function initSponzaScene(scene, collidableObjects, loader, camera) {
l = loader; l = loader;
loader.load(); loader.load();
loader.getCamera = function() {
return [
loader.camera.position.x * 10,
loader.camera.position.y * 10,
loader.camera.position.z * 10,
loader.camera.target.x * 10,
loader.camera.target.y * 10,
loader.camera.target.z * 10
];
}
loader.obj.scale.set(0.1,0.1,0.1); loader.obj.scale.set(0.1,0.1,0.1);
collidableObjects.push(loader.obj); collidableObjects.push(loader.obj);
loader.obj.raycastable = true; loader.obj.raycastable = true;
// ProgressiveLoader('/static/data/sponza/sponza.obj', scene, // ProgressiveLoader('/static/data/sponza/sponza.obj', scene,
// function(obj) { // function(obj) {
// obj.scale.set(0.1,0.1,0.1); // obj.scale.set(0.1,0.1,0.1);

View File

@ -45,7 +45,7 @@ function init() {
// Load the scene // Load the scene
// loader = new THREE.OBJLoader(); // loader = new THREE.OBJLoader();
sphereLoader = new ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene); sphereLoader = new ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene, camera);
sphereLoader.load(); sphereLoader.load();
sphere = sphereLoader.obj; sphere = sphereLoader.obj;