Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: solvespace/solvespace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ffef006b317d
Choose a base ref
...
head repository: solvespace/solvespace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e243396c6f5f
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on May 23, 2019

  1. Copy the full SHA
    e243396 View commit details
Showing with 30 additions and 0 deletions.
  1. +30 −0 res/threejs/SolveSpaceControls.js
30 changes: 30 additions & 0 deletions res/threejs/SolveSpaceControls.js
Original file line number Diff line number Diff line change
@@ -330,15 +330,18 @@ solvespace = function(obj, params) {
var geometry, controls, material, mesh, edges;
var width, height, scale, offset, projRight, projUp;
var directionalLightArray = [];
var inheritedWidth = false, inheritedHeight = false;

if (typeof params === "undefined" || !("width" in params)) {
width = window.innerWidth;
inheritedWidth = true;
} else {
width = params.width;
}

if (typeof params === "undefined" || !("height" in params)) {
height = window.innerHeight;
inheritedHeight = true;
} else {
height = params.height;
}
@@ -409,10 +412,37 @@ solvespace = function(obj, params) {
controls.addEventListener("change", render);
controls.addEventListener("change", lightUpdate);

if(inheritedWidth || inheritedHeight) {
window.addEventListener("resize", resize);
}

animate();
return renderer.domElement;
}

function resize() {
scale = camera.zoomScale;
if(inheritedWidth) {
scale *= window.innerWidth / width;
width = window.innerWidth;
}
if(inheritedHeight) {
scale *= window.innerHeight / height;
height = window.innerHeight;
}

camera.renderWidth = width;
camera.renderHeight = height;
camera.zoomScale = scale;

renderer.setSize(width * window.devicePixelRatio, height * window.devicePixelRatio);
renderer.domElement.style =
"width: " + width + "px;" +
"height: " + height + "px;";

render();
}

function animate() {
requestAnimationFrame(animate);
controls.update();