Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { engine, Entity, GLTFShape, Transform } from 'decentraland-ecs'
const shape = new GLTFShape('AnimatedCube.gltf')
const gltf = new Entity()
const transform = new Transform()
transform.position.set(5, 1, 5)
gltf.addComponent(transform)
gltf.addComponent(shape)
engine.addEntity(gltf)
function createComponent(component: AnyComponent, scene: Scene) {
const { id, type, data } = component
if (!getComponentById(id)) {
switch (type) {
case ComponentType.GLTFShape: {
const { assetId } = data as ComponentData[ComponentType.GLTFShape]
const asset = scene.assets[assetId]
const url = `${assetId}/${asset.model}`
editorComponents[id] = new GLTFShape(url)
editorComponents[id].isPickable = true
break
}
case ComponentType.Transform:
editorComponents[id] = new Transform()
break
case ComponentType.NFTShape:
editorComponents[id] = new NFTShape((data as ComponentData[ComponentType.NFTShape]).url)
editorComponents[id].isPickable = true
break
case ComponentType.Script: {
const { assetId, values } = data as ComponentData[ComponentType.Script]
const asset = scene.assets[assetId]
const src = asset.contents[asset.script!]
editorComponents[id] = new Script(assetId, src, values)
if (!scriptPromises.has(assetId)) {
const url = `${scriptBaseUrl}/${src}`
const promise = fetch(url).then(resp => resp.text())
scriptPromises.set(assetId, promise)
}
break