Skip to main content

Editor

The Editor class provides functionality for editing and managing Fragments models. It handles operations like editing model elements, saving changes and managing edit history.

Properties​

onEdit​

onEdit: Event<object>

Event triggered when an edit is made.

Type declaration​

modelId​

modelId: string

Methods​

_update()​

_update(modelId): Promise<void>

Internal method to update the specified Fragments model. Do not use this method directly.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to update.

Returns​

Promise<void>


applyChanges()​

applyChanges(modelId, elements): Promise<number[]>

Applies changes to the specified Fragments model.

Parameters​

ParameterTypeDefault valueDescription
modelIdstringundefinedThe ID of the model to apply the changes to.
elementsElement[][]The elements to apply the changes to.

Returns​

Promise<number[]>

The applied changes.


clearElementsRequests()​

clearElementsRequests(modelId): null | (UpdateMaterialRequest | UpdateRepresentationRequest | UpdateSampleRequest | UpdateGlobalTransformRequest | UpdateLocalTransformRequest | UpdateItemRequest | UpdateMaxLocalIdRequest | UpdateRelationRequest | UpdateMetadataRequest | UpdateSpatialStructureRequest | CreateMaterialRequest | CreateRepresentationRequest | CreateSampleRequest | CreateGlobalTransformRequest | CreateLocalTransformRequest | CreateItemRequest | CreateRelationRequest | DeleteMaterialRequest | DeleteRepresentationRequest | DeleteSampleRequest | DeleteGlobalTransformRequest | DeleteLocalTransformRequest | DeleteItemRequest | DeleteRelationRequest | CreateIndexRequest | UpdateIndexRequest | DeleteIndexRequest)[]

Clears all the element edit requests of the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to clear the requests from.

Returns​

null | (UpdateMaterialRequest | UpdateRepresentationRequest | UpdateSampleRequest | UpdateGlobalTransformRequest | UpdateLocalTransformRequest | UpdateItemRequest | UpdateMaxLocalIdRequest | UpdateRelationRequest | UpdateMetadataRequest | UpdateSpatialStructureRequest | CreateMaterialRequest | CreateRepresentationRequest | CreateSampleRequest | CreateGlobalTransformRequest | CreateLocalTransformRequest | CreateItemRequest | CreateRelationRequest | DeleteMaterialRequest | DeleteRepresentationRequest | DeleteSampleRequest | DeleteGlobalTransformRequest | DeleteLocalTransformRequest | DeleteItemRequest | DeleteRelationRequest | CreateIndexRequest | UpdateIndexRequest | DeleteIndexRequest)[]


createCircleExtrusion()​

createCircleExtrusion(modelId, data): string

Creates a circle extrusion in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the circle extrusion in.
dataRawCircleExtrusionThe data of the circle extrusion to create.

Returns​

string

The created circle extrusion.


createElements()​

createElements(modelId, elements): Promise<null | Element[]>

Creates elements in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the elements in.
elementsNewElementData[]The elements to create.

Returns​

Promise<null | Element[]>

The created elements.


createGlobalTransform()​

createGlobalTransform(modelId, transform, itemId): string

Creates a global transform in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the global transform in.
transformMatrix4The global transform to create.
itemIdstring | numberThe ID of the item to create the global transform for.

Returns​

string

The created global transform.


createIndex()​

createIndex(modelId, data): void

Queues a CREATE_INDEX request on the specified model. The new index is persisted on the next applyChanges() call. See RawIndexData for the supported shapes (keys-only, 1:1, 1:N linear, 1:N nonlinear).

Live reads via model.getIndexEntry see the pending index immediately; applyChanges makes it survive a save/reload cycle.

Parameters​

ParameterType
modelIdstring
dataRawIndexData

Returns​

void


createItem()​

createItem(modelId, item): string

Creates an item in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the item in.
itemRawItemDataThe item to create.

Returns​

string

The created item.


createLocalTransform()​

createLocalTransform(modelId, transform): string

Creates a local transform in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the local transform in.
transformMatrix4The local transform to create.

Returns​

string

The created local transform.


createMaterial()​

createMaterial(modelId, material): string

Creates a material in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the material in.
materialMeshLambertMaterialThe material to create.

Returns​

string

The created material.


createSample()​

createSample(modelId, data): string

Creates a sample in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the sample in.
dataobjectThe data of the sample to create.
data.globalTransformstring | number-
data.localTransformstring | number-
data.materialstring | number-
data.representationstring | number-

Returns​

string

The created sample.


createShell()​

createShell(modelId, geometry): string

Creates a shell in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to create the shell in.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The geometry of the shell to create.

Returns​

string

The created shell.


deleteData()​

deleteData(modelId, data): Promise<void>

Deletes any type of data from the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to delete the data from.
dataobjectThe data to delete.
data.filterInUse?boolean-
data.itemIds?Iterable<number>-
data.localTransformIds?Iterable<number>-
data.materialIds?Iterable<number>-
data.representationIds?Iterable<number>-
data.sampleIds?Iterable<number>-

Returns​

Promise<void>

The deleted data.


deleteElements()​

deleteElements(modelId, elements): void

Deletes elements in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to delete the elements in.
elementsElement[]The elements to delete.

Returns​

void

The deleted elements.


deleteIndex()​

deleteIndex(modelId, name): void

Queues a DELETE_INDEX request. No-op at flush time if the named index doesn't exist on the model.

Parameters​

ParameterType
modelIdstring
namestring

Returns​

void


edit()​

edit(modelId, actions, config): Promise<number[]>

Edits a Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to edit.
actionsEditRequest[]The actions to perform on the model.
configobjectThe configuration for the edit.
config.removeRedoboolean-

Returns​

Promise<number[]>

The IDs of the elements that were edited.


getElements()​

getElements(modelId, localIds): Promise<Element[]>

Gets the elements of the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to get the elements from.
localIdsIterable<number>The local IDs of the elements to get.

Returns​

Promise<Element[]>

The elements of the model.


getModelRequests()​

getModelRequests(modelId): Promise<object>

Gets the requests of the specified Fragments model. Useful for building a history menu.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to get the requests from.

Returns​

Promise<object>

The requests of the model.

requests​

requests: EditRequest[]

undoneRequests​

undoneRequests: EditRequest[]


getModelRequestsSince()​

getModelRequestsSince(modelId, from, generation): Promise <EditRequestsSince>

Gets the requests of the specified Fragments model added since an earlier call.

Parameters​

ParameterTypeDefault valueDescription
modelIdstringundefinedThe ID of the model to get the requests from.
fromnumber0The count of the previous result (0 the first time).
generationnumber-1The generation of the previous result (-1 the first time).

Returns​

Promise <EditRequestsSince>

The requests from from on, the request count and the generation of the log.

Remarks​

Reading only what was added keeps a long unsaved session cheap to follow: every request is copied from the worker once. Pass the count and generation of the previous result. If requests were undone, selected, set or reset since, all of them are returned and from is 0. The same happens after save, or after the model is disposed and loaded again with the same ID: the log starts again (save leaves it empty) under a new generation, so check from before appending to what was read earlier.


relate()​

relate(modelId, itemId, relationName, itemIds): Promise<void>

Relates an item to other items in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to relate the item in.
itemIdnumberThe ID of the item to relate.
relationNamestringThe name of the relation to relate.
itemIdsnumber[]The IDs of the items to relate.

Returns​

Promise<void>

The related items.


reset()​

reset(modelId): Promise<void>

Resets the edits of the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to reset.

Returns​

Promise<void>


save()​

save(modelId): Promise<null | object>

Saves all the edits of the specified Fragments model. Useful for exporting the model with the edits applied. Similar to "Saving" the changes in a BIM app.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to save.

Returns​

Promise<null | object>

The requests that were saved.


selectRequest()​

selectRequest(modelId, index): Promise<void>

Selects an edit request of the specified Fragments model to set the model in the state it was after the request was applied.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to select the request from.
indexnumberThe index of the request to select.

Returns​

Promise<void>

The selected request.


setItem()​

setItem(modelId, item): void

Sets an item in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to set the item in.
itemItemDataThe item to set.

Returns​

void

The set item.


unrelate()​

unrelate(modelId, itemId, relationName, itemIds): Promise<void>

Removes a relation between an item and other items in the specified Fragments model.

Parameters​

ParameterTypeDescription
modelIdstringThe ID of the model to unrelate the item in.
itemIdnumberThe ID of the item to unrelate.
relationNamestringThe name of the relation to unrelate.
itemIdsnumber[]The IDs of the items to unrelate.

Returns​

Promise<void>

The unrelated items.


updateIndex()​

updateIndex(modelId, data): void

Queues an UPDATE_INDEX request. Replaces the index identified by data.name in its entirety. Use deleteIndex + createIndex if you want to rename.

Parameters​

ParameterType
modelIdstring
dataRawIndexData

Returns​

void