From 91d7ba6cbf708e58ac9c2e4ba2bff8e1426c5140 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 9 May 2024 03:02:37 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20MRjs=20-=20Auto=20Generated=20Di?= =?UTF-8?q?st=20=F0=9F=91=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes from `github.com/Volumetrics-io/mrjs` at 2427764818d7a4a741aa6254e537485663ce59e6 -includes folder updates: `static/dist` -runs smoo.sh before committing --- source/static/dist/mr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/static/dist/mr.js b/source/static/dist/mr.js index d5ce03c..08e9bff 100644 --- a/source/static/dist/mr.js +++ b/source/static/dist/mr.js @@ -498,7 +498,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ AnimationSystem: () => (/* binding */ AnimationSystem)\n/* harmony export */ });\n/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! three */ \"./node_modules/three/build/three.module.js\");\n/* harmony import */ var mrjs_core_MRSystem__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! mrjs/core/MRSystem */ \"./src/core/MRSystem.js\");\n/* harmony import */ var mrjs_core_MREntity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! mrjs/core/MREntity */ \"./src/core/MREntity.js\");\n/* harmony import */ var mrjs_core_entities_MRDivEntity__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! mrjs/core/entities/MRDivEntity */ \"./src/core/entities/MRDivEntity.js\");\n/* harmony import */ var mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! mrjs/core/entities/MRModelEntity */ \"./src/core/entities/MRModelEntity.js\");\n/* harmony import */ var mrjs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! mrjs */ \"./src/index.js\");\n\n\n\n\n\n\n\n\n\n/**\n * @class AnimationSystem\n * @classdesc Handles specific needs for setting up the masking for all necessary items.\n * @augments MRSystem\n */\nclass AnimationSystem extends mrjs_core_MRSystem__WEBPACK_IMPORTED_MODULE_0__.MRSystem {\n /**\n * @class\n * @description AnimationSystem's default constructor.\n */\n constructor() {\n super();\n }\n\n /**\n * @function\n * @description Updates each animation mixer in the registry. This function should be called\n * within the main animation loop of the application. It iterates through all the\n * animation mixers stored in the registry and updates them with the given deltaTime.\n * The deltaTime parameter is typically the time elapsed since the last frame\n * which is used to ensure smooth animation playback.\n * @param {number} deltaTime - The time elapsed since the last update call, used to update the animation mixers.\n * @param {object} frame - Additional frame information, not used in the current implementation but can be utilized for future enhancements.\n */\n update(deltaTime, frame) {\n for (const entity of this.registry) {\n if (entity.mixer) {\n entity.mixer.update(deltaTime);\n }\n }\n }\n\n /**\n * @function\n * @description (async) Called when the entity component is initialized\n * @param {object} entity - the entity being attached/initialized.\n */\n async attachedComponent(entity) {\n let comp = entity.components.get('animation');\n // the animations list does not load immediately, so we set a promise to wait for the model to load.\n await new Promise((resolve) => {\n const interval = setInterval(() => {\n if (entity.loaded) {\n clearInterval(interval);\n resolve();\n }\n }, 100); // Checks every 100ms\n });\n\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n // Create a mixer for each Model instance with animations\n if (!entity.mixer) {\n // set it only if not yet set by onNewEntity\n entity.mixer = new three__WEBPACK_IMPORTED_MODULE_5__.AnimationMixer(entity.object3D);\n }\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Called when the entity component is updated\n * @param {object} entity - the entity being updated based on the component.\n */\n updatedComponent(entity) {\n let comp = entity.components.get('animation');\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Called when the entity component is detached\n * @param {object} entity - the entity being updated based on the component being detached.\n */\n detachedComponent(entity) {\n entity.mixer.stopAllActions();\n }\n\n /**\n * @function\n * @description When the system swaps to a new entity, this handles setting up the animations for the system runs.\n * @param {object} entity - given entity that might be handled by the system.\n */\n onNewEntity(entity) {\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n let comp = entity.components.get('animation');\n if (!comp) {\n return;\n }\n this.registry.add(entity);\n if (!entity.mixer) {\n // set it only if not yet set by attachedComponent\n entity.mixer = new three__WEBPACK_IMPORTED_MODULE_5__.AnimationMixer(entity.object3D);\n }\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Sets the Animation of the entity object based on the component value associated with it. Otherwise lets those\n * be handled by the threejs default setup. (Always looping, always playing based on browser type, etc).\n * @param {object} entity - the entity being updated based on the component being detached.\n * @param {object} comp - component that contains the values of 'action', 'loop', and/or 'loopMode'\n */\n setAnimation(entity, comp) {\n const _perform = (clip, comp, action, entity) => {\n /* ----- Handle all the settings for the animation ----- */\n\n // Handle ending position. Threejs defaults to the starting position; when\n // `clampWhenFinished` is true, it defaults the stop position as the ending\n // clip of the animation.\n action.clampWhenFinished = comp.clampWhenFinished ?? false;\n\n let hasLoop = comp.hasOwnProperty('loop');\n let hasLoopMode = comp.hasOwnProperty('loopMode');\n if (hasLoop || hasLoopMode) {\n if (hasLoop && !hasLoopMode) {\n switch (comp.loop) {\n case true:\n case 'true':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopRepeat, Infinity);\n break;\n case false:\n case 'false':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n break;\n default:\n // loopMode doesnt exist so we hit an unexpected value\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err(\n 'Bad configuration for loop. It isnt set to true/false (did you mean to pair it with loopMode?) specified in the AnimationSystem from entity:',\n entity,\n ' Comp:',\n comp\n );\n return;\n }\n } else if (hasLoopMode && !hasLoop) {\n // The only time where loop doesnt need to exist but loopMode does is for 'once'. Additionally, note that we also\n // handle this version of loopMode even in the case where loop count exists.\n if (comp.loopMode === 'once') {\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n } else {\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err(\n 'Bad configuration, loopMode isnt `once`, but loop isnt set (did you mean to pair it with loop?) specified in the AnimationSystem from entity:',\n entity,\n ' Comp:',\n comp\n );\n return;\n }\n } else if (hasLoop && hasLoopMode) {\n // Convert comp.loop to a number, and check if it's a valid normal number or Infinity\n let loopCount = Number(comp.loop);\n if (!((Number.isInteger(loopCount) && loopCount >= 0) || loopCount === Infinity)) {\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('loop must be a non-negative integer or Infinity when using loop as count. Entity:', entity, ' Comp:', comp);\n return;\n }\n // Use the appropriate looping based on loopMode\n switch (comp.loopMode) {\n case 'repeat':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopRepeat, loopCount);\n break;\n case 'pingpong':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopPingPong, loopCount);\n break;\n case 'once':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n break;\n default:\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Unknown loopMode specified in the AnimationSystem from entity:', entity, ' Comp:', comp);\n break;\n }\n } else {\n // hasLoop and both hasLoopMode are false, should never reach this case so error as failsafe\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Hit unreachable code - major error in AnimationSystem loop handling');\n }\n }\n\n /* ----- Now actually handle playing the animation ----- */\n\n if (comp.hasOwnProperty('action')) {\n switch (comp.action) {\n case 'play':\n action.reset().play();\n break;\n case 'pause':\n action.pause();\n break;\n case 'stop':\n action.stop();\n break;\n default:\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Unknown case hit for action in the AnimationSystem from entity:', entity, '. Comp is:', comp);\n return;\n }\n }\n };\n\n // XXX in future - add conditions to play specific animations based on names/properties/etc.\n //\n // For now, just hitting the user-specific clip or looping through all existing ones to\n // update as needed.\n if (comp.hasOwnProperty('clip')) {\n let clip = entity.animations[comp.clip];\n\n entity.traverseObjects((object) => {\n if (object.isMesh) {\n // Check if there are any animation clips associated with the child object3D\n if (clip && clip.duration !== undefined && clip.duration > 0) {\n // If an animation clip is found and it has a valid duration, play it\n let action = entity.mixer.clipAction(clip);\n _perform(clip, comp, action, entity);\n }\n }\n });\n } else {\n entity.animations.forEach((clip, index) => {\n let action = entity.mixer.clipAction(clip);\n _perform(clip, comp, action, entity);\n });\n }\n }\n}\n\n\n//# sourceURL=webpack://mrjs/./src/core/componentSystems/AnimationSystem.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ AnimationSystem: () => (/* binding */ AnimationSystem)\n/* harmony export */ });\n/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! three */ \"./node_modules/three/build/three.module.js\");\n/* harmony import */ var mrjs_core_MRSystem__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! mrjs/core/MRSystem */ \"./src/core/MRSystem.js\");\n/* harmony import */ var mrjs_core_MREntity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! mrjs/core/MREntity */ \"./src/core/MREntity.js\");\n/* harmony import */ var mrjs_core_entities_MRDivEntity__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! mrjs/core/entities/MRDivEntity */ \"./src/core/entities/MRDivEntity.js\");\n/* harmony import */ var mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! mrjs/core/entities/MRModelEntity */ \"./src/core/entities/MRModelEntity.js\");\n/* harmony import */ var mrjs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! mrjs */ \"./src/index.js\");\n\n\n\n\n\n\n\n\n\n/**\n * @class AnimationSystem\n * @classdesc Handles specific needs for setting up the masking for all necessary items.\n * @augments MRSystem\n */\nclass AnimationSystem extends mrjs_core_MRSystem__WEBPACK_IMPORTED_MODULE_0__.MRSystem {\n /**\n * @class\n * @description AnimationSystem's default constructor.\n */\n constructor() {\n super();\n }\n\n /**\n * @function\n * @description Updates each animation mixer in the registry. This function should be called\n * within the main animation loop of the application. It iterates through all the\n * animation mixers stored in the registry and updates them with the given deltaTime.\n * The deltaTime parameter is typically the time elapsed since the last frame\n * which is used to ensure smooth animation playback.\n * @param {number} deltaTime - The time elapsed since the last update call, used to update the animation mixers.\n * @param {object} frame - Additional frame information, not used in the current implementation but can be utilized for future enhancements.\n */\n update(deltaTime, frame) {\n for (const entity of this.registry) {\n if (entity.mixer) {\n entity.mixer.update(deltaTime);\n }\n }\n }\n\n /**\n * @function\n * @description (async) Called when the entity component is initialized\n * @param {object} entity - the entity being attached/initialized.\n */\n async attachedComponent(entity) {\n let comp = entity.components.get('animation');\n // the animations list does not load immediately, so we set a promise to wait for the model to load.\n await new Promise((resolve) => {\n const interval = setInterval(() => {\n if (entity.loaded) {\n clearInterval(interval);\n resolve();\n }\n }, 100); // Checks every 100ms\n });\n\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n // Create a mixer for each Model instance with animations\n if (!entity.mixer) {\n // set it only if not yet set by onNewEntity\n entity.mixer = new three__WEBPACK_IMPORTED_MODULE_5__.AnimationMixer(entity.object3D);\n }\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Called when the entity component is updated\n * @param {object} entity - the entity being updated based on the component.\n */\n updatedComponent(entity) {\n let comp = entity.components.get('animation');\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Called when the entity component is detached\n * @param {object} entity - the entity being updated based on the component being detached.\n */\n detachedComponent(entity) {\n entity.mixer.stopAllActions();\n }\n\n /**\n * @function\n * @description When the system swaps to a new entity, this handles setting up the animations for the system runs.\n * @param {object} entity - given entity that might be handled by the system.\n */\n onNewEntity(entity) {\n if (entity instanceof mrjs_core_entities_MRModelEntity__WEBPACK_IMPORTED_MODULE_3__.MRModelEntity && entity.animations.length > 0) {\n let comp = entity.components.get('animation');\n if (!comp) {\n return;\n }\n this.registry.add(entity);\n if (!entity.mixer) {\n // set it only if not yet set by attachedComponent\n entity.mixer = new three__WEBPACK_IMPORTED_MODULE_5__.AnimationMixer(entity.object3D);\n }\n this.setAnimation(entity, comp);\n }\n }\n\n /**\n * @function\n * @description Sets the Animation of the entity object based on the component value associated with it. Otherwise lets those\n * be handled by the threejs default setup. (Always looping, always playing based on browser type, etc).\n * @param {object} entity - the entity being updated based on the component being detached.\n * @param {object} comp - component that contains the values of 'action', 'loop', and/or 'loopMode'\n */\n setAnimation(entity, comp) {\n const _perform = (clip, comp, action, entity) => {\n /* ----- Handle all the settings for the animation ----- */\n\n // Handle ending position. Threejs defaults to the starting position; when\n // `clampWhenFinished` is true, it defaults the stop position as the ending\n // clip of the animation.\n action.clampWhenFinished = comp.clampWhenFinished ?? false;\n\n let hasLoop = comp.hasOwnProperty('loop');\n let hasLoopMode = comp.hasOwnProperty('loopMode');\n if (hasLoop || hasLoopMode) {\n if (hasLoop && !hasLoopMode) {\n switch (comp.loop) {\n case true:\n case 'true':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopRepeat, Infinity);\n break;\n case false:\n case 'false':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n break;\n default:\n // loopMode doesnt exist so we hit an unexpected value\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err(\n 'Bad configuration for loop. It isnt set to true/false (did you mean to pair it with loopMode?) specified in the AnimationSystem from entity:',\n entity,\n ' Comp:',\n comp\n );\n return;\n }\n } else if (hasLoopMode && !hasLoop) {\n // The only time where loop doesnt need to exist but loopMode does is for 'once'. Additionally, note that we also\n // handle this version of loopMode even in the case where loop count exists.\n if (comp.loopMode === 'once') {\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n } else {\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err(\n 'Bad configuration, loopMode isnt `once`, but loop isnt set (did you mean to pair it with loop?) specified in the AnimationSystem from entity:',\n entity,\n ' Comp:',\n comp\n );\n return;\n }\n } else if (hasLoop && hasLoopMode) {\n // Convert comp.loop to a number, and check if it's a valid normal number or Infinity\n let loopCount = Number(comp.loop);\n if (!((Number.isInteger(loopCount) && loopCount >= 0) || loopCount === Infinity)) {\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('loop must be a non-negative integer or Infinity when using loop as count. Entity:', entity, ' Comp:', comp);\n return;\n }\n // Use the appropriate looping based on loopMode\n switch (comp.loopMode) {\n case 'repeat':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopRepeat, loopCount);\n break;\n case 'pingpong':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopPingPong, loopCount);\n break;\n case 'once':\n action.setLoop(three__WEBPACK_IMPORTED_MODULE_5__.LoopOnce, 1);\n break;\n default:\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Unknown loopMode specified in the AnimationSystem from entity:', entity, ' Comp:', comp);\n break;\n }\n } else {\n // hasLoop and both hasLoopMode are false, should never reach this case so error as failsafe\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Hit unreachable code - major error in AnimationSystem loop handling');\n }\n }\n\n /* ----- Now actually handle playing the animation ----- */\n\n if (comp.hasOwnProperty('action')) {\n switch (comp.action) {\n case 'play':\n action.reset().play();\n break;\n case 'pause':\n action.pause();\n break;\n case 'stop':\n action.stop();\n break;\n default:\n mrjs__WEBPACK_IMPORTED_MODULE_4__.mrjsUtils.error.err('Unknown case hit for action in the AnimationSystem from entity:', entity, '. Comp is:', comp);\n return;\n }\n }\n };\n\n // Figure out what clips we want to run in the animation sequence.\n let clips = [];\n if (comp.hasOwnProperty('clip')) {\n // By clip number, by name, or all as default\n if (typeof comp.clip === 'number') {\n clips = [entity.animations[comp.clip]].filter(Boolean);\n } else if (typeof comp.clip === 'string') {\n clips = entity.animations.filter((clip) => clip.name === comp.clip);\n } else {\n console.warn('On Entity in AnimationSystem. Could not find designated comp clip so using all animations:', entity, comp.clip);\n clips = entity.animations;\n }\n } else {\n clips = entity.animations;\n }\n\n // Make sure we're only running the actions we want to run. That is,\n // if there's others currently playing in the mixer, stop them.\n //\n // If any of the clips are the same, we assume the user is handling\n // the comp.action as theyre expecting, so we do not manually stop those.\n const currentActions = entity.mixer._actions.filter((currentAction) => !clips.includes(currentAction._clip));\n currentActions.forEach((currentAction) => currentAction.stop());\n\n // Handle running the clips with normal and multi-layer meshes.\n clips.forEach((clip) => {\n entity.traverseObjects((object) => {\n if (object.isMesh && clip && clip.duration !== undefined && clip.duration > 0) {\n const action = entity.mixer.clipAction(clip);\n _perform(clip, comp, action, entity);\n }\n });\n });\n }\n}\n\n\n//# sourceURL=webpack://mrjs/./src/core/componentSystems/AnimationSystem.js?"); /***/ }), @@ -1047,7 +1047,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ model: () => (/* binding */ model)\n/* harmony export */ });\n/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! three */ \"./node_modules/three/build/three.module.js\");\n/* harmony import */ var three_addons_loaders_ColladaLoader_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! three/addons/loaders/ColladaLoader.js */ \"./node_modules/three/examples/jsm/loaders/ColladaLoader.js\");\n/* harmony import */ var three_addons_loaders_FBXLoader_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! three/addons/loaders/FBXLoader.js */ \"./node_modules/three/examples/jsm/loaders/FBXLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_GLTFLoader_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! three/examples/jsm/loaders/GLTFLoader.js */ \"./node_modules/three/examples/jsm/loaders/GLTFLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_STLLoader_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! three/examples/jsm/loaders/STLLoader.js */ \"./node_modules/three/examples/jsm/loaders/STLLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_USDZLoader_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! three/examples/jsm/loaders/USDZLoader.js */ \"./node_modules/three/examples/jsm/loaders/USDZLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three/examples/jsm/loaders/OBJLoader.js */ \"./node_modules/three/examples/jsm/loaders/OBJLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_MTLLoader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! three/examples/jsm/loaders/MTLLoader.js */ \"./node_modules/three/examples/jsm/loaders/MTLLoader.js\");\n\n\n\n\n\n\n\n\n\n// Keeping the below imports in as reference for future items we can add.\n// import { AMFLoader } from 'three/addons/loaders/AMFLoader.js';\n// import { BVHLoader } from 'three/addons/loaders/BVHLoader.js';\n// import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';\n// import { GCodeLoader } from 'three/addons/loaders/GCodeLoader.js';\n// import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';\n// // import { IFCLoader } from 'web-ifc-three';\n// // import { IFCSPACE } from 'web-ifc';\n// import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';\n// import { PCDLoader } from 'three/addons/loaders/PCDLoader.js';\n// import { PDBLoader } from 'three/addons/loaders/PDBLoader.js';\n// import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';\n// import { SVGLoader } from 'three/addons/loaders/SVGLoader.js';\n// import { TDSLoader } from 'three/addons/loaders/TDSLoader.js';\n// import { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';\n\n/**\n * @namespace model\n * @description Useful namespace for helping with Model utility functions\n */\nlet model = {};\n\n/**\n * @function\n * @memberof model\n * @description Loads Collada file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadDAE = async function (filePath) {\n const loader = new three_addons_loaders_ColladaLoader_js__WEBPACK_IMPORTED_MODULE_0__.ColladaLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (dae) => {\n resolve(dae.scene);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads OBJ file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadOBJ = async function (filePath) {\n const loader = new three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__.OBJLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (obj) => {\n resolve(obj);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads OBJ file with externally hosted MTL file\n * @param {string} filePath - The path of the form '/path/to/mtlFile.mtl,/path/to/objFile.obj'.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadOBJWithMTL = function (filePath) {\n let paths = filePath.split(',');\n // Assigning each path to a variable\n if (paths.length != 2) {\n console.error('Expected the loading of an MTL file and an OBJ file like \"path/to/mtlFile.mtl,path/to/the/objFile.obj\" - got:', filePath);\n return Promise.reject(new Error('Invalid path format for OBJ and MTL files.'));\n }\n\n const filePathMTL = paths[0];\n const filePathOBJ = paths[1];\n\n const loadMTL = (url) =>\n new Promise((resolve, reject) => {\n const mtlLoader = new three_examples_jsm_loaders_MTLLoader_js__WEBPACK_IMPORTED_MODULE_2__.MTLLoader();\n mtlLoader.load(\n url,\n (materials) => {\n materials.preload();\n resolve(materials);\n },\n undefined,\n (error) => {\n console.error('Failed to load MTL from URL:', error);\n reject(error);\n }\n );\n });\n\n const loadOBJ = (filePath, materials) =>\n new Promise((resolve, reject) => {\n const objLoader = new three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__.OBJLoader();\n objLoader.setMaterials(materials);\n objLoader.load(\n filePath,\n (obj) => {\n resolve(obj);\n },\n undefined,\n (error) => {\n console.error('Failed to load OBJ:', error);\n reject(error);\n }\n );\n });\n\n return loadMTL(filePathMTL)\n .then((materials) => loadOBJ(filePathOBJ, materials))\n .catch((error) => {\n console.error('An error occurred while loading OBJ with external MTL:', error);\n throw error; // Ensure errors are propagated\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads FBX file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadFBX = async function (filePath) {\n const loader = new three_addons_loaders_FBXLoader_js__WEBPACK_IMPORTED_MODULE_3__.FBXLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (fbx) => {\n resolve(fbx);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads GLTF/GLB file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadGLTF = async function (filePath) {\n const loader = new three_examples_jsm_loaders_GLTFLoader_js__WEBPACK_IMPORTED_MODULE_4__.GLTFLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (gltf) => {\n const scene = gltf.scene;\n const animations = gltf.animations;\n\n // Resolve the promise with the loaded scene and animations\n resolve({ scene, animations });\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads stl file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadSTL = async function (filePath) {\n const loader = new three_examples_jsm_loaders_STLLoader_js__WEBPACK_IMPORTED_MODULE_5__.STLLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (geometry) => {\n const material = new three__WEBPACK_IMPORTED_MODULE_6__.MeshPhongMaterial();\n const mesh = new three__WEBPACK_IMPORTED_MODULE_6__.Mesh(geometry, material);\n\n resolve(mesh); // Resolve the promise with the loaded mesh\n },\n (xhr) => {\n // Progress callback\n },\n (error) => {\n console.error(error);\n reject(error); // Reject the promise if there's an error\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads USD/USDZ file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadUSDZ = async function (filePath) {\n const usdzLoader = new three_examples_jsm_loaders_USDZLoader_js__WEBPACK_IMPORTED_MODULE_7__.USDZLoader();\n\n const [model] = await Promise.all([usdzLoader.loadAsync(filePath)], undefined, (error) => {\n console.error(error);\n return null;\n });\n\n return model;\n};\n\n/// ////////////////////////\n// Main Loading Function //\n/// ////////////////////////\n\n/**\n * @function\n * @memberof model\n * @description The main loading function\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @param {string} extension - The extension of the file type. Current allowed extensions are `dae`, fbx`, `glb`, `obj`, and `stl`.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadModel = async function (filePath, extension) {\n // Flag used for debugging the ones that are only 'partially implemented' and\n // still as todos.\n const allowed = false;\n\n if (extension == 'fbx') {\n return model.loadFBX(filePath);\n } else if (extension == 'glb') {\n return model.loadGLTF(filePath);\n } else if (allowed && extension == 'gltf') {\n // TODO\n return model.loadGLTF(filePath);\n } else if (extension == 'stl') {\n return model.loadSTL(filePath);\n } else if (extension == 'obj') {\n if (filePath.includes(',')) {\n // has a preceeding material file\n return model.loadOBJWithMTL(filePath);\n } else {\n return model.loadOBJ(filePath);\n }\n } else if (extension == 'dae') {\n return model.loadDAE(filePath);\n } else if (allowed && (extension == 'usdc' || extension == 'usdz')) {\n // TODO\n return model.loadUSDZ(filePath);\n }\n console.error(`ERR: the extensions ${extension} is not supported by MR.js`);\n return null;\n};\n\nmodel.disposeObject3D = function (parentObject3D) {\n parentObject3D.traverse(function (node) {\n if (node.isMesh) {\n if (node.geometry) {\n node.geometry.dispose();\n }\n\n if (node.material) {\n if (node.material instanceof Array) {\n // An array of materials\n node.material.forEach((material) => material.dispose());\n } else {\n // A single material\n node.material.dispose();\n }\n }\n }\n });\n};\n\nmodel.removeObject3DFromScene = function (object3D, scene) {\n model.disposeObject3D(object3D);\n scene.remove(object3D);\n\n // Optional: Clean up references for GC if necessary\n};\n\n\n\n\n//# sourceURL=webpack://mrjs/./src/utils/Model.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ model: () => (/* binding */ model)\n/* harmony export */ });\n/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! three */ \"./node_modules/three/build/three.module.js\");\n/* harmony import */ var three_addons_loaders_ColladaLoader_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! three/addons/loaders/ColladaLoader.js */ \"./node_modules/three/examples/jsm/loaders/ColladaLoader.js\");\n/* harmony import */ var three_addons_loaders_FBXLoader_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! three/addons/loaders/FBXLoader.js */ \"./node_modules/three/examples/jsm/loaders/FBXLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_GLTFLoader_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! three/examples/jsm/loaders/GLTFLoader.js */ \"./node_modules/three/examples/jsm/loaders/GLTFLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_STLLoader_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! three/examples/jsm/loaders/STLLoader.js */ \"./node_modules/three/examples/jsm/loaders/STLLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_USDZLoader_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! three/examples/jsm/loaders/USDZLoader.js */ \"./node_modules/three/examples/jsm/loaders/USDZLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three/examples/jsm/loaders/OBJLoader.js */ \"./node_modules/three/examples/jsm/loaders/OBJLoader.js\");\n/* harmony import */ var three_examples_jsm_loaders_MTLLoader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! three/examples/jsm/loaders/MTLLoader.js */ \"./node_modules/three/examples/jsm/loaders/MTLLoader.js\");\n\n\n\n\n\n\n\n\n\n// Keeping the below imports in as reference for future items we can add.\n// import { AMFLoader } from 'three/addons/loaders/AMFLoader.js';\n// import { BVHLoader } from 'three/addons/loaders/BVHLoader.js';\n// import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';\n// import { GCodeLoader } from 'three/addons/loaders/GCodeLoader.js';\n// import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';\n// // import { IFCLoader } from 'web-ifc-three';\n// // import { IFCSPACE } from 'web-ifc';\n// import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';\n// import { PCDLoader } from 'three/addons/loaders/PCDLoader.js';\n// import { PDBLoader } from 'three/addons/loaders/PDBLoader.js';\n// import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';\n// import { SVGLoader } from 'three/addons/loaders/SVGLoader.js';\n// import { TDSLoader } from 'three/addons/loaders/TDSLoader.js';\n// import { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';\n\n/**\n * @namespace model\n * @description Useful namespace for helping with Model utility functions\n */\nlet model = {};\n\n/**\n * @function\n * @memberof model\n * @description Loads Collada file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadDAE = async function (filePath) {\n const loader = new three_addons_loaders_ColladaLoader_js__WEBPACK_IMPORTED_MODULE_0__.ColladaLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (dae) => {\n resolve(dae.scene);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads OBJ file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadOBJ = async function (filePath) {\n const loader = new three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__.OBJLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (obj) => {\n resolve(obj);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads OBJ file with externally hosted MTL file\n * @param {string} filePath - The path of the form '/path/to/mtlFile.mtl,/path/to/objFile.obj'.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadOBJWithMTL = function (filePath) {\n let paths = filePath.split(',');\n // Assigning each path to a variable\n if (paths.length != 2) {\n console.error('Expected the loading of an MTL file and an OBJ file like \"path/to/mtlFile.mtl,path/to/the/objFile.obj\" - got:', filePath);\n return Promise.reject(new Error('Invalid path format for OBJ and MTL files.'));\n }\n\n const filePathMTL = paths[0];\n const filePathOBJ = paths[1];\n\n const loadMTL = (url) =>\n new Promise((resolve, reject) => {\n const mtlLoader = new three_examples_jsm_loaders_MTLLoader_js__WEBPACK_IMPORTED_MODULE_2__.MTLLoader();\n mtlLoader.load(\n url,\n (materials) => {\n materials.preload();\n resolve(materials);\n },\n undefined,\n (error) => {\n console.error('Failed to load MTL from URL:', error);\n reject(error);\n }\n );\n });\n\n const loadOBJ = (filePath, materials) =>\n new Promise((resolve, reject) => {\n const objLoader = new three_examples_jsm_loaders_OBJLoader_js__WEBPACK_IMPORTED_MODULE_1__.OBJLoader();\n objLoader.setMaterials(materials);\n objLoader.load(\n filePath,\n (obj) => {\n resolve(obj);\n },\n undefined,\n (error) => {\n console.error('Failed to load OBJ:', error);\n reject(error);\n }\n );\n });\n\n return loadMTL(filePathMTL)\n .then((materials) => loadOBJ(filePathOBJ, materials))\n .catch((error) => {\n console.error('An error occurred while loading OBJ with external MTL:', error);\n throw error; // Ensure errors are propagated\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads FBX file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadFBX = async function (filePath) {\n const loader = new three_addons_loaders_FBXLoader_js__WEBPACK_IMPORTED_MODULE_3__.FBXLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (fbx) => {\n resolve(fbx);\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads GLTF/GLB file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadGLTF = async function (filePath) {\n const loader = new three_examples_jsm_loaders_GLTFLoader_js__WEBPACK_IMPORTED_MODULE_4__.GLTFLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (gltf) => {\n const scene = gltf.scene;\n const animations = gltf.animations;\n\n // Resolve the promise with the loaded scene and animations\n resolve({ scene, animations });\n },\n undefined,\n (error) => {\n console.error(error);\n reject(error);\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads stl file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadSTL = async function (filePath) {\n const loader = new three_examples_jsm_loaders_STLLoader_js__WEBPACK_IMPORTED_MODULE_5__.STLLoader();\n\n return new Promise((resolve, reject) => {\n loader.load(\n filePath,\n (geometry) => {\n const material = new three__WEBPACK_IMPORTED_MODULE_6__.MeshPhongMaterial();\n const mesh = new three__WEBPACK_IMPORTED_MODULE_6__.Mesh(geometry, material);\n\n resolve(mesh); // Resolve the promise with the loaded mesh\n },\n (xhr) => {\n // Progress callback\n },\n (error) => {\n console.error(error);\n reject(error); // Reject the promise if there's an error\n }\n );\n });\n};\n\n/**\n * @function\n * @memberof model\n * @description Loads USD/USDZ file\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadUSDZ = async function (filePath) {\n const usdzLoader = new three_examples_jsm_loaders_USDZLoader_js__WEBPACK_IMPORTED_MODULE_7__.USDZLoader();\n\n const [model] = await Promise.all([usdzLoader.loadAsync(filePath)], undefined, (error) => {\n console.error(error);\n return null;\n });\n\n return model;\n};\n\n/// ////////////////////////\n// Main Loading Function //\n/// ////////////////////////\n\n/**\n * @function\n * @memberof model\n * @description The main loading function\n * @param {string} filePath - The path to the file(s) needing to be loaded. For now this only supports\n * the full path and the relative path directly to the file.\n * @param {string} extension - The extension of the file type. Current allowed extensions are `dae`, fbx`, `glb`, `obj`, and `stl`.\n * @returns {Promise} - the promise of the loaded mesh object.\n */\nmodel.loadModel = async function (filePath, extension) {\n // Flag used for debugging the ones that are only 'partially implemented' and\n // still as todos.\n const allowed = false;\n\n if (extension == 'fbx') {\n return model.loadFBX(filePath);\n } else if (extension == 'glb') {\n return model.loadGLTF(filePath);\n } else if (allowed && extension == 'gltf') {\n // TODO\n return model.loadGLTF(filePath);\n } else if (extension == 'stl') {\n return model.loadSTL(filePath);\n } else if (extension == 'obj') {\n if (filePath.includes(',')) {\n // has a preceeding material file\n return model.loadOBJWithMTL(filePath);\n } else {\n return model.loadOBJ(filePath);\n }\n } else if (extension == 'dae') {\n return model.loadDAE(filePath);\n } else if (allowed && (extension == 'usdc' || extension == 'usdz')) {\n // TODO\n return model.loadUSDZ(filePath);\n }\n console.error(`ERR: the extensions ${extension} is not supported by MR.js`);\n return null;\n};\n\nmodel.disposeObject3D = function (parentObject3D) {\n parentObject3D.traverse(function (node) {\n if (node.isMesh) {\n if (node.geometry) {\n node.geometry.dispose();\n }\n\n if (node.material) {\n if (node.material instanceof Array) {\n // An array of materials\n node.material.forEach((material) => material.dispose());\n } else {\n // A single material\n node.material.dispose();\n }\n }\n }\n });\n};\n\nmodel.removeObject3DFromScene = function (object3D, scene) {\n model.disposeObject3D(object3D);\n scene.remove(object3D);\n\n // Optional: Clean up references for GC if necessary\n};\n\nmodel.currentRunningAnimationClip = function (entity) {\n if (!entity.mixer) {\n console.log('No mixer found for :', entity);\n return;\n }\n // If no animation is currently playing\n if (!entity.mixer._actions.some((action) => action.isRunning())) {\n console.log('No animation is currently playing');\n return;\n }\n\n // Iterate over all clip actions in the mixer\n for (let i = 0; i < entity.mixer._actions.length; i++) {\n let clipAction = entity._actions[i];\n if (clipAction.isRunning()) {\n let clipName = clipAction.getClip().name;\n console.log(\"Animation '\" + clipName + \"' is currently playing\");\n // You can do whatever you need with this information\n // break; // Break the loop if you only want to know the first running animation\n }\n }\n};\n\n\n\n\n//# sourceURL=webpack://mrjs/./src/utils/Model.js?"); /***/ }),