apply workspace unit scale to dropped loaded STLs
This commit is contained in:
parent
40dbbd2e60
commit
f10879edda
7 changed files with 39 additions and 18 deletions
9
app.js
9
app.js
|
|
@ -22,6 +22,7 @@ const synth = {};
|
||||||
const api = {};
|
const api = {};
|
||||||
|
|
||||||
let level;
|
let level;
|
||||||
|
let setupFn;
|
||||||
let cacheDir;
|
let cacheDir;
|
||||||
let startTime;
|
let startTime;
|
||||||
let lastmod;
|
let lastmod;
|
||||||
|
|
@ -73,6 +74,7 @@ function init(mod) {
|
||||||
return vmatch.indexOf(cookie) >= 0;
|
return vmatch.indexOf(cookie) >= 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mod.add(handleSetup);
|
||||||
mod.add(handleOptions);
|
mod.add(handleOptions);
|
||||||
mod.add(fullpath({
|
mod.add(fullpath({
|
||||||
"/kiri" : redir("/kiri/", 301),
|
"/kiri" : redir("/kiri/", 301),
|
||||||
|
|
@ -212,7 +214,8 @@ function initModule(mod, file, dir) {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
redir: redir,
|
redir: redir,
|
||||||
remap: remap
|
remap: remap,
|
||||||
|
setup: fn => { setupFn = fn }
|
||||||
},
|
},
|
||||||
handler: {
|
handler: {
|
||||||
addCORS: addCorsHeaders,
|
addCORS: addCorsHeaders,
|
||||||
|
|
@ -428,6 +431,10 @@ function string2obj(s) {
|
||||||
return JSON.parse(s);
|
return JSON.parse(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSetup(req, res, next) {
|
||||||
|
if (setupFn) setupFn(req, res, next);
|
||||||
|
}
|
||||||
|
|
||||||
function handleVersion(req, res, next) {
|
function handleVersion(req, res, next) {
|
||||||
if (req.app.path === "/kiri/" && req.url.indexOf(version) < 0) {
|
if (req.app.path === "/kiri/" && req.url.indexOf(version) < 0) {
|
||||||
if (req.url.indexOf("?") > 0) {
|
if (req.url.indexOf("?") > 0) {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,10 @@
|
||||||
js2o = API.js2o,
|
js2o = API.js2o,
|
||||||
o2js = API.o2js,
|
o2js = API.o2js,
|
||||||
platform = API.platform,
|
platform = API.platform,
|
||||||
selection = API.selection;
|
selection = API.selection,
|
||||||
|
proto = location.protocol,
|
||||||
|
root = "grid.space",
|
||||||
|
ver = Date.now().toString(36);
|
||||||
|
|
||||||
let currentDevice = null,
|
let currentDevice = null,
|
||||||
deviceURL = null,
|
deviceURL = null,
|
||||||
|
|
@ -1331,6 +1334,8 @@
|
||||||
function init_one() {
|
function init_one() {
|
||||||
API.event.emit('init.one');
|
API.event.emit('init.one');
|
||||||
|
|
||||||
|
$('gsbox').src = `${proto}//${root}/kiri/gsbox.png?ver=${ver}`;
|
||||||
|
|
||||||
// ensure we have settings from last session
|
// ensure we have settings from last session
|
||||||
API.conf.restore();
|
API.conf.restore();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1413,6 +1413,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function platformLoadSTL(url, onload, formdata) {
|
function platformLoadSTL(url, onload, formdata) {
|
||||||
|
let scale = 1 / unitScale();
|
||||||
new MOTO.STL().load(url, function(vertices, filename) {
|
new MOTO.STL().load(url, function(vertices, filename) {
|
||||||
if (vertices) {
|
if (vertices) {
|
||||||
let widget = newWidget().loadVertices(vertices);
|
let widget = newWidget().loadVertices(vertices);
|
||||||
|
|
@ -1422,7 +1423,7 @@
|
||||||
onload(vertices, widget);
|
onload(vertices, widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, formdata);
|
}, formdata, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
function platformComputeMaxZ() {
|
function platformComputeMaxZ() {
|
||||||
|
|
@ -1888,9 +1889,10 @@
|
||||||
if (API.feature.on_add_stl) {
|
if (API.feature.on_add_stl) {
|
||||||
API.feature.on_add_stl(e.target.result, file);
|
API.feature.on_add_stl(e.target.result, file);
|
||||||
} else {
|
} else {
|
||||||
|
let scale = unitScale();
|
||||||
platform.add(
|
platform.add(
|
||||||
newWidget(undefined,group)
|
newWidget(undefined,group)
|
||||||
.loadVertices(new MOTO.STL().parse(e.target.result))
|
.loadVertices(new MOTO.STL().parse(e.target.result,scale))
|
||||||
.saveToCatalog(e.target.file.name)
|
.saveToCatalog(e.target.file.name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SP.load = function(url, callback, formdata) {
|
SP.load = function(url, callback, formdata, scale) {
|
||||||
let stl = this,
|
let stl = this,
|
||||||
xhr = new XMLHttpRequest();
|
xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
function onloaded (event) {
|
function onloaded (event) {
|
||||||
if (event.target.status === 200 || event.target.status === 0) {
|
if (event.target.status === 200 || event.target.status === 0) {
|
||||||
stl.parse(event.target.response || event.target.responseText);
|
stl.parse(event.target.response || event.target.responseText, scale);
|
||||||
let cd = undefined;
|
let cd = undefined;
|
||||||
if (xhr.getAllResponseHeaders().indexOf(CDH) > 0) {
|
if (xhr.getAllResponseHeaders().indexOf(CDH) > 0) {
|
||||||
cd = xhr.getResponseHeader(CDH)
|
cd = xhr.getResponseHeader(CDH)
|
||||||
|
|
@ -107,7 +107,7 @@
|
||||||
return bin;
|
return bin;
|
||||||
};
|
};
|
||||||
|
|
||||||
SP.parse = function(data) {
|
SP.parse = function(data, scale) {
|
||||||
let binData = this.convertToBinary(data);
|
let binData = this.convertToBinary(data);
|
||||||
|
|
||||||
let isBinary = function () {
|
let isBinary = function () {
|
||||||
|
|
@ -120,11 +120,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
return isBinary()
|
return isBinary()
|
||||||
? this.parseBinary(binData)
|
? this.parseBinary(binData, scale)
|
||||||
: this.parseASCII(this.convertToString(data));
|
: this.parseASCII(this.convertToString(data), scale);
|
||||||
};
|
};
|
||||||
|
|
||||||
SP.parseBinary = function(data) {
|
SP.parseBinary = function(data, scale = 1) {
|
||||||
let reader = new DataView(data),
|
let reader = new DataView(data),
|
||||||
faces = reader.getUint32 (80, true),
|
faces = reader.getUint32 (80, true),
|
||||||
r, g, b, hasColors = false, colors,
|
r, g, b, hasColors = false, colors,
|
||||||
|
|
@ -176,9 +176,9 @@
|
||||||
|
|
||||||
while (i <= 3) {
|
while (i <= 3) {
|
||||||
vertexstart = start + (i++) * 12;
|
vertexstart = start + (i++) * 12;
|
||||||
vertices[offset ] = reader.getFloat32 (vertexstart, true);
|
vertices[offset ] = reader.getFloat32 (vertexstart, true) * scale;
|
||||||
vertices[offset + 1] = reader.getFloat32 (vertexstart + 4, true);
|
vertices[offset + 1] = reader.getFloat32 (vertexstart + 4, true) * scale;
|
||||||
vertices[offset + 2] = reader.getFloat32 (vertexstart + 8, true);
|
vertices[offset + 2] = reader.getFloat32 (vertexstart + 8, true) * scale;
|
||||||
normals[offset ] = normalX;
|
normals[offset ] = normalX;
|
||||||
normals[offset + 1] = normalY;
|
normals[offset + 1] = normalY;
|
||||||
normals[offset + 2] = normalZ;
|
normals[offset + 2] = normalZ;
|
||||||
|
|
@ -198,7 +198,7 @@
|
||||||
return vertices;
|
return vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
SP.parseASCII = function(data) {
|
SP.parseASCII = function(data, scale = 1) {
|
||||||
let result,
|
let result,
|
||||||
resultText,
|
resultText,
|
||||||
patternNormal,
|
patternNormal,
|
||||||
|
|
@ -217,9 +217,9 @@
|
||||||
normals.push(parseFloat(result[5]));
|
normals.push(parseFloat(result[5]));
|
||||||
}
|
}
|
||||||
while ((result = patternVertex.exec(resultText)) !== null) {
|
while ((result = patternVertex.exec(resultText)) !== null) {
|
||||||
vertices.push(parseFloat(result[1]));
|
vertices.push(parseFloat(result[1]) * scale);
|
||||||
vertices.push(parseFloat(result[3]));
|
vertices.push(parseFloat(result[3]) * scale);
|
||||||
vertices.push(parseFloat(result[5]));
|
vertices.push(parseFloat(result[5]) * scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
web/kiri/gsbox.png
Normal file
BIN
web/kiri/gsbox.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
|
|
@ -27,6 +27,13 @@ a, a:hover, a:visited {
|
||||||
border: 0px;
|
border: 0px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
}
|
}
|
||||||
|
#gsbox {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
padding-right: 15px;
|
||||||
|
position: fixed;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
div {
|
div {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app" class="f-col">
|
<div id="app" class="f-col">
|
||||||
<div id="curtain" class="j-center a-center">loading...</div>
|
<div id="curtain" class="j-center a-center"><img id="gsbox"/>loading...</div>
|
||||||
<div id="container"></div>
|
<div id="container"></div>
|
||||||
<div id="tracker"></div>
|
<div id="tracker"></div>
|
||||||
<div id="top-sep"></div>
|
<div id="top-sep"></div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue