Server-side threejs rendering
This commit is contained in:
parent
f4e06c9c28
commit
c0d8d6292c
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
|
||||
function pad(n, width, z) {
|
||||
z = z || '0';
|
||||
n = n + '';
|
||||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||||
}
|
||||
|
||||
let fs = require('fs');
|
||||
let THREE = require('./three.js');
|
||||
|
||||
let width = Math.floor(1134);
|
||||
let height = Math.floor(768);
|
||||
|
||||
let renderer = new THREE.CanvasRenderer();
|
||||
renderer.domElement.style = renderer.domElement;
|
||||
renderer.setSize(width,height);
|
||||
renderer.setClearColor(0x000000);
|
||||
|
||||
let scene = new THREE.Scene();
|
||||
|
||||
let camera = new THREE.PerspectiveCamera(75, width / height, 1, 10000);
|
||||
camera.position.z = 1000;
|
||||
|
||||
let geometry = new THREE.BoxGeometry(200, 200, 200);
|
||||
let material = new THREE.MeshBasicMaterial({color: 0xff0000});
|
||||
|
||||
let mesh = new THREE.Mesh(geometry, material);
|
||||
scene.add(mesh);
|
||||
scene.add(camera);
|
||||
|
||||
let counter = 0;
|
||||
for (let i = 0; i < 1; i += 0.005) {
|
||||
|
||||
mesh.rotation.x = i * 2 * Math.PI;
|
||||
mesh.rotation.y = i * Math.PI;
|
||||
|
||||
camera.lookAt(new THREE.Vector3());
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
console.log(i);
|
||||
fs.writeFileSync(__dirname + '/' + pad(counter++, 4) + '.png', renderer.domElement.toBuffer());
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -457,18 +457,7 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
|
||||
// console.log('Time to generate chunk : ' + (Date.now() - oldTime) + 'ms');
|
||||
|
||||
if (next.data.length === 0) {
|
||||
|
||||
// If nothing, just serve stuff
|
||||
var tmp = self.nextElements([
|
||||
// {
|
||||
// proportion: 1,
|
||||
// frustum: cameraFrustum
|
||||
// }
|
||||
]);
|
||||
next.data = tmp.data;
|
||||
|
||||
} else if (!self.prefetch && next.size < this.chunk) {
|
||||
if (self.prefetch && next.size < self.chunk) {
|
||||
|
||||
// Recompute config
|
||||
var newConfig = [];
|
||||
|
@ -477,7 +466,7 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
for (var i = 0; i < config.length; i++) {
|
||||
|
||||
// Check if config was full
|
||||
if (next.configSizes[i] < this.chunk * config[i].proportion) {
|
||||
if (next.configSizes[i] >= self.chunk * config[i].proportion) {
|
||||
|
||||
newConfig.push(config[i]);
|
||||
sum += config[i].proportion;
|
||||
|
@ -494,12 +483,32 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
|
||||
// Normalize config probabilities
|
||||
|
||||
var newData = self.nextElements(newConfig, this.chunk - next.size);
|
||||
var newData = self.nextElements(newConfig, self.chunk - next.size);
|
||||
|
||||
next.data = next.data.push.apply(next.data, newData.data);
|
||||
next.data.push.apply(next.data, newData.data);
|
||||
|
||||
// console.log('Adding ' + newData.size + ' for newConfig : ' + JSON.stringify(newConfig.map(function(o) { return o.proportion})));
|
||||
|
||||
next.size = next.size + newData.size;
|
||||
|
||||
}
|
||||
|
||||
if (next.data.length === 0) {
|
||||
|
||||
// If nothing, just serve stuff
|
||||
var tmp = self.nextElements([
|
||||
// {
|
||||
// proportion: 1,
|
||||
// frustum: cameraFrustum
|
||||
// }
|
||||
]);
|
||||
next.data = tmp.data;
|
||||
next.size = tmp.size;
|
||||
|
||||
}
|
||||
|
||||
// console.log('Chunk of size ' + next.size);
|
||||
|
||||
socket.emit('elements', next.data);
|
||||
|
||||
if (next.finished) {
|
||||
|
@ -599,7 +608,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
|
||||
var currentConfig = config[configIndex];
|
||||
|
||||
if ( configSizes[configIndex] < chunk * currentConfig.proportion) {
|
||||
if (configSizes[configIndex] < chunk * currentConfig.proportion) {
|
||||
|
||||
var display = false;
|
||||
var exitToContinue = false;
|
||||
|
@ -614,6 +623,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
data.push(vertex1.toList());
|
||||
this.vertices[currentFace.a] = true;
|
||||
configSizes[configIndex]++;
|
||||
totalSize++;
|
||||
|
||||
}
|
||||
|
||||
|
@ -622,6 +632,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
data.push(vertex2.toList());
|
||||
this.vertices[currentFace.b] = true;
|
||||
configSizes[configIndex]++;
|
||||
totalSize++;
|
||||
|
||||
}
|
||||
|
||||
|
@ -630,6 +641,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
data.push(vertex3.toList());
|
||||
this.vertices[currentFace.c] = true;
|
||||
configSizes[configIndex]++;
|
||||
totalSize++;
|
||||
|
||||
}
|
||||
|
||||
|
@ -714,6 +726,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
continue faceloop;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (totalSize > chunk) {
|
||||
|
@ -727,7 +740,7 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
|||
|
||||
}
|
||||
|
||||
return {data: data, finished: mightBeCompletetlyFinished, configSizes: configSizes};
|
||||
return {data: data, finished: mightBeCompletetlyFinished, configSizes: configSizes, size:totalSize};
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue