import Entity from "../../../src/engine/ecs/Entity.js";
import Renderable from "../../../src/engine/ecs/renderable/Renderable.js";
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
import EditorEntity from "../../ecs/EditorEntity.js";
import Script from "../../../src/engine/ecs/components/Script.js";


/**
 *
 * @param {Object3D} helper
 * @param {number} sourceEntity
 * @return {Entity}
 */
export function buildThreeJSHelperEntity(helper, sourceEntity = -1) {
    helper.frustumCulled = false;

    const entityBuilder = new Entity();

    const renderable = new Renderable(helper);
    // renderable.matrixAutoUpdate = false;

    entityBuilder.add(new Transform());
    entityBuilder.add(new EditorEntity(sourceEntity));
    entityBuilder.add(renderable);


    if (typeof helper.update === "function") {
        entityBuilder.add(new Script(function () {
            helper.update();
        }));
    }

    renderable.computeBoundsFromObject();

    return entityBuilder;
}
