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,16 +169,20 @@ 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 = null;
if (_camera !== null) {
var camera = { var camera = {
position: { position: {
x: _camera[0]*10, x: _camera[0],
y: _camera[1]*10, y: _camera[1],
z: _camera[2]*10 z: _camera[2]
}, },
target: { target: {
x: _camera[3]*10, x: _camera[3],
y: _camera[4]*10, y: _camera[4],
z: _camera[5]*10 z: _camera[5]
} }
} }
@ -189,6 +193,8 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
z: camera.target.z - camera.position.z z: camera.target.z - camera.position.z
} }
}
var sent = 0; var sent = 0;
var data = []; var data = [];
@ -239,6 +245,8 @@ 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];
if (camera !== null) {
var v1 = { var v1 = {
x: vertex1.x - camera.position.x, x: vertex1.x - camera.position.x,
y: vertex1.y - camera.position.y, y: vertex1.y - camera.position.y,
@ -267,6 +275,8 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
} }
}
if (!vertex1.sent) { if (!vertex1.sent) {
data.push(vertex1.toList()); data.push(vertex1.toList());

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;