Skip to content

Commit 6063247

Browse files
vincentfretinclaude
andcommitted
Document the asset commands in docs/commands.md
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 81d716b commit 6063247

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

docs/commands.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,71 @@ AFRAME.INSPECTOR.execute('entityremove', entity);
133133
When executed, this emits an `entityremoved` event with `entity`.
134134
When undone, this emits an `entitycreated` event with `entity`.
135135

136+
### assetcreate
137+
138+
Create an asset element in `<a-assets>` (e.g. `a-material`, `a-mixin`, `img`, `audio`, `video`, `a-asset-item`).
139+
140+
Usage:
141+
142+
```js
143+
AFRAME.INSPECTOR.execute('assetcreate', {
144+
tagName: 'a-material'
145+
});
146+
```
147+
148+
or with an explicit id, attributes and a callback receiving the created element:
149+
150+
```js
151+
AFRAME.INSPECTOR.execute(
152+
'assetcreate',
153+
{
154+
tagName: 'img',
155+
id: 'wood',
156+
attributes: { src: 'wood.png', crossorigin: 'anonymous' }
157+
},
158+
undefined,
159+
(img) => { console.log('created', img); }
160+
);
161+
```
162+
163+
- `tagName`: element tag to create.
164+
- `id`: optional; a unique `<base>-N` id is generated otherwise (e.g. `material-1` for `a-material`). The id stays stable across undo/redo so later commands referencing the asset keep working.
165+
- `attributes`: optional object of attribute name to string value.
166+
167+
When executed, this emits an `assetcreate` event with the created element.
168+
When undone, this emits an `assetremove` event with the asset id.
169+
170+
### assetupdate
171+
172+
Update an attribute of an asset element. Consecutive updates to the same asset attribute are merged in history like entity updates.
173+
174+
Usage:
175+
176+
```js
177+
AFRAME.INSPECTOR.execute('assetupdate', {
178+
assetEl: materialEl, // element or id string
179+
attribute: 'color',
180+
value: 'green' // attribute string, or null to remove the attribute
181+
});
182+
```
183+
184+
When executed or undone, this emits an `assetupdate` event with `{assetEl, attribute, value}`.
185+
186+
### assetremove
187+
188+
Remove an asset element from `<a-assets>`. The tag name, attributes and position are captured so undo recreates the asset in place. For `<a-material>`, entities referencing the asset are re-resolved on undo so they use the recreated `THREE.Material` instance.
189+
190+
Usage:
191+
192+
```js
193+
AFRAME.INSPECTOR.execute('assetremove', {
194+
assetEl: materialEl // element or id string
195+
});
196+
```
197+
198+
When executed, this emits an `assetremove` event with the asset id.
199+
When undone, this emits an `assetcreate` event with the recreated element.
200+
136201
### multi
137202

138203
Create two entities in a row:
@@ -264,6 +329,31 @@ type EntityUpdateCommand = [
264329
},
265330
];
266331

332+
type AssetCreatePayload = {
333+
tagName: string;
334+
id?: string;
335+
attributes?: Record<string, string>;
336+
};
337+
type AssetCreateCommand =
338+
| ["assetcreate", AssetCreatePayload]
339+
| ["assetcreate", AssetCreatePayload, (el: Element) => void];
340+
341+
type AssetUpdateCommand = [
342+
"assetupdate",
343+
{
344+
assetEl: Element | string;
345+
attribute: string;
346+
value: string | null;
347+
},
348+
];
349+
350+
type AssetRemoveCommand = [
351+
"assetremove",
352+
{
353+
assetEl: Element | string;
354+
},
355+
];
356+
267357
type CommandsForMulti = (
268358
| ComponentAddCommand
269359
| ComponentRemoveCommand

0 commit comments

Comments
 (0)