Skip to content

Commit dc64145

Browse files
committed
added save/load for json data of project, fixed saving scenes with sample mode.
1 parent a5289ff commit dc64145

File tree

2,352 files changed

+510581
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,352 files changed

+510581
-55
lines changed

animationHud.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ export function createPlaybackHUD(animationManager, scene) {
180180
pathToggleCheckbox.checked = true; // Default to showing paths
181181
pathToggleCheckbox.id = 'path-toggle';
182182

183+
// Listen for project loading to update UI state
184+
window.addEventListener('project-loaded', (event) => {
185+
if (event.detail && event.detail.showAnimationPaths !== undefined) {
186+
window.showAnimationPaths = event.detail.showAnimationPaths;
187+
togglePathsButton.textContent = window.showAnimationPaths ? '👁️ Paths: ON' : '👁️ Paths: OFF';
188+
189+
// Update visibility of all paths
190+
scene.traverse(obj => {
191+
if (obj.isAnimationPath) {
192+
obj.visible = window.showAnimationPaths;
193+
}
194+
});
195+
}
196+
});
197+
183198
// Add components to container in correct order
184199
pathToggleContainer.appendChild(pathLabelContent);
185200
pathToggleContainer.appendChild(pathToggleCheckbox);
@@ -194,11 +209,27 @@ export function createPlaybackHUD(animationManager, scene) {
194209
gizmoToggleCheckbox.id = 'gizmo-toggle';
195210
gizmoToggleCheckbox.checked = true; // Default to visible
196211

212+
//create gizmo icon image
213+
const gizmoIcon = document.createElement('img');
214+
gizmoIcon.src = '/../assets/gizmo.PNG';
215+
gizmoIcon.width = 20;
216+
gizmoIcon.height = 20;
217+
gizmoIcon.style.marginLeft = '5px';
218+
197219
const gizmoToggleLabel = document.createElement('label');
198220
gizmoToggleLabel.htmlFor = 'gizmo-toggle';
199221
gizmoToggleLabel.textContent = 'Show Gizmo:';
200222
gizmoToggleLabel.style.marginRight = '10px';
201223

224+
// Create label container with icon and text
225+
const gizmoLabelContent = document.createElement('div');
226+
gizmoLabelContent.style.display = 'flex';
227+
gizmoLabelContent.style.alignItems = 'right';
228+
gizmoLabelContent.style.marginRight = '10px';
229+
gizmoLabelContent.appendChild(gizmoIcon);
230+
gizmoLabelContent.appendChild(gizmoToggleLabel);
231+
gizmoToggleContainer.appendChild(gizmoLabelContent);
232+
// Append the checkbox to the label container
202233
gizmoToggleContainer.appendChild(gizmoToggleLabel);
203234
gizmoToggleContainer.appendChild(gizmoToggleCheckbox);
204235

animationManager.js

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,15 @@ export class AnimationManager {
1010
}
1111

1212
addAnimation(object, animationConfig) {
13+
console.log("Adding animation:", animationConfig);
14+
1315
// Update start/end times of the timeline if needed
1416
this.startTime = Math.min(this.startTime, animationConfig.startT);
1517
this.endTime = Math.max(this.endTime, animationConfig.endT);
1618

17-
// Check if the object already has animations
19+
// Initialize animations array if it doesn't exist
1820
if (!object.animations) {
1921
object.animations = [];
20-
21-
// Add an update method to the object
22-
object.update = (time) => {
23-
// Apply all animations for this object, using the provided time
24-
object.animations.forEach(anim => {
25-
const { property, axis, startT, endT, functions, loop } = anim;
26-
27-
// Skip if outside time range and not looping
28-
if (time < startT) return;
29-
if (time > endT && !loop && !this.loop) return;
30-
31-
// Calculate local time based on global time
32-
let localTime;
33-
if (loop || this.loop) {
34-
// Loop the animation (cycle between startT and endT)
35-
const duration = endT - startT;
36-
const elapsed = time - startT;
37-
localTime = startT + (elapsed % duration);
38-
} else {
39-
// Play once and clamp to endT
40-
localTime = Math.min(time, endT);
41-
}
42-
43-
// Apply the function to the specified property and axis
44-
if (functions[axis]) {
45-
const { apply, params } = functions[axis];
46-
const value = apply(localTime, params);
47-
48-
// Apply to the object
49-
if (property === 'position') {
50-
object.position[axis] = value;
51-
} else if (property === 'rotation') {
52-
object.rotation[axis] = value;
53-
} else if (property === 'scale') {
54-
object.scale[axis] = Math.max(0.01, value); // Prevent negative/zero scale
55-
}
56-
}
57-
});
58-
};
5922
}
6023

6124
// Add this animation to the object's animations
@@ -64,8 +27,49 @@ export class AnimationManager {
6427
// Add to global animations list
6528
this.animations.push({ object, ...animationConfig });
6629

30+
// Ensure the update method is created
31+
object.update = (time) => {
32+
if (!object.animations || object.animations.length === 0) return;
33+
34+
object.animations.forEach(anim => {
35+
const { property, axis, startT, endT, functions } = anim;
36+
37+
if (time < startT) return;
38+
39+
let localTime;
40+
if (this.loop) {
41+
const duration = endT - startT;
42+
const elapsed = time - startT;
43+
localTime = startT + (elapsed % duration);
44+
} else {
45+
localTime = Math.min(time, endT);
46+
}
47+
48+
if (functions[axis]) {
49+
const { apply, params } = functions[axis];
50+
const value = apply(localTime, params);
51+
52+
if (property === 'position') {
53+
object.position[axis] = value;
54+
} else if (property === 'rotation') {
55+
object.rotation[axis] = value;
56+
} else if (property === 'scale') {
57+
object.scale[axis] = Math.max(0.01, value);
58+
} else if (property === 'color' && object.material && object.material.color) {
59+
// Color animation
60+
if (axis === 'r') object.material.color.r = value / 255;
61+
if (axis === 'g') object.material.color.g = value / 255;
62+
if (axis === 'b') object.material.color.b = value / 255;
63+
}
64+
}
65+
});
66+
};
67+
6768
// Apply animation immediately with current time
6869
object.update(this.globalTime);
70+
71+
// Debug log to verify the animation is added
72+
console.log(`Animation added to ${object.uuid}, total animations: ${this.animations.length}`);
6973
} addAnimation(object, animationConfig) {
7074
console.log("Adding animation:", animationConfig);
7175

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createTorusMenu } from './torusMenu.js';
66
import { createConeMenu } from './coneMenu.js';
77
import { createCylinderMenu } from './cylinderMenu.js';
88
import { createExportMenu } from './exportMenu.js';
9+
import { createProjectMenu } from './projectMenu.js';
910
//import { createCustomObjectMenu } from './customObjectMenu.js';
1011
import { initializeObjectEditMenu, getSelectedObject} from './objectEditMenu.js';
1112
// import animation manager
@@ -53,6 +54,7 @@ createTorusMenu(scene);
5354
createConeMenu(scene);
5455
createCylinderMenu(scene);
5556
createExportMenu(scene, animManager, getActiveCamera, renderer);
57+
createProjectMenu(scene, animManager, getActiveCamera);
5658
//createCustomObjectMenu(scene);
5759
// Initialize the animation HUD
5860
createPlaybackHUD(animManager, scene);

assets/arrow glyphs.svg

Lines changed: 76 additions & 7 deletions
Loading

assets/gizmo.PNG

2.61 KB
Loading

assets/paths.png

2.61 KB
Loading

assets/pitch.png

203 Bytes
Loading

assets/pitchx.png

-2.23 KB
Binary file not shown.

assets/roll.png

122 Bytes
Loading

assets/rollz.png

-2.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)