FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Three.js: allow to configure projRight/projUp. · ruevs/solvespace@afafa5e · GitHub

Repository navigation

Commit afafa5e

Browse files
committed
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.
1 parent 44223ea commit afafa5e

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

‎res/threejs/SolveSpaceControls.js‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ SolvespaceControls.prototype.constructor = SolvespaceControls;
327327
solvespace = function(obj, params) {
328328
var scene, edgeScene, camera, edgeCamera, renderer;
329329
var geometry, controls, material, mesh, edges;
330-
var width, height;
330+
var width, height, scale, offset, projRight, projUp;
331331
var directionalLightArray = [];
332332

333333
if (typeof params === "undefined" || !("width" in params)) {
@@ -342,7 +342,32 @@ solvespace = function(obj, params) {
342342
height = params.height;
343343
}
344344

345+
if (typeof params === "undefined" || !("scale" in params)) {
346+
scale = 5;
347+
} else {
348+
scale = params.scale;
349+
}
350+
351+
if (typeof params === "undefined" || !("offset" in params)) {
352+
offset = new THREE.Vector3(0, 0, 0);
353+
} else {
354+
offset = params.offset;
355+
}
356+
357+
if (typeof params === "undefined" || !("projUp" in params)) {
358+
projUp = new THREE.Vector3(0, 1, -1);
359+
} else {
360+
projUp = params.projUp;
361+
}
362+
363+
if (typeof params === "undefined" || !("projRight" in params)) {
364+
projRight = new THREE.Vector3(1, 0, -1);
365+
} else {
366+
projRight = params.projRight;
367+
}
368+
345369
domElement = init();
370+
lightUpdate();
346371
render();
347372
return domElement;
348373

@@ -351,9 +376,8 @@ solvespace = function(obj, params) {
351376
scene = new THREE.Scene();
352377
edgeScene = new THREE.Scene();
353378

354-
camera = new SolvespaceCamera(width,
355-
height, 5, new THREE.Vector3(0, 1, 0),
356-
new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 0));
379+
camera = new SolvespaceCamera(width, height, scale, projUp, projRight, offset);
380+
camera.NormalizeProjectionVectors();
357381

358382
mesh = createMesh(obj);
359383
scene.add(mesh);

‎src/export.cpp‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
860860
<script>
861861
)";
862862
const char htmlend[] = R"(
863-
document.body.appendChild(solvespace(solvespace_model_%s));
863+
document.body.appendChild(solvespace(solvespace_model_%s, {
864+
scale: %g,
865+
offset: new THREE.Vector3(%g, %g, %g),
866+
projUp: new THREE.Vector3(%g, %g, %g),
867+
projRight: new THREE.Vector3(%g, %g, %g)
868+
}));
864869
</script>
865870
</body>
866871
</html>
@@ -1001,7 +1006,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
10011006
fputs(" ]\n};\n", f);
10021007

10031008
if(extension == "html")
1004-
fprintf(f, htmlend, baseFilename.c_str());
1009+
fprintf(f, htmlend,
1010+
baseFilename.c_str(),
1011+
SS.GW.scale,
1012+
CO(SS.GW.offset),
1013+
CO(SS.GW.projUp),
1014+
CO(SS.GW.projRight));
10051015

10061016
spl.Clear();
10071017
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL