allow anim1 and anim2 to coexist

This commit is contained in:
Stewart Allen 2022-10-27 23:20:21 -04:00
commit 61e4c7b9de
4 changed files with 66 additions and 60 deletions

View file

@ -11,30 +11,29 @@ const { driver } = kiri;
const { CAM } = driver; const { CAM } = driver;
const asLines = false; const asLines = false;
const asPoints = false; const asPoints = false;
const defer = true;
let meshes = {},
unitScale = 1,
progress,
speedValues = [ 1, 2, 4, 8, 32 ],
speedPauses = [ 30, 20, 10, 5, 0 ],
speedNames = [ "1x", "2x", "4x", "8x", "!!" ],
speedMax = speedValues.length - 1,
speedIndex = 0,
speedLabel,
speed,
color = 0,
pauseButton,
playButton,
posOffset = { x:0, y:0, z:0 };
// ---( CLIENT FUNCTIONS )--- // ---( CLIENT FUNCTIONS )---
kiri.load(() => { kiri.load(() => {
if (!kiri.client || defer) { if (!kiri.client) {
return; return;
} }
let meshes = {},
unitScale = 1,
progress,
speedValues = [ 1, 2, 4, 8, 32 ],
speedPauses = [ 30, 20, 10, 5, 0 ],
speedNames = [ "1x", "2x", "4x", "8x", "!!" ],
speedMax = speedValues.length - 1,
speedIndex = 0,
speedLabel,
speed,
color = 0,
pauseButton,
playButton,
posOffset = { x:0, y:0, z:0 };
const { moto } = root; const { moto } = root;
const { space } = moto; const { space } = moto;
const { api } = kiri; const { api } = kiri;
@ -266,7 +265,7 @@ kiri.load(() => {
// ---( WORKER FUNCTIONS )--- // ---( WORKER FUNCTIONS )---
kiri.load(() => { kiri.load(() => {
if (!kiri.worker || defer) { if (!kiri.worker) {
return; return;
} }

View file

@ -10,22 +10,6 @@ const { kiri } = root;
const { driver } = kiri; const { driver } = kiri;
const { CAM } = driver; const { CAM } = driver;
let meshes = {},
unitScale = 1,
progress,
// speedValues = [ 32, 32, 32, 32, 32 ],
speedPauses = [ 0, 0, 0, 0, 0 ],
speedValues = [ 1, 2, 4, 8, 32 ],
// speedPauses = [ 30, 20, 10, 5, 0 ],
speedNames = [ "1x", "2x", "4x", "8x", "!!" ],
speedMax = speedValues.length - 1,
speedIndex = 0,
speedLabel,
speed,
color = 0,
pauseButton,
playButton;
// ---( CLIENT FUNCTIONS )--- // ---( CLIENT FUNCTIONS )---
kiri.load(() => { kiri.load(() => {
@ -33,21 +17,34 @@ kiri.load(() => {
return; return;
} }
let meshes = {},
progress,
speedPauses = [ 0, 0, 0, 0, 0 ],
speedValues = [ 1, 2, 4, 8, 32 ],
speedNames = [ "1x", "2x", "4x", "8x", "!!" ],
speedMax = speedValues.length - 1,
speedIndex = 0,
speedLabel,
speed,
color = 0,
pauseButton,
playButton;
const { moto } = root; const { moto } = root;
const { space } = moto; const { space } = moto;
const { api } = kiri; const { api } = kiri;
function animate_clear(api) { function animate_clear2(api) {
moto.space.platform.showGridBelow(true); moto.space.platform.showGridBelow(true);
kiri.client.animate_cleanup(); kiri.client.animate_cleanup2();
$('layer-animate').innerHTML = ''; $('layer-animate').innerHTML = '';
$('layer-toolpos').innerHTML = ''; $('layer-toolpos').innerHTML = '';
Object.keys(meshes).forEach(id => deleteMesh(id)); Object.keys(meshes).forEach(id => deleteMesh(id));
} }
function animate(api, delay) { function animate2(api, delay) {
let alert = api.alerts.show("building animation"); let alert = api.alerts.show("building animation");
kiri.client.animate_setup(api.conf.get(), data => { kiri.client.animate_setup2(api.conf.get(), data => {
handleUpdate(data); handleUpdate(data);
if (data) { if (data) {
return; return;
@ -80,24 +77,23 @@ kiri.load(() => {
} }
gapp.overlay(kiri.client, { gapp.overlay(kiri.client, {
animate(data, ondone) { animate2(data, ondone) {
kiri.client.send("animate", data, ondone); kiri.client.send("animate2", data, ondone);
}, },
animate_setup(settings, ondone) { animate_setup2(settings, ondone) {
color = settings.controller.dark ? 0x888888 : 0; color = settings.controller.dark ? 0x888888 : 0;
unitScale = settings.controller.units === 'in' ? 1/25.4 : 1; kiri.client.send("animate_setup2", {settings}, ondone);
kiri.client.send("animate_setup", {settings}, ondone);
}, },
animate_cleanup(data, ondone) { animate_cleanup2(data, ondone) {
kiri.client.send("animate_cleanup", data, ondone); kiri.client.send("animate_cleanup2", data, ondone);
} }
}); });
gapp.overlay(CAM, { gapp.overlay(CAM, {
animate, animate2,
animate_clear animate_clear2
}); });
function meshAdd(id, ind, pos, ilen, plen) { function meshAdd(id, ind, pos, ilen, plen) {
@ -142,7 +138,7 @@ kiri.load(() => {
function step() { function step() {
updateSpeed(); updateSpeed();
kiri.client.animate({speed, steps: 1}, handleUpdate); kiri.client.animate2({speed, steps: 1}, handleUpdate);
} }
function play(opts) { function play(opts) {
@ -153,7 +149,7 @@ kiri.load(() => {
pauseButton.style.display = ''; pauseButton.style.display = '';
$('render-hide').onclick(); $('render-hide').onclick();
} }
kiri.client.animate({ kiri.client.animate2({
speed, speed,
steps: steps || Infinity, steps: steps || Infinity,
pause: speedPauses[speedIndex] pause: speedPauses[speedIndex]
@ -166,7 +162,7 @@ kiri.load(() => {
playButton.style.display = 'none'; playButton.style.display = 'none';
pauseButton.style.display = ''; pauseButton.style.display = '';
$('render-hide').onclick(); $('render-hide').onclick();
kiri.client.animate({ kiri.client.animate2({
speed, speed,
steps: steps || Infinity, steps: steps || Infinity,
pause: speedPauses[speedIndex] pause: speedPauses[speedIndex]
@ -176,7 +172,7 @@ kiri.load(() => {
function pause() { function pause() {
playButton.style.display = ''; playButton.style.display = '';
pauseButton.style.display = 'none'; pauseButton.style.display = 'none';
kiri.client.animate({speed: 0}, handleUpdate); kiri.client.animate2({speed: 0}, handleUpdate);
} }
function handleUpdate(data) { function handleUpdate(data) {
@ -221,9 +217,9 @@ kiri.load(() => {
} }
function replay() { function replay() {
CAM.animate_clear(api); CAM.animate_clear2(api);
setTimeout(() => { setTimeout(() => {
CAM.animate(api, 50); CAM.animate2(api, 50);
}, 250); }, 250);
} }
}); });
@ -354,13 +350,12 @@ kiri.load(() => {
let updates = 0; let updates = 0;
kiri.worker.animate_setup = function(data, send) { kiri.worker.animate_setup2 = function(data, send) {
const { settings } = data; const { settings } = data;
const { process } = settings; const { process } = settings;
const print = worker.print; const print = worker.print;
const density = parseInt(settings.controller.animesh) * 1000; const density = parseInt(settings.controller.animesh) * 1000;
unitScale = settings.controller.units === 'in' ? 1/25.4 : 1;
pathIndex = 0; pathIndex = 0;
path = print.output.flat(); path = print.output.flat();
tools = settings.tools; tools = settings.tools;
@ -402,7 +397,7 @@ kiri.load(() => {
send.done(); send.done();
}; };
kiri.worker.animate = function(data, send) { kiri.worker.animate2 = function(data, send) {
renderPause = data.pause || renderPause; renderPause = data.pause || renderPause;
renderSpeed = data.speed || 0; renderSpeed = data.speed || 0;
if (animating) { if (animating) {
@ -415,7 +410,7 @@ kiri.load(() => {
renderPath(send); renderPath(send);
}; };
kiri.worker.animate_cleanup = function(data, send) { kiri.worker.animate_cleanup2 = function(data, send) {
if (animating) { if (animating) {
animateClear = true; animateClear = true;
} }

View file

@ -4,6 +4,7 @@
// dep: kiri-mode.cam.driver // dep: kiri-mode.cam.driver
// use: kiri-mode.cam.animate // use: kiri-mode.cam.animate
// use: kiri-mode.cam.animate2
gapp.register("kiri-mode.cam.client", [], (root, exports) => { gapp.register("kiri-mode.cam.client", [], (root, exports) => {
const { base, kiri } = root; const { base, kiri } = root;
@ -31,6 +32,16 @@ let zaxis = { x: 0, y: 0, z: 1 },
}, },
flipping; flipping;
function animFn(v) {
return [{
animate: CAM.animate,
animate_clear: CAM.animate_clear
},{
animate: CAM.animate2,
animate_clear: CAM.animate_clear2
}][0];
}
CAM.restoreTabs = restoreTabs; CAM.restoreTabs = restoreTabs;
CAM.init = function(kiri, api) { CAM.init = function(kiri, api) {
@ -68,7 +79,7 @@ CAM.init = function(kiri, api) {
api.event.on("function.export", (mode) => { api.event.on("function.export", (mode) => {
if (isAnimate) { if (isAnimate) {
CAM.animate_clear(api); animFn(0).animate_clear(api);
isAnimate = false; isAnimate = false;
} }
}); });
@ -91,7 +102,7 @@ CAM.init = function(kiri, api) {
api.event.on("view.set", (mode) => { api.event.on("view.set", (mode) => {
isArrange = (mode === VIEWS.ARRANGE); isArrange = (mode === VIEWS.ARRANGE);
isAnimate = false; isAnimate = false;
CAM.animate_clear(api); animFn(0).animate_clear(api);
func.clearPops(); func.clearPops();
$('camops').style.display = isCamMode && isArrange ? 'flex' : ''; $('camops').style.display = isCamMode && isArrange ? 'flex' : '';
}); });
@ -1516,7 +1527,7 @@ function animate() {
API.widgets.opacity(isParsed ? 0 : 0.75); API.widgets.opacity(isParsed ? 0 : 0.75);
API.hide.slider(); API.hide.slider();
STACKS.clear(); STACKS.clear();
CAM.animate(API); animFn(0).animate(API);
} }
function updateStock(args, event) { function updateStock(args, event) {

View file

@ -12,6 +12,7 @@
// use: ext.jszip // use: ext.jszip
// use: kiri.render // use: kiri.render
// use: kiri-mode.cam.animate // use: kiri-mode.cam.animate
// use: kiri-mode.cam.animate2
// use: kiri-mode.cam.slice // use: kiri-mode.cam.slice
// use: kiri-mode.cam.prepare // use: kiri-mode.cam.prepare
// use: kiri-mode.cam.export // use: kiri-mode.cam.export