Reference Source

src/combined/index.js

import GuiRender from "../gui/index";
import ModelRender from "../model/index";
import SkinRender from "../skin/index";
import Render from "../renderBase";

/**
 * A renderer-wrapper to combine the individual aspects of renderers into a single scene, e.g. render a player and a block at once
 */
class CombinedRender extends Render {

    /**
     * @param {Object} [options] The options for this renderer, see {@link defaultOptions}
     * @param {HTMLElement} [element=document.body] DOM Element to attach the renderer to - defaults to document.body
     */
    constructor(options, element) {
        super(options, {}, element);

        this.renderType = "CombinedRender";
    }

    /**
     * Initializes the renderer - This has to be called before {@link render}
     * @param {Render[]} renders Array of render objects
     */
    init(renders) {
        let combinedRender = this;

        super.initScene(function () {
            combinedRender.element.dispatchEvent(new CustomEvent("combinedRender", {detail: {renders: renders}}));
        }, true);


        for (let i = 0; i < renders.length; i++) {
            attachTo(renders[i], combinedRender);
        }
    };

    /**
     * Starts rendering - This has to be called after {@link init}
     */
    render() {
        this._animate();
    };
}

/**
 * @ignore
 */
function attachTo(self, target) {
    console.log("Attaching " + self.constructor.name + " to " + target.constructor.name);

    self._scene = target._scene;
    // self._camera = target._camera;
    // self._renderer = target._renderer;
    // self._composer = target._composer;
    // self._canvas = target._canvas;
    self.attached = true;
}

CombinedRender.prototype.constructor = CombinedRender;

window.CombinedRender = CombinedRender;

// Add the other render classes here, because adding them as separate scripts bugs out THREE.js
window.GuiRender = GuiRender;
window.ModelRender = ModelRender;
window.SkinRender = SkinRender;

export default CombinedRender;