Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

add a request animation feature when no search results found

Scott Petrovic025fb0d85878
diff --git a/src/dialog.css b/src/dialog.css
index 0a197ce..59eacdf 100644
--- a/src/dialog.css
+++ b/src/dialog.css
@@ -419,11 +419,6 @@
gap: 1rem;
}
-.survey-thank-you {
- font-style: italic;
- margin-top: 0 !important;
-}
-
.download-success-dialog-overlay {
position: fixed;
top: 0;
@@ -504,6 +499,50 @@
margin: 1rem auto;
}
+/* ── Animation Request Dialog ── */
+
+.animation-request-dialog .modal-dialog-content {
+ width: 90vw;
+ max-width: 36rem;
+}
+
+.animation-request-body {
+ display: flex;
+ flex-direction: column;
+}
+
+.animation-request-body label {
+ margin-bottom: 0;
+}
+
+.animation-request-textarea {
+ padding: 1rem;
+ background-color: var(--bg-primary);
+ border: 1px solid var(--bg-tertiary);
+ font-family: 'Jost', sans-serif;
+ resize: vertical;
+ min-height: 6rem;
+}
+
+.animation-request-textarea::placeholder {
+ color: var(--text-primary);
+ opacity: 0.6;
+ font-style: italic;
+}
+
+.animation-request-textarea:focus {
+ outline: none;
+ border-color: var(--button-primary-bg);
+}
+
+.animation-request-error {
+ margin-bottom: 0 !important;
+}
+
+#animation-request-submit {
+ align-self: flex-end;
+}
+
/* ── Star Rating Component ── */
.star-rating {
diff --git a/src/index.html b/src/index.html
index ceaffe5..b748e33 100644
--- a/src/index.html
+++ b/src/index.html
@@ -143,7 +143,7 @@
<!-- javascript will populate this item with animations
that we get from the animations file(s) -->
- <div id="animations-items"> </div>
+ <div id="animations-items"> </div>
diff --git a/src/lib/SurveyWorkerUrl.ts b/src/lib/SurveyWorkerUrl.ts
new file mode 100644
index 0000000..92d9131
--- /dev/null
+++ b/src/lib/SurveyWorkerUrl.ts
@@ -0,0 +1,2 @@
+// Cloudflare Worker endpoint that stores survey responses and animation requests (see src/survey-worker.js)
+export const SURVEY_WORKER_URL = 'https://mesh2motion-app.scottpetrovic.workers.dev'
diff --git a/src/lib/components/animation-request/AnimationRequestDialog.ts b/src/lib/components/animation-request/AnimationRequestDialog.ts
new file mode 100644
index 0000000..d4bd48e
--- /dev/null
+++ b/src/lib/components/animation-request/AnimationRequestDialog.ts
@@ -0,0 +1,137 @@
+import { SkeletonType } from '../../enums/SkeletonType'
+import { RigConfig } from '../../RigConfig'
+import { SURVEY_WORKER_URL } from '../../SurveyWorkerUrl'
+
+const MAX_DESCRIPTION_LENGTH = 1000
+
+// Dialog that lets people request new animations for a rig type.
+// Submissions are stored by the survey worker in the animation_requests table.
+export class AnimationRequestDialog {
+ private static request_links_enabled: boolean = false
+ private dialog_element: HTMLDivElement | null = null
+
+ constructor (private readonly default_rig_type: SkeletonType) {}
+
+ /**
+ * Any ".request-animation-link" element opens this dialog, defaulting to the rig in its
+ * data-rig-type attribute. Links get re-rendered often (e.g. the empty animation listing),
+ * so a single delegated listener is registered once instead of one per link.
+ */
+ public static enable_request_links (): void {
+ if (this.request_links_enabled) return
+ this.request_links_enabled = true
+
+ document.addEventListener('click', (event) => {
+ const link = (event.target as HTMLElement | null)?.closest<HTMLElement>('.request-animation-link')
+ if (link == null) return
+
+ event.preventDefault()
+ const rig_type = (link.dataset.rigType as SkeletonType | undefined) ?? SkeletonType.Human
+ new AnimationRequestDialog(rig_type).show()
+ })
+ }
+
+ public show (): void {
+ this.remove()
+ this.dialog_element = document.createElement('div')
+ this.dialog_element.className = 'modal-dialog-overlay animation-request-dialog'
+ this.dialog_element.innerHTML = this.build_html()
+ document.body.appendChild(this.dialog_element)
+
+ const description_textarea = this.dialog_element.querySelector<HTMLTextAreaElement>('#animation-request-description')
+ const submit_button = this.dialog_element.querySelector<HTMLButtonElement>('#animation-request-submit')
+
+ // only allow submitting once something has been typed in
+ description_textarea?.addEventListener('input', () => {
+ if (submit_button !== null) {
+ submit_button.disabled = description_textarea.value.trim().length === 0
+ }
+ })
+ description_textarea?.focus()
+
+ submit_button?.addEventListener('click', () => { void this.submit_request() })
+
+ const close_button = this.dialog_element.querySelector('.modal-dialog-close')
+ close_button?.addEventListener('click', () => { this.remove() })
+
+ this.dialog_element.addEventListener('click', (e) => {
+ if (e.target === this.dialog_element) this.remove()
+ })
+ }
+
+ private build_html (): string {
+ const rig_options: string = RigConfig.all.map((rig) => {
+ const selected = rig.skeleton_type === this.default_rig_type ? ' selected' : ''
+ return `<option value="${rig.skeleton_type}"${selected}>${rig.rig_display_name}</option>`
+ }).join('')
+
+ return `
+ <div class="modal-dialog-content">
+ <h2>Request an Animation</h2>
+ <div class="modal-dialog-body animation-request-body">
+ <label for="animation-request-rig">Rig type</label>
+ <select id="animation-request-rig">
+ ${rig_options}
+ <option value="other">Other / new rig type</option>
+ </select>
+
+ <label for="animation-request-description">What animation(s) would you like?</label>
+ <textarea id="animation-request-description" class="animation-request-textarea"
+ placeholder="Describe the animation(s) you want. (${MAX_DESCRIPTION_LENGTH} character max)"
+ rows="6" maxlength="${MAX_DESCRIPTION_LENGTH}"></textarea>
+
+ <p class="animation-request-error" style="display: none;">Something went wrong submitting your request. Please try again.</p>
+ <button id="animation-request-submit" disabled>Submit</button>
+ </div>
+ <button class="modal-dialog-close secondary-button">Close</button>
+ </div>
+ `
+ }
+
+ private async submit_request (): Promise<void> {
+ if (this.dialog_element === null) return
+
+ const rig_select = this.dialog_element.querySelector<HTMLSelectElement>('#animation-request-rig')
+ const description_textarea = this.dialog_element.querySelector<HTMLTextAreaElement>('#animation-request-description')
+ const submit_button = this.dialog_element.querySelector<HTMLButtonElement>('#animation-request-submit')
+ const error_message = this.dialog_element.querySelector<HTMLParagraphElement>('.animation-request-error')
+ const body_element = this.dialog_element.querySelector<HTMLDivElement>('.animation-request-body')
+
+ const rig_type = rig_select?.value ?? this.default_rig_type
+ const description = description_textarea?.value.trim() ?? ''
+ if (description.length === 0) return
+
+ if (submit_button !== null) submit_button.disabled = true
+ if (error_message !== null) error_message.style.display = 'none'
+
+ try {
+ const res = await fetch(`${SURVEY_WORKER_URL}/animation-request`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ rig_type, description })
+ })
+
+ if (!res.ok) {
+ throw new Error(res.statusText)
+ }
+
+ if (body_element !== null) {
+ body_element.innerHTML = `
+ <p class="survey-thank-you">
+ Request submitted. Can't promise I can do every request, but I will try to focus on areas that I get the most requests for.
+ </p>`
+ }
+ } catch (error) {
+ console.error('Error submitting animation request:', error)
+ if (submit_button !== null) submit_button.disabled = false
+ if (error_message !== null) error_message.style.display = 'block'
+ }
+ }
+
+ private remove (): void {
+ if (this.dialog_element?.parentNode != null) {
+ this.dialog_element.parentNode.removeChild(this.dialog_element)
+ this.dialog_element = null
+ }
+ }
+}
diff --git a/src/lib/components/download-success/DownloadSuccessDialog.ts b/src/lib/components/download-success/DownloadSuccessDialog.ts
index d648cc0..64553a4 100644
--- a/src/lib/components/download-success/DownloadSuccessDialog.ts
+++ b/src/lib/components/download-success/DownloadSuccessDialog.ts
@@ -1,4 +1,5 @@
import { StarRating } from './StarRating'
+import { SURVEY_WORKER_URL } from '../../SurveyWorkerUrl'
export class DownloadSuccessDialog {
private dialog_element: HTMLDivElement | null = null
@@ -87,10 +88,8 @@ export class DownloadSuccessDialog {
}
// Use the Cloudflare Worker endpoint to submit the survey data
- const WORKER_URL = "https://mesh2motion-app.scottpetrovic.workers.dev"
-
try {
- const res = await fetch(`${WORKER_URL}/submit`, {
+ const res = await fetch(`${SURVEY_WORKER_URL}/submit`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ survey: survey_data })
diff --git a/src/lib/processes/animations-listing/AnimationSearch.ts b/src/lib/processes/animations-listing/AnimationSearch.ts
index bd568dc..7b459af 100644
--- a/src/lib/processes/animations-listing/AnimationSearch.ts
+++ b/src/lib/processes/animations-listing/AnimationSearch.ts
@@ -4,6 +4,7 @@ import { RigConfig } from '../../RigConfig'
import { type AnimationWithState } from './interfaces/AnimationWithState'
import { type TransformedAnimationClipPair } from './interfaces/TransformedAnimationClipPair'
import { type AnimationExportSelection, type AnimationMirrorExportMode } from './interfaces/AnimationExportSelection'
+import { AnimationRequestDialog } from '../../components/animation-request/AnimationRequestDialog'
export class AnimationSearch extends EventTarget {
private all_animations: AnimationWithState[] = []
@@ -32,6 +33,7 @@ export class AnimationSearch extends EventTarget {
this.theme_manager = theme_manager
this.skeleton_type = skeleton_type
this.setup_event_listeners()
+ AnimationRequestDialog.enable_request_links()
}
public initialize_animations (animations: TransformedAnimationClipPair[]): void {
@@ -268,7 +270,11 @@ export class AnimationSearch extends EventTarget {
// Show "no animations found" if the filtered list is empty
if (this.filtered_animations_list.length === 0) {
- this.animation_list_container.innerHTML = '<div class="no-animations-message">No animations found</div>'
+ this.animation_list_container.innerHTML = `
+ <div class="no-animations-message">
+ No animations found.
+ <a href="#" class="request-animation-link" data-rig-type="${this.skeleton_type}">Request an animation</a>
+ </div>`
return
}
diff --git a/src/styles.css b/src/styles.css
index ee389df..03227bb 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -942,12 +942,21 @@ input[type="file"] {
left: 0;
}
-#animations-items .no-animations-message {
+div.modal-dialog-body p.survey-thank-you {
+ margin-bottom: 0;
+ font-size: 120%;
+}
+
+#animations-items .no-animations-message,
+.request-animation-link {
padding: 0.5rem;
font-style: italic;
- font-size: 90%;
+ font-size: 100%;
+ align-items: center;
+}
+.request-animation-link {
+ color: var(--text-primary);
}
-
#build-version {
position: fixed;
@@ -1037,4 +1046,5 @@ input[type="file"] {
be hiding most of the post-download stuff */
.download-success-desktop {
display: none;
-}
\ No newline at end of file
+}
+
diff --git a/src/survey-worker.js b/src/survey-worker.js
index 4e57a7b..3f21a4f 100644
--- a/src/survey-worker.js
+++ b/src/survey-worker.js
@@ -1,7 +1,7 @@
/***
* A simple Cloudflare Worker to accept survey responses and store them in a D1 database.
- *
- * Expected payload format (JSON):
+ *
+ * POST /submit expected payload format (JSON):
* {
* "survey": [
* { "question": "How satisfied are you?", "answer": 5 },
@@ -9,6 +9,12 @@
* ],
* "session_id": "optional-session-id"
* }
+ *
+ * POST /animation-request expected payload format (JSON):
+ * {
+ * "rig_type": "human",
+ * "description": "A sword slash combo and a ledge climb"
+ * }
*/
export default {
/**
@@ -29,7 +35,12 @@ export default {
return handleSubmit(request, env);
}
- // 3) Fallback for unknown routes/methods.
+ // 3) Animation request endpoint: store a single rig type + description.
+ if (request.method === "POST" && url.pathname === "/animation-request") {
+ return handleAnimationRequest(request, env);
+ }
+
+ // 4) Fallback for unknown routes/methods.
return corsResponse({ error: "Not found" }, 404);
},
};
@@ -37,6 +48,8 @@ export default {
const MAX_SURVEY_ITEMS = 20;
const MAX_QUESTION_LENGTH = 200;
const MAX_ANSWER_LENGTH = 2000;
+const MAX_RIG_TYPE_LENGTH = 50;
+const MAX_ANIMATION_REQUEST_LENGTH = 2000;
/**
* Handles POST /submit by validating payload shape, preparing DB writes,
@@ -78,6 +91,45 @@ async function handleSubmit(request, env) {
);
}
+/**
+ * Handles POST /animation-request by validating the rig type and description,
+ * then inserting a single row into the animation_requests table.
+ */
+async function handleAnimationRequest(request, env) {
+ let body;
+ try {
+ body = await request.json();
+ } catch {
+ return badRequest("Invalid JSON");
+ }
+
+ const rig_type = typeof body?.rig_type === "string" ? body.rig_type.trim() : "";
+ const description = typeof body?.description === "string" ? body.description.trim() : "";
+
+ if (!rig_type) {
+ return badRequest("rig_type is required");
+ }
+
+ if (rig_type.length > MAX_RIG_TYPE_LENGTH) {
+ return badRequest("rig_type is too long");
+ }
+
+ if (!description) {
+ return badRequest("description is required");
+ }
+
+ if (description.length > MAX_ANIMATION_REQUEST_LENGTH) {
+ return badRequest("description is too long");
+ }
+
+ // submitted_at defaults to the current timestamp and id auto-increments
+ await env.DB.prepare(
+ "INSERT INTO animation_requests (rig_type, description) VALUES (?, ?)"
+ ).bind(rig_type, description).run();
+
+ return corsResponse({ success: true }, 201);
+}
+
/**
* Normalizes an optional session id from the client.
* Generates a UUID when no usable id is provided.
diff --git a/static/survey/readme.md b/static/survey/readme.md
new file mode 100644
index 0000000..bd32d94
--- /dev/null
+++ b/static/survey/readme.md
@@ -0,0 +1,15 @@
+# Survey original setup instructions
+
+I am using Cloudflare for this since that is just where I am doing things. If something else is used, this process won't work. I am mostly writing this when I forget what I did, or need to set it up later on if I have to change platforms.
+
+1. Create a new database on your Cloudflare account. I made one called "m2m-survey-responses".
+2. Get the UUID of the database using the npx command in command prompt: npx wrangler d1 list
+3. Run this command to create the table that stores responses:
+
+ npx wrangler d1 execute m2m-survey-responses --remote --file=survey/schema.sql
+
+4. Run this command to actually deploy the new "worker" that will process the survey being sent:
+
+ npx wrangler deploy
+
+The schema file also creates the `animation_requests` table used by the "Request an animation" dialog (POST /animation-request). The statements use `IF NOT EXISTS`, so re-running step 3 on an existing database only adds missing tables.
\ No newline at end of file
diff --git a/survey/schema.sql b/static/survey/schema.sql
similarity index 51%
rename from survey/schema.sql
rename to static/survey/schema.sql
index 7c8c605..1c3f52b 100644
--- a/survey/schema.sql
+++ b/static/survey/schema.sql
@@ -5,3 +5,10 @@ CREATE TABLE IF NOT EXISTS responses (
answer TEXT NOT NULL,
submitted_at TEXT NOT NULL DEFAULT (datetime('now'))
);
+
+CREATE TABLE IF NOT EXISTS animation_requests (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ rig_type TEXT NOT NULL,
+ description TEXT NOT NULL,
+ submitted_at TEXT NOT NULL DEFAULT (datetime('now'))
+);
diff --git a/survey/readme.md b/survey/readme.md
deleted file mode 100644
index f5f22aa..0000000
--- a/survey/readme.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# Survey original setup instructions
-
-I am using Cloudflare for this since that is just where I am doing things. If something else is used, this process won't work. I am mostly writing this when I forget what I did, or need to set it up later on if I have to change platforms.
-
-1. Create a new database on your Cloudflare account
-2. Get the UUID of the database usin the npx command in command prompt: npx wrangler d1 list
-3. Run this command to create the table that stores responses: npx wrangler d1 execute m2m-survey-responses --remote --file=survey/schema.sql
-4. Run this command to actually deploy the new "worker" that will process the survey being sent: npx wrangler deploy
\ No newline at end of file