Three.js: allow to configure projRight/projUp.

Also, use a more appealing isometric projection if none specified,
instead of orthographic.

Also, use the scale, offset and projection from the viewport at
the time of export.
pull/10/head
whitequark 2016-06-11 23:08:12 +00:00
parent 44223ea332
commit afafa5ec2e
2 changed files with 40 additions and 6 deletions

View File

@ -327,7 +327,7 @@ SolvespaceControls.prototype.constructor = SolvespaceControls;
solvespace = function(obj, params) { solvespace = function(obj, params) {
var scene, edgeScene, camera, edgeCamera, renderer; var scene, edgeScene, camera, edgeCamera, renderer;
var geometry, controls, material, mesh, edges; var geometry, controls, material, mesh, edges;
var width, height; var width, height, scale, offset, projRight, projUp;
var directionalLightArray = []; var directionalLightArray = [];
if (typeof params === "undefined" || !("width" in params)) { if (typeof params === "undefined" || !("width" in params)) {
@ -342,7 +342,32 @@ solvespace = function(obj, params) {
height = params.height; height = params.height;
} }
if (typeof params === "undefined" || !("scale" in params)) {
scale = 5;
} else {
scale = params.scale;
}
if (typeof params === "undefined" || !("offset" in params)) {
offset = new THREE.Vector3(0, 0, 0);
} else {
offset = params.offset;
}
if (typeof params === "undefined" || !("projUp" in params)) {
projUp = new THREE.Vector3(0, 1, -1);
} else {
projUp = params.projUp;
}
if (typeof params === "undefined" || !("projRight" in params)) {
projRight = new THREE.Vector3(1, 0, -1);
} else {
projRight = params.projRight;
}
domElement = init(); domElement = init();
lightUpdate();
render(); render();
return domElement; return domElement;
@ -351,9 +376,8 @@ solvespace = function(obj, params) {
scene = new THREE.Scene(); scene = new THREE.Scene();
edgeScene = new THREE.Scene(); edgeScene = new THREE.Scene();
camera = new SolvespaceCamera(width, camera = new SolvespaceCamera(width, height, scale, projUp, projRight, offset);
height, 5, new THREE.Vector3(0, 1, 0), camera.NormalizeProjectionVectors();
new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 0));
mesh = createMesh(obj); mesh = createMesh(obj);
scene.add(mesh); scene.add(mesh);

View File

@ -860,7 +860,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
<script> <script>
)"; )";
const char htmlend[] = R"( const char htmlend[] = R"(
document.body.appendChild(solvespace(solvespace_model_%s)); document.body.appendChild(solvespace(solvespace_model_%s, {
scale: %g,
offset: new THREE.Vector3(%g, %g, %g),
projUp: new THREE.Vector3(%g, %g, %g),
projRight: new THREE.Vector3(%g, %g, %g)
}));
</script> </script>
</body> </body>
</html> </html>
@ -1001,7 +1006,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
fputs(" ]\n};\n", f); fputs(" ]\n};\n", f);
if(extension == "html") if(extension == "html")
fprintf(f, htmlend, baseFilename.c_str()); fprintf(f, htmlend,
baseFilename.c_str(),
SS.GW.scale,
CO(SS.GW.offset),
CO(SS.GW.projUp),
CO(SS.GW.projRight));
spl.Clear(); spl.Clear();
} }