Skip to content

Commit a92ab7b

Browse files
committed
add support for generating slots from blender properties
1 parent a01fca4 commit a92ab7b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/utils/parser.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,21 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
370370
// Bail out if the object was pruned
371371
if (pruned !== undefined) return pruned
372372

373+
// Add custom slots if defined in the object's userData.
374+
// E.g. userData: { "slot" : "mySlot" } becomes `{ props.mySlot }`
375+
const slot = obj.userData?.slot;
376+
const hasSlot = (slot && typeof slot === "string" && slot.length > 0);
377+
const hasContent = children.length || hasSlot;
378+
379+
// Close tag if no children
380+
result += `${hasContent ? '>' : '/>'}\n`
381+
382+
// Add children
383+
if (children.length) result += `${children}\n`
384+
// Add custom slot
385+
if (hasSlot) result += `{props.${slot}}\n`;
373386
// Close tag
374-
result += `${children.length ? '>' : '/>'}\n`
375-
376-
// Add children and return
377-
if (children.length) result += children + `</${type}>`
387+
if (hasContent) result += `</${type}>`
378388
return result
379389
}
380390

0 commit comments

Comments
 (0)