From afafa5ec2e390555b5d331ea34c9d3546d86fd8c Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 11 Jun 2016 23:08:12 +0000 Subject: [PATCH] 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. --- res/threejs/SolveSpaceControls.js | 32 +++++++++++++++++++++++++++---- src/export.cpp | 14 ++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/res/threejs/SolveSpaceControls.js b/res/threejs/SolveSpaceControls.js index f445a05c..c0875357 100644 --- a/res/threejs/SolveSpaceControls.js +++ b/res/threejs/SolveSpaceControls.js @@ -327,7 +327,7 @@ SolvespaceControls.prototype.constructor = SolvespaceControls; solvespace = function(obj, params) { var scene, edgeScene, camera, edgeCamera, renderer; var geometry, controls, material, mesh, edges; - var width, height; + var width, height, scale, offset, projRight, projUp; var directionalLightArray = []; if (typeof params === "undefined" || !("width" in params)) { @@ -342,7 +342,32 @@ solvespace = function(obj, params) { 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(); + lightUpdate(); render(); return domElement; @@ -351,9 +376,8 @@ solvespace = function(obj, params) { scene = new THREE.Scene(); edgeScene = new THREE.Scene(); - camera = new SolvespaceCamera(width, - height, 5, new THREE.Vector3(0, 1, 0), - new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 0)); + camera = new SolvespaceCamera(width, height, scale, projUp, projRight, offset); + camera.NormalizeProjectionVectors(); mesh = createMesh(obj); scene.add(mesh); diff --git a/src/export.cpp b/src/export.cpp index 20fca2e5..dd7df394 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -860,7 +860,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, @@ -1001,7 +1006,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, fputs(" ]\n};\n", f); 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(); }