platform api work

This commit is contained in:
Stewart Allen 2021-12-27 09:00:27 -05:00
commit 7547fe9377
4 changed files with 88 additions and 109 deletions

View file

@ -1457,8 +1457,8 @@
view.update_slider(); view.update_slider();
}); });
SPACE.showSkyGrid(false); SPACE.sky.showGrid(false);
SPACE.setSkyColor(controller.dark ? 0 : 0xffffff); SPACE.sky.setColor(controller.dark ? 0 : 0xffffff);
SPACE.init(container, function (delta) { SPACE.init(container, function (delta) {
let vars = API.var; let vars = API.var;
if (vars.layer_max === 0 || !delta) return; if (vars.layer_max === 0 || !delta) return;

View file

@ -132,8 +132,8 @@
group_done: platformGroupDone, group_done: platformGroupDone,
update: SPACE.platform.update, update: SPACE.platform.update,
set_font: SPACE.platform.setFont, set_font: SPACE.platform.setFont,
set_axes: SPACE.platform.setAxes, show_axes: SPACE.platform.showAxes,
set_volume: SPACE.platform.setVolume, show_volume: SPACE.platform.showVolume,
top_z: () => { return topZ }, top_z: () => { return topZ },
clear: () => { clearWorkspace(); saveWorkspace(true) } clear: () => { clearWorkspace(); saveWorkspace(true) }
}; };
@ -1875,17 +1875,17 @@
if (ctrl.dark) { if (ctrl.dark) {
SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0x333333); SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0x333333);
SPACE.platform.opacity(0.8); SPACE.platform.opacity(0.8);
SPACE.setSkyColor(0); SPACE.sky.setColor(0);
DOC.body.classList.add('dark'); DOC.body.classList.add('dark');
} else { } else {
SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0xcccccc); SPACE.platform.setGrid(gridMajor, gridMinor, 0x999999, 0xcccccc);
SPACE.platform.opacity(0.3); SPACE.platform.opacity(0.3);
SPACE.setSkyColor(0xffffff); SPACE.sky.setColor(0xffffff);
DOC.body.classList.remove('dark'); DOC.body.classList.remove('dark');
} }
} }
SPACE.platform.setRulers(ruler, ruler, 1 / unitScale(), 'X', isBelt ? 'Z' : 'Y'); SPACE.platform.setRulers(ruler, ruler, 1 / unitScale(), 'X', isBelt ? 'Z' : 'Y');
SPACE.platform.setGZOff(height/2 - 0.1); // SPACE.platform.setGZOff(height/2 - 0.1);
platform.update_origin(); platform.update_origin();
} }
@ -2093,7 +2093,7 @@
function platformAdd(widget, shift, nolayout) { function platformAdd(widget, shift, nolayout) {
widget.anno.extruder = widget.anno.extruder || 0; widget.anno.extruder = widget.anno.extruder || 0;
WIDGETS.push(widget); WIDGETS.push(widget);
SPACE.platform.add(widget.mesh); SPACE.world.add(widget.mesh);
platform.select(widget, shift); platform.select(widget, shift);
platform.compute_max_z(); platform.compute_max_z();
API.event.emit('widget.add', widget); API.event.emit('widget.add', widget);
@ -2158,7 +2158,7 @@
KIRI.work.clear(widget); KIRI.work.clear(widget);
WIDGETS.remove(widget); WIDGETS.remove(widget);
Widget.Groups.remove(widget); Widget.Groups.remove(widget);
SPACE.platform.remove(widget.mesh); SPACE.world.remove(widget.mesh);
selectedMeshes.remove(widget.mesh); selectedMeshes.remove(widget.mesh);
updateSliderMax(); updateSliderMax();
platform.compute_max_z(); platform.compute_max_z();

View file

@ -29,13 +29,12 @@ function init() {
platform = space.platform; platform = space.platform;
// setup default workspace // setup default workspace
space.showSkyGrid(sky); space.sky.showGrid(sky);
space.setSkyColor(dark ? 0 : 0xffffff); space.sky.setColor(dark ? 0 : 0xffffff);
space.init($('container'), delta => { }, ortho); space.init($('container'), delta => { }, ortho);
platform.onMove(delta => { } ); platform.onMove(delta => { } );
platform.setRound(false); platform.setRound(false);
platform.setZOff(0.2); platform.setZOff(0.2);
platform.setGZOff(1.24); // half platform thickness - 0.1
platform.setSize(300,300,2.5,300); platform.setSize(300,300,2.5,300);
platform.setGrid(25,5,0x999999,0xcccccc); platform.setGrid(25,5,0x999999,0xcccccc);
platform.setColor(0xcccccc); platform.setColor(0xcccccc);

View file

@ -186,28 +186,6 @@
start(); start();
} }
function tweenPlatform(w,h,d) {
let from = {x: platform.scale.x, y: platform.scale.y, z: platform.scale.z},
to = {x:w, y:h, z:d},
start = function() {
setGrid();
},
update = function() {
setPlatformSize(this.x, this.y, this.z);
updateLastAction();
refresh();
},
complete = function() {
setGrid();
};
new TWEEN.Tween(from).
to(to, tweenTime).
onStart(start).
onUpdate(update).
onComplete(complete).
start();
}
/** ****************************************************************** /** ******************************************************************
* Utility Functions * Utility Functions
******************************************************************* */ ******************************************************************* */
@ -298,7 +276,7 @@
{x: -width/2, z: depth/2, y: maxz}, {x: -width/2, z: depth/2, y: maxz},
]; ];
SCENE.add(volume = makeLinesFromPoints(points, 0x888888, 0.25)); SCENE.add(volume = makeLinesFromPoints(points, 0x888888, 0.25));
setVolume(volumeOn); showVolume(volumeOn);
} }
} }
@ -325,12 +303,12 @@
updateRulers(); updateRulers();
} }
function setAxes(bool) { function showAxes(bool) {
axesOn = bool; axesOn = bool;
updateRulers(); updateRulers();
} }
function setVolume(bool) { function showVolume(bool) {
volumeOn = bool; volumeOn = bool;
if (volume) volume.visible = bool; if (volume) volume.visible = bool;
requestRefresh(); requestRefresh();
@ -380,7 +358,7 @@
w = x / 2, w = x / 2,
h = y / 2, h = y / 2,
d = z / 2, d = z / 2,
zp = -d - platformZOff + gridZOff, zp = -d - platformZOff + (gridZOff || (z/2-0.1)),
labelSize = grid.unitMinor * fontScale, labelSize = grid.unitMinor * fontScale,
oldView = ruler.view, oldView = ruler.view,
view = ruler.view = new THREE.Group(); view = ruler.view = new THREE.Group();
@ -456,7 +434,7 @@
x = platform.scale.x, x = platform.scale.x,
y = isRound ? platform.scale.z : platform.scale.y, y = isRound ? platform.scale.z : platform.scale.y,
z = isRound ? platform.scale.y : platform.scale.z, z = isRound ? platform.scale.y : platform.scale.z,
zp = -(z / 2) - platformZOff + gridZOff, zp = -(z / 2) - platformZOff + (gridZOff || (z/2-0.1)),
xh = x / 2, xh = x / 2,
yh = y / 2, yh = y / 2,
x1 = -xh - origin.x, x1 = -xh - origin.x,
@ -869,18 +847,20 @@
raycast: intersect, raycast: intersect,
refresh: refresh, refresh: refresh,
showSkyGrid: function(b) { sky: {
showSkyGrid = b; showGrid: (b) => {
}, showSkyGrid = b;
},
setSkyColor: function(c) { setColor: (c) => {
skyColor = c; skyColor = c;
if (skyMaterial) skyMaterial.color = new THREE.Color(c); if (skyMaterial) skyMaterial.color = new THREE.Color(c);
}, },
setSkyGridColor: function(c) { setGridColor: (c) => {
skyGridColor = c; skyGridColor = c;
if (skyGridMaterial) skyGridMaterial.color = new THREE.Color(c); if (skyGridMaterial) skyGridMaterial.color = new THREE.Color(c);
}
}, },
scene: { scene: {
@ -888,9 +868,11 @@
o.rotation.x = WORLD.rotation.x; o.rotation.x = WORLD.rotation.x;
return SCENE.add(o); return SCENE.add(o);
}, },
remove: function (o) { remove: function (o) {
return SCENE.remove(o); return SCENE.remove(o);
}, },
active: updateLastAction active: updateLastAction
}, },
@ -898,39 +880,37 @@
add: function(o) { add: function(o) {
WORLD.add(o); WORLD.add(o);
}, },
remove: function(o) { remove: function(o) {
WORLD.remove(o); WORLD.remove(o);
} }
}, },
platform: { platform: {
update: updateDraws, update: updateDraws,
tweenTo: tweenPlatform, setSize: setPlatformSizeUpdateGrid,
setSize: setPlatformSizeUpdateGrid, setColor: setPlatformColor,
setColor: setPlatformColor, setOrigin: setOrigin,
setOrigin: setOrigin, setRulers: setRulers,
setRulers: setRulers, setGrid: setGrid,
setGrid: setGrid, setFont: setFont,
setFont: setFont, showAxes: showAxes,
setAxes: setAxes, showVolume: showVolume,
setVolume: setVolume, setMaxZ: (z) => { panY = z / 2 },
add: function(o) { WORLD.add(o) }, setCenter: (x,y,z) => { panX = x; panY = z, panZ = y },
remove: function(o) { WORLD.remove(o) }, isHidden: () => { return !showPlatform },
setMaxZ: function(z) { panY = z / 2 }, setHidden: (b) => { showPlatform = !b; platform.visible = !b },
setCenter: function(x,y,z) { panX = x; panY = z, panZ = y }, setHiding: (b) => { hidePlatformBelow = b },
isHidden: function() { return !showPlatform }, setZOff: (z) => { platformZOff = z; updatePlatformPosition() },
setHidden: function(b) { showPlatform = !b; platform.visible = !b }, setGridZOff:(z) => { gridZOff = z; updatePlatformPosition() },
setHiding: function(b) { hidePlatformBelow = b }, opacity: (o) => { platform.material.opacity = o },
setZOff: function(z) { platformZOff = z; updatePlatformPosition() }, onMove: (f) => { platformOnMove = f },
setGZOff: function(z) { gridZOff = z; updatePlatformPosition() }, onHover: (f) => { platformHover = f },
opacity: function(o) { platform.material.opacity = o }, onClick: (f) => { platformClick = f},
onMove: function(f) { platformOnMove = f }, size: () => { return platform.scale },
onHover: function(f) { platformHover = f }, isVisible: () => { return platform.visible },
onClick: function(f) { platformClick = f}, showGrid: (b) => { grid.view.visible = b },
size: function() { return platform.scale }, setRound: (bool) => {
isVisible: function() { return platform.visible },
showGrid: function(b) { grid.view.visible = b },
setRound: function(bool) {
let current = platform; let current = platform;
isRound = bool; isRound = bool;
if (bool) { if (bool) {
@ -957,35 +937,35 @@
}, },
view: { view: {
top: function(then) { tweenCam({left: home, up: 0, panX, panY, panZ, then}) }, top: (then) => { tweenCam({left: home, up: 0, panX, panY, panZ, then}) },
back: function(then) { tweenCam({left: PI, up: PI2, panX, panY, panZ, then}) }, back: (then) => { tweenCam({left: PI, up: PI2, panX, panY, panZ, then}) },
home: function(then) { tweenCam({left: home, up, panX, panY, panZ, then}) }, home: (then) => { tweenCam({left: home, up, panX, panY, panZ, then}) },
front: function(then) { tweenCam({left: 0, up: PI2, panX, panY, panZ, then}) }, front: (then) => { tweenCam({left: 0, up: PI2, panX, panY, panZ, then}) },
right: function(then) { tweenCam({left: PI2, up: PI2, panX, panY, panZ, then}) }, right: (then) => { tweenCam({left: PI2, up: PI2, panX, panY, panZ, then}) },
left: function(then) { tweenCam({left: -PI2, up: PI2, panX, panY, panZ, then}) }, left: (then) => { tweenCam({left: -PI2, up: PI2, panX, panY, panZ, then}) },
reset: function() { viewControl.reset(); requestRefresh() }, reset: () => { viewControl.reset(); requestRefresh() },
load: function(cam) { viewControl.setPosition(cam) }, load: (cam) => { viewControl.setPosition(cam) },
save: function() { return viewControl.getPosition(true) }, save: () => { return viewControl.getPosition(true) },
panTo: function(x,y,z) { tweenCamPan(x,y,z) }, panTo: (x,y,z) => { tweenCamPan(x,y,z) },
setZoom: function(r,v) { viewControl.setZoom(r,v) }, setZoom: (r,v) => { viewControl.setZoom(r,v) },
setCtrl: function(name) { setCtrl: (name) => {
if (name === 'onshape') { if (name === 'onshape') {
viewControl.setMouse(viewControl.mouseOnshape); viewControl.setMouse(viewControl.mouseOnshape);
} else { } else {
viewControl.setMouse(viewControl.mouseDefault); viewControl.setMouse(viewControl.mouseDefault);
} }
}, },
getFPS: function() { return fps }, getFPS: () => { return fps },
getFocus: function() { return viewControl.getTarget() }, getFocus: () => { return viewControl.getTarget() },
setFocus: function(v) { setFocus: (v) => {
viewControl.setTarget(v); viewControl.setTarget(v);
refresh(); refresh();
}, },
setHome: function(r,u) { setHome: (r,u) => {
home = r || 0; home = r || 0;
up = u || PI4; up = u || PI4;
}, },
spin: function(then, count) { spin: (then, count) => {
Space.view.front(() => { Space.view.front(() => {
Space.view.right(() => { Space.view.right(() => {
Space.view.back(() => { Space.view.back(() => {
@ -1003,39 +983,39 @@
}, },
mouse: { mouse: {
up: function(f) { mouseUp = f }, up: (f) => { mouseUp = f },
down: function(f) { mouseDown = f }, down: (f) => { mouseDown = f },
downSelect: function(f) { mouseDownSelect = f }, downSelect: (f) => { mouseDownSelect = f },
upSelect: function(f) { mouseUpSelect = f }, upSelect: (f) => { mouseUpSelect = f },
onDrag: function(f) { mouseDrag = f }, onDrag: (f) => { mouseDrag = f },
onHover: function(f) { mouseHover = f } onHover: (f) => { mouseHover = f }
}, },
useDefaultKeys: function(b) { useDefaultKeys: (b) => {
defaultKeys = b; defaultKeys = b;
}, },
selectRecurse: function(b) { selectRecurse: (b) => {
selectRecurse = b; selectRecurse = b;
}, },
setTweenTime: function(t) { setTweenTime: (t) => {
tweenTime = t || 500; tweenTime = t || 500;
}, },
setTweenDelay: function(d) { setTweenDelay: (d) => {
tweenDelay = d || 20; tweenDelay = d || 20;
}, },
objects: function() { objects: () => {
return WC; return WC;
}, },
screenshot: function(format, options) { screenshot: (format, options) => {
return renderer.domElement.toDataURL(format || "image/png", options); return renderer.domElement.toDataURL(format || "image/png", options);
}, },
screenshot2: function(param = {}) { screenshot2: (param = {}) => {
let oco = renderer.domElement; let oco = renderer.domElement;
let oWidth = oco.offsetWidth; let oWidth = oco.offsetWidth;
let oHeight = oco.offsetHeight; let oHeight = oco.offsetHeight;
@ -1053,11 +1033,11 @@
}; };
}, },
internals: function() { internals: () => {
return { renderer, camera, platform }; return { renderer, camera, platform };
}, },
init: function(domelement, slider, ortho) { init: (domelement, slider, ortho) => {
container = domelement; container = domelement;
WORLD.rotation.x = -PI2; WORLD.rotation.x = -PI2;
@ -1081,7 +1061,7 @@
raycaster = new THREE.Raycaster(); raycaster = new THREE.Raycaster();
viewControl = new MOTO.CTRL(camera, domelement, function (position, moved) { viewControl = new MOTO.CTRL(camera, domelement, (position, moved) => {
if (platform) { if (platform) {
platform.visible = hidePlatformBelow ? platform.visible = hidePlatformBelow ?
initialized && position.y >= 0 && showPlatform : showPlatform; initialized && position.y >= 0 && showPlatform : showPlatform;