@hology/core 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. package/LICENSE.md +15 -0
  2. package/README.md +3 -0
  3. package/dist/config/project-config.d.ts +10 -0
  4. package/dist/config/project-config.js +5 -0
  5. package/dist/controllers/base-game-controller.d.ts +3 -0
  6. package/dist/controllers/base-game-controller.js +5 -0
  7. package/dist/csm.d.ts +7 -0
  8. package/dist/csm.js +5 -0
  9. package/dist/effects/particles/examples.d.ts +271 -0
  10. package/dist/effects/particles/examples.js +5 -0
  11. package/dist/effects/particles/particle-system-config.d.ts +85 -0
  12. package/dist/effects/particles/particle-system-config.js +5 -0
  13. package/dist/game-component/component-decorators.d.ts +5 -0
  14. package/dist/game-component/component-decorators.js +5 -0
  15. package/dist/game-component/game-component.d.ts +8 -0
  16. package/dist/game-component/game-component.js +5 -0
  17. package/dist/gameplay/actors/actor.d.ts +37 -0
  18. package/dist/gameplay/actors/actor.js +5 -0
  19. package/dist/gameplay/actors/builtin/camera-actor.d.ts +11 -0
  20. package/dist/gameplay/actors/builtin/camera-actor.js +5 -0
  21. package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +67 -0
  22. package/dist/gameplay/actors/builtin/components/character/character-animation.js +5 -0
  23. package/dist/gameplay/actors/builtin/components/character/character-movement copy.d.ts +37 -0
  24. package/dist/gameplay/actors/builtin/components/character/character-movement copy.js +5 -0
  25. package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +51 -0
  26. package/dist/gameplay/actors/builtin/components/character/character-movement.js +5 -0
  27. package/dist/gameplay/actors/builtin/components/character/modes.d.ts +18 -0
  28. package/dist/gameplay/actors/builtin/components/character/modes.js +5 -0
  29. package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +20 -0
  30. package/dist/gameplay/actors/builtin/components/mesh-component.js +5 -0
  31. package/dist/gameplay/actors/builtin/components/scene-component.d.ts +7 -0
  32. package/dist/gameplay/actors/builtin/components/scene-component.js +5 -0
  33. package/dist/gameplay/actors/builtin/index.d.ts +11 -0
  34. package/dist/gameplay/actors/builtin/index.js +5 -0
  35. package/dist/gameplay/actors/builtin/positional-audio-actor.d.ts +19 -0
  36. package/dist/gameplay/actors/builtin/positional-audio-actor.js +5 -0
  37. package/dist/gameplay/actors/builtin/spawn-point.d.ts +11 -0
  38. package/dist/gameplay/actors/builtin/spawn-point.js +5 -0
  39. package/dist/gameplay/actors/builtin/trigger-volume.d.ts +23 -0
  40. package/dist/gameplay/actors/builtin/trigger-volume.js +5 -0
  41. package/dist/gameplay/actors/camera/camera-component.d.ts +13 -0
  42. package/dist/gameplay/actors/camera/camera-component.js +5 -0
  43. package/dist/gameplay/actors/camera/third-party-camera-component.d.ts +43 -0
  44. package/dist/gameplay/actors/camera/third-party-camera-component.js +5 -0
  45. package/dist/gameplay/actors/component.d.ts +41 -0
  46. package/dist/gameplay/actors/component.js +5 -0
  47. package/dist/gameplay/actors/factory.d.ts +12 -0
  48. package/dist/gameplay/actors/factory.js +5 -0
  49. package/dist/gameplay/actors/index.d.ts +10 -0
  50. package/dist/gameplay/actors/index.js +5 -0
  51. package/dist/gameplay/actors/internal/component-init.d.ts +3 -0
  52. package/dist/gameplay/actors/internal/component-init.js +5 -0
  53. package/dist/gameplay/actors/internal/container-map.d.ts +6 -0
  54. package/dist/gameplay/actors/internal/container-map.js +5 -0
  55. package/dist/gameplay/animation/anim-sm.d.ts +38 -0
  56. package/dist/gameplay/animation/anim-sm.js +5 -0
  57. package/dist/gameplay/animation/root-motion.d.ts +31 -0
  58. package/dist/gameplay/animation/root-motion.js +5 -0
  59. package/dist/gameplay/env.d.ts +3 -0
  60. package/dist/gameplay/env.js +5 -0
  61. package/dist/gameplay/index.d.ts +14 -0
  62. package/dist/gameplay/index.js +5 -0
  63. package/dist/gameplay/initiate.d.ts +51 -0
  64. package/dist/gameplay/initiate.js +5 -0
  65. package/dist/gameplay/inject.d.ts +3 -0
  66. package/dist/gameplay/inject.js +5 -0
  67. package/dist/gameplay/input/index.d.ts +3 -0
  68. package/dist/gameplay/input/index.js +5 -0
  69. package/dist/gameplay/input/input-service.d.ts +33 -0
  70. package/dist/gameplay/input/input-service.js +5 -0
  71. package/dist/gameplay/input/input.d.ts +41 -0
  72. package/dist/gameplay/input/input.js +5 -0
  73. package/dist/gameplay/input/keybind.d.ts +23 -0
  74. package/dist/gameplay/input/keybind.js +5 -0
  75. package/dist/gameplay/services/asset-loader.d.ts +34 -0
  76. package/dist/gameplay/services/asset-loader.js +5 -0
  77. package/dist/gameplay/services/physics/collision-contact.d.ts +2 -0
  78. package/dist/gameplay/services/physics/collision-contact.js +5 -0
  79. package/dist/gameplay/services/physics/physics-system.d.ts +145 -0
  80. package/dist/gameplay/services/physics/physics-system.js +5 -0
  81. package/dist/gameplay/services/render.d.ts +19 -0
  82. package/dist/gameplay/services/render.js +5 -0
  83. package/dist/gameplay/services/world.d.ts +15 -0
  84. package/dist/gameplay/services/world.js +5 -0
  85. package/dist/index.d.ts +4 -0
  86. package/dist/index.js +5 -0
  87. package/dist/rendering/shader-override.d.ts +2 -0
  88. package/dist/rendering/shader-override.js +5 -0
  89. package/dist/rendering.d.ts +53 -0
  90. package/dist/rendering.js +5 -0
  91. package/dist/scene/asset-resource-loader.d.ts +32 -0
  92. package/dist/scene/asset-resource-loader.js +5 -0
  93. package/dist/scene/assets-provider.d.ts +9 -0
  94. package/dist/scene/assets-provider.js +5 -0
  95. package/dist/scene/bootstrap.d.ts +21 -0
  96. package/dist/scene/bootstrap.js +5 -0
  97. package/dist/scene/collision/collision-shape-import.d.ts +4 -0
  98. package/dist/scene/collision/collision-shape-import.js +5 -0
  99. package/dist/scene/collision/collision-shape.d.ts +59 -0
  100. package/dist/scene/collision/collision-shape.js +5 -0
  101. package/dist/scene/landscape/landscape-manager.d.ts +43 -0
  102. package/dist/scene/landscape/landscape-manager.js +5 -0
  103. package/dist/scene/landscape/landscape.d.ts +20 -0
  104. package/dist/scene/landscape/landscape.js +5 -0
  105. package/dist/scene/landscape/utils.d.ts +9 -0
  106. package/dist/scene/landscape/utils.js +5 -0
  107. package/dist/scene/materializer.d.ts +245 -0
  108. package/dist/scene/materializer.js +5 -0
  109. package/dist/scene/materials/grass-foliage.d.ts +8 -0
  110. package/dist/scene/materials/grass-foliage.js +5 -0
  111. package/dist/scene/materials/grass.d.ts +4 -0
  112. package/dist/scene/materials/grass.js +5 -0
  113. package/dist/scene/materials/utils/material-painting.d.ts +2 -0
  114. package/dist/scene/materials/utils/material-painting.js +5 -0
  115. package/dist/scene/materials/utils/noise.glsl.d.ts +1 -0
  116. package/dist/scene/materials/utils/noise.glsl.js +5 -0
  117. package/dist/scene/materials/water.d.ts +3 -0
  118. package/dist/scene/materials/water.js +5 -0
  119. package/dist/scene/model.d.ts +96 -0
  120. package/dist/scene/model.js +5 -0
  121. package/dist/scene/objects/ramp-geometry.d.ts +2 -0
  122. package/dist/scene/objects/ramp-geometry.js +5 -0
  123. package/dist/scene/objects/shapes.d.ts +121 -0
  124. package/dist/scene/objects/shapes.js +5 -0
  125. package/dist/scene/runtime-asset-service.d.ts +14 -0
  126. package/dist/scene/runtime-asset-service.js +5 -0
  127. package/dist/scene/runtime-backend-service.d.ts +12 -0
  128. package/dist/scene/runtime-backend-service.js +5 -0
  129. package/dist/scene/scene-data-service.d.ts +33 -0
  130. package/dist/scene/scene-data-service.js +5 -0
  131. package/dist/scene/sky.d.ts +3 -0
  132. package/dist/scene/sky.js +5 -0
  133. package/dist/scene/storage/storage.d.ts +39 -0
  134. package/dist/scene/storage/storage.js +5 -0
  135. package/dist/shader/builtin/index.d.ts +2 -0
  136. package/dist/shader/builtin/index.js +5 -0
  137. package/dist/shader/builtin/lambert-shader.d.ts +19 -0
  138. package/dist/shader/builtin/lambert-shader.js +5 -0
  139. package/dist/shader/builtin/standard-shader.d.ts +29 -0
  140. package/dist/shader/builtin/standard-shader.js +5 -0
  141. package/dist/shader/index.d.ts +2 -0
  142. package/dist/shader/index.js +5 -0
  143. package/dist/shader/parameter.d.ts +23 -0
  144. package/dist/shader/parameter.js +5 -0
  145. package/dist/shader/shader.d.ts +25 -0
  146. package/dist/shader/shader.js +5 -0
  147. package/dist/shader-nodes/depth.d.ts +10 -0
  148. package/dist/shader-nodes/depth.js +5 -0
  149. package/dist/shader-nodes/index.d.ts +5 -0
  150. package/dist/shader-nodes/index.js +5 -0
  151. package/dist/shader-nodes/landscape.d.ts +5 -0
  152. package/dist/shader-nodes/landscape.js +5 -0
  153. package/dist/shader-nodes/layers.d.ts +14 -0
  154. package/dist/shader-nodes/layers.js +5 -0
  155. package/dist/shader-nodes/time.d.ts +4 -0
  156. package/dist/shader-nodes/time.js +5 -0
  157. package/dist/test/injection.test.d.ts +1 -0
  158. package/dist/test/injection.test.js +5 -0
  159. package/dist/utils/async.d.ts +5 -0
  160. package/dist/utils/async.js +5 -0
  161. package/dist/utils/cannon/CannonUtils.d.ts +17 -0
  162. package/dist/utils/cannon/CannonUtils.js +5 -0
  163. package/dist/utils/cannon/three-to-cannon/ConvexHull.d.ts +47 -0
  164. package/dist/utils/cannon/three-to-cannon/ConvexHull.js +5 -0
  165. package/dist/utils/cannon/three-to-cannon/index.d.ts +63 -0
  166. package/dist/utils/cannon/three-to-cannon/index.js +5 -0
  167. package/dist/utils/cannon/three-to-cannon/utils.d.ts +9 -0
  168. package/dist/utils/cannon/three-to-cannon/utils.js +5 -0
  169. package/dist/utils/collections.d.ts +26 -0
  170. package/dist/utils/collections.js +5 -0
  171. package/dist/utils/files.d.ts +1 -0
  172. package/dist/utils/files.js +5 -0
  173. package/dist/utils/math.d.ts +24 -0
  174. package/dist/utils/math.js +5 -0
  175. package/dist/utils/mesh.d.ts +6 -0
  176. package/dist/utils/mesh.js +5 -0
  177. package/dist/utils/polyfill.d.ts +1 -0
  178. package/dist/utils/polyfill.js +5 -0
  179. package/dist/utils/three/depth-pass.d.ts +13 -0
  180. package/dist/utils/three/depth-pass.js +5 -0
  181. package/dist/utils/three/line-sphere.d.ts +2 -0
  182. package/dist/utils/three/line-sphere.js +5 -0
  183. package/dist/utils/three/outline-pass.d.ts +61 -0
  184. package/dist/utils/three/outline-pass.js +5 -0
  185. package/dist/utils/three/positional-audio-helper.d.ts +11 -0
  186. package/dist/utils/three/positional-audio-helper.js +5 -0
  187. package/dist/utils/three/stats.d.ts +12 -0
  188. package/dist/utils/three/stats.js +5 -0
  189. package/dist/utils/three/transform-controls.d.ts +73 -0
  190. package/dist/utils/three/transform-controls.js +5 -0
  191. package/dist/utils/three/traverse.d.ts +13 -0
  192. package/dist/utils/three/traverse.js +5 -0
  193. package/dist/utils/type.d.ts +4 -0
  194. package/dist/utils/type.js +5 -0
  195. package/dist/utils/uuid.d.ts +1 -0
  196. package/dist/utils/uuid.js +5 -0
  197. package/package.json +114 -0
  198. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{Subject as t}from"rxjs";import*as i from"three";import{BoxGeometry as r,Color as a,Euler as s,Fog as n,FogExp2 as o,Group as l,Material as c,Mesh as d,MeshLambertMaterial as h,MeshPhongMaterial as u,MeshStandardMaterial as p,Object3D as m,PointLight as f,Quaternion as v,SphereGeometry as y,Texture as g,Vector2 as w,Vector3 as A,Vector4 as S}from"three";import b,{SpriteRenderer as M}from"three-nebula";import{bool as x,BooleanNode as I,float as D,FloatNode as P,NodeShaderMaterial as E,rgb as j,RgbNode as N,Texture2dLookupNode as O,textureSampler2d as F,vec2 as V,Vec2Node as B,vec3 as z,Vec3Node as C,vec4 as T}from"three-shader-graph";import _ from"../gameplay/actors/builtin";import{extractShaderParameters as $}from"../shader/parameter";import{groupBy as k,ArrayMap as L}from"../utils/collections";import{filterChildrenShallow as R,filterSceneShallow as U}from"../utils/three/traverse";import{AssetMeshInstance as W}from"./asset-resource-loader";import{BoxCollisionShape as G,PhysicalShapeMesh as H}from"./collision/collision-shape";import{isCollisionMesh as J}from"./collision/collision-shape-import";import{initLandscape as X}from"./landscape/landscape";import{LandscapeManager as Y}from"./landscape/landscape-manager";import{SectionGrid as q,smoothNormalsCrossMeshes as Z}from"./landscape/utils";import{createGrassMaterial as K}from"./materials/grass";import{createGrassFoliageMaterial as Q}from"./materials/grass-foliage";import{getMaterialAttribute as ee}from"./materials/utils/material-painting";import{createWaterMaterial as te}from"./materials/water";import{SerializedParamType as ie}from"./model";import{Matrix4 as re}from"three";import{BaseActor as ae}from"../gameplay/actors/actor";import{Sampler2DNode as se}from"../shader-nodes";import{StandardShader as ne}from"../shader/builtin/standard-shader";import{LambertShader as oe}from"../shader/builtin/lambert-shader";import{ShapeLibrary as le,ShapeLibraryKeys as ce}from"./objects/shapes";import{ambientLightName as de}from"./sky";import{withInjectionContext as he}from"../gameplay";const ue={};export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,i){this.dataProvider=e,this.assetsService=t,this.assetManagerService=i}get(t,i){return new SceneMaterializer(t,this.dataProvider,this.assetsService,this.assetManagerService,i,[],[],{create:()=>null,initActor:()=>e(this,void 0,void 0,(function*(){}))})}}export class SceneMaterializer{constructor(i,r,a,s,n,o,l,c){this.scene=i,this.dataProvider=r,this.assetsService=a,this.assetManagerService=s,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.originalFog=null,r.onUpdate((e=>this.update(e))),r.onRemove((e=>this.remove(e))),this.updateSubscription=a.onUpdate.subscribe((t=>e(this,void 0,void 0,(function*(){"material"==t.type?((yield this.assetsService.getAssets()).filter((e=>{var i;return(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))})).forEach((e=>{const t=this.findByAssetId(e.id);e.materialAssignments.forEach((e=>{t.forEach((t=>{const i=t.userData.src.materialAssignments;null!=i&&i.some((t=>t.color===e.color))||this.applyMaterial(t,e)}))}))})),U(this.scene,(e=>{var i;return null!=e.userData.src&&(null!==(i=e.userData.src.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))}),(e=>null!=e.userData.src)).forEach((t=>e(this,void 0,void 0,(function*(){this.deleteSceneObject(t.userData.src),this.materialize(t.userData.src)}))))):"mesh"==t.type?this.findByAssetId(t.id).forEach((e=>{Me(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})):"prefab"===t.type&&this.findByAssetId(t.id).forEach((e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}))}))))}get actorInstances(){return Array.from(this.materializedActors.values())}prefetchAssets(){return e(this,void 0,void 0,(function*(){const e=Array.from(new Set(this.dataProvider.getObjects().filter((e=>null!=e.assetId&&"asset_mesh"==e.type)).filter((e=>e.assetId))));yield Promise.all(e.map((e=>this.assetsService.getAsset(e.assetId).then((e=>e&&this.assetManagerService.getMesh(e))))))}))}init(){return e(this,void 0,void 0,(function*(){me.clear(),yield this.prefetchAssets(),yield Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),yield this.initActorsPostInit()}))}initActorsPostInit(t=this.actorInstances){const i=t.map((t=>e(this,void 0,void 0,(function*(){var e,i,r,a;const s=t.container.userData.src,n=yield this.assetsService.getAsset(s.assetId),o=Object.assign(Object.assign({},null!==(i=null===(e=null==n?void 0:n.actor)||void 0===e?void 0:e.params)&&void 0!==i?i:{}),null!==(r=s.actor.params)&&void 0!==r?r:{});for(const e of null!==(a=s.actor.innerParams)&&void 0!==a?a:[])yield this.applyActorComponentParams(t,e.path.slice(),e.params);const l=yield ye(o,t.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);Object.assign(t,l);try{return yield this.actorProvider.initActor(t)}catch(e){console.error(`Failed to initiate actor (name="${s.name}", id=${s.id})`,e)}}))));return Promise.all(i)}applyActorComponentParams(t,i,r){return e(this,void 0,void 0,(function*(){const e=i.length,a=i.shift();if(0==e){const e=yield ye(r,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[i,r]of Object.entries(e))null!=r&&(t[i]=r)}else null!=t[a]&&(yield this.applyActorComponentParams(t[a],i,r))}))}canAssetBeInstanced(t){return e(this,void 0,void 0,(function*(){if(!this._canBeInstancedCache.has(t.assetId)){const e=yield this.createFromAsset(t);if(null==e)return!1;const i=[];e.traverse((e=>{!J(e)&&e.isMesh&&i.push(e)}));const r=1==i.length&&0==i[0].children.length,a=!0;this._canBeInstancedCache.set(t.assetId,r&&a)}return this._canBeInstancedCache.get(t.assetId)}))}initWithInstancing(){return e(this,void 0,void 0,(function*(){const t=new L;for(const i of this.dataProvider.getObjects())yield Se(i,((i,r,a)=>e(this,void 0,void 0,(function*(){var e,s;const n="asset_mesh"==i.type&&(yield this.canAssetBeInstanced(i))?i.assetId+JSON.stringify(null!==(e=i.materialAssignments)&&void 0!==e?e:[]):"other";"other"!==n&&r&&(null===(s=r.children)||void 0===s?void 0:s.length)>0&&r.children.splice(r.children.findIndex((e=>e.id===i.id)),1),t.push(n,Object.assign(Object.assign({},i),{parentTransform:a}))}))));for(const[e,i]of t.entries())if("other"!==e&&i.length>1){const e=yield this.createFromAsset(i[0]);if(null==e)continue;const t=yield this.createInstancedMesh(i,e),r=new W;r.add(t),r.userData.src=i[0],e instanceof W&&(r.collisionShapes=e.collisionShapes),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}else yield Promise.all(i.map((e=>this.materialize(e))));yield this.initActorsPostInit()}))}createInstancedMesh(t,r){var a,n;return e(this,void 0,void 0,(function*(){const e=r.children.filter((e=>!J(e)))[0],o=yield this.assetsService.getAsset(t[0].assetId);yield this.applyMaterials(r,Me(t[0].materialAssignments,o.materialAssignments)),e.updateMatrix();const l=e.geometry.clone().applyMatrix4(e.matrix),c=new i.InstancedMesh(l,e.material.clone(),t.length);c.material.side=i.FrontSide;for(let e=0;e<t.length;e++){const r=(new i.Matrix4).compose((new A).fromArray(t[e].position),(new v).setFromEuler((new s).fromArray(t[e].rotation)),(new A).fromArray(t[e].scale)),a=(new re).copy(t[e].parentTransform).multiply(r);c.setMatrixAt(e,a)}return c.castShadow=null===(a=o.castShadow)||void 0===a||a,c.receiveShadow=null===(n=o.receiveShadow)||void 0===n||n,c}))}remove(e){if("global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("actor"==e.type){const t=this.materializedActors.get(e.id);null!=t&&t.disposed.next(!0)}const t=this.sceneObjectMap.get(e.id);null==t||t.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter((t=>{var i;return(null===(i=t.object.userData.src)||void 0===i?void 0:i.id)===e.id})).forEach((e=>this.components.splice(this.components.indexOf(e,1)))),this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))})),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex((t=>t.source.id===e.id));if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return U(this.scene,(t=>{var i;return(null===(i=t.userData.src)||void 0===i?void 0:i.assetId)==e}),(e=>null!=e.userData.src))}applyMaterials(e,t){return Promise.all(t.filter((e=>"null"!==e.materialId)).map((t=>this.applyMaterial(e,t))))}applyMaterial(t,i){const r=[];return t.traverse((t=>e(this,void 0,void 0,(function*(){(t instanceof d||t.isMesh)&&t.material.hasOwnProperty("color")&&r.push(t)})))),Promise.all(r.map((t=>e(this,void 0,void 0,(function*(){var e;const r="#"+t.material.color.getHexString();if(r===i.color||t.userData.originalColor===i.color){const a=yield this.assetsService.getAsset(i.materialId),s=t.material;a&&(t.material=yield materialFromAsset(a,this.renderingView,this.assetsService,this.assetManagerService,this.shaders),t.userData.originalColor=null!==(e=t.userData.originalColor)&&void 0!==e?e:r,this.inEditor&&this._originalMaterials.set(t.id,s))}})))))}unapplyMaterials(t){t.traverse((t=>e(this,void 0,void 0,(function*(){t instanceof d&&this._originalMaterials.has(t.id)&&(t.material=this._originalMaterials.get(t.id))}))))}updateActors(t){this.actorTypes=t;const i=new Set(Object.values(_));U(this.scene,(e=>{var t,r;return(null===(t=e.userData.src)||void 0===t?void 0:t.id)&&"actor"===e.userData.src.type&&this.materializedActors.has(null===(r=e.userData.src)||void 0===r?void 0:r.id)&&!i.has(e.userData.src.actor.type)})).forEach((t=>e(this,void 0,void 0,(function*(){this.remove(t.userData.src),console.time(t.userData.src.id),yield this.materializeAndInitActor(t.userData.src),console.timeEnd(t.userData.src.id)}))))}updateShaders(e){this.shaders=e;for(const[e,t]of me.entries())t.userData.customShaderName&&me.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),U(this.scene,(e=>!0)).forEach((e=>{e.traverse((e=>{var t;if(e instanceof d){if(null!=e.material.userData.customShaderName){const i=null===(t=function(e,t){if(t(e))return e;let i;return e.traverseAncestors((e=>{null==i&&t(e)&&(i=e)})),i}(e,(e=>{var t;return null!=(null===(t=e.userData.src)||void 0===t?void 0:t.id)})))||void 0===t?void 0:t.userData.src;null!=i&&this.update(i)}}}))}))}update(t){var i;return e(this,void 0,void 0,(function*(){const e=this.sceneObjectMap.get(t.id);if(e){const s=this.findParent(t);null!=s&&s.uuid!=e.uuid?s.attach(e):console.error("Parent is wrong"),this.unapplyMaterials(e);if(this.inEditor&&t.hidden&&!1?e.traverse((e=>{e instanceof d&&(e.material.wireframe=!0)})):(e.traverse((e=>{e instanceof d&&(e.material.wireframe=!1)})),(null!==(i=t.materialAssignments)&&void 0!==i?i:[]).forEach((t=>this.applyMaterial(e,t)))),e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation),this.applyVertexMaterials(t,e),"light"==t.type)if("point"==t.light.type){const i=e;i.color=new a(t.light.point.color),i.intensity=t.light.point.intensity,i.decay=t.light.point.decay,i.castShadow=t.light.point.castShadow,i.distance=Math.max(t.light.point.distance,0)}else"directional"===t.light.type?this.applyDirectionalLight(t.light.directional):"ambient"===t.light.type&&this.applyDirectionalAmbientLight(e,t.light.ambient);else if("landscape"===t.shape)this.applyHeightMaps(e,t.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter((e=>e.source.id===t.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>!0))));else if("global_fog"===t.type){const e=(this.scene.fog instanceof o?"density":"linear")!==t.fog.type;this.scene.fog=we(t.fog),e&&(r=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof E&&(r.fog instanceof n?(t.uniforms.fogFar.value=r.fog.far,t.uniforms.fogNear.value=r.fog.near):r.fog instanceof o&&(t.uniforms.density={value:r.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}})),this.fixFogColor()}else if("actor"===t.type){if(this.materializedActors.has(t.id)){const e=this.editorActorParamSnapshot.get(t.id);null!=e&&e===JSON.stringify(t.actor)||(console.log("Rematerializing actor because parameters changed"),this.remove(t),yield this.materializeAndInitActor(t))}}else if("shape_mesh"===t.type){const i=yield this.createMeshByShape(t.shape,e.material,t.shapeParams);e instanceof H&&(e.geometry=i.geometry,e.collisionShape=i.collisionShape)}"asset_mesh"!==t.type&&"shape_mesh"!==t.type||pe(e,t.castShadow,t.receiveShadow),t.name&&t.name.length>0&&(e.name=t.name),this.updated$.next({object:e,source:t})}else{const e=yield this.materializeAndInitActor(t);this.updated$.next({object:e,source:t})}var r}))}materializeAndInitActor(t){return e(this,void 0,void 0,(function*(){const e=this.findParent(t),i=yield this.materialize(t,e);if("actor"===t.type){const e=this.materializedActors.get(t.id);null!=e?yield this.initActorsPostInit([e]):console.error(`Something went wrong when creating actor ${t.id}`)}return i}))}findParent(e){const t=this.dataProvider.getObjects().flatMap((t=>t.id===e.id?null:R(t,(t=>{var i;return null===(i=t.children)||void 0===i?void 0:i.some((t=>t.id===e.id))}),(()=>!0))))[0];return null==t?this.scene:null!=t?U(this.scene,(e=>{var i,r;return(null===(r=null===(i=e.userData)||void 0===i?void 0:i.src)||void 0===r?void 0:r.id)===t.id}),(e=>{var t;return null!=(null===(t=e.userData)||void 0===t?void 0:t.src)}))[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new a(this.scene.fog.color).convertSRGBToLinear())}findMeshWithGeometry(e){let t;return e.traverse((e=>{e instanceof d&&e.geometry&&(t=e)})),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;const i=k(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){const t=ee(e,!1);if(null!=t){for(let e=0;e<t.array.length;e++)t.setX(e,0);t.needsUpdate=!0}}}));const r=new Set;for(const[e,a]of i.entries()){const i=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let s=!1;if(null==i)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const n=ee(i,!0);for(let e=0;e<n.array.length;e++)n.setX(e,0);for(const e of a)n.setX(e.i,e.w[0]),n.setY(e.i,e.w[1]),n.setZ(e.i,e.w[2]),s=!0;s&&r.add(e)}this.inEditor&&this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>r.has(e.name)))))}materialize(t,i,a=!1){var s,n,o,c;return e(this,void 0,void 0,(function*(){let e;switch(t.type){case"asset_mesh":e=yield this.createFromAsset(t);break;case"shape_mesh":e=yield this.createFromShape(t);break;case"light":e=yield this.createLight(t);break;case"particles":e=yield this.createParticleSystem(t),t.collisionDetection=!1;break;case"global_fog":this.scene.fog=we(t.fog),this.fixFogColor(),e=new l;break;case"actor":e=yield this.createFromActor(t);break;case"group":e=new l;break;case"prefab":e=yield this.createFromPrefabAsset(t);break;default:throw console.log(t),new Error("unknown type "+t.type)}if(null!=e){if(t.name&&t.name.length>0&&(e.name=t.name),e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation),a||(e.userData.src=t),!this.inEditor){const i=null!==(s=t.components)&&void 0!==s?s:[],r=null!=t.assetId&&null!==(o=null===(n=yield this.assetsService.getAsset(t.assetId))||void 0===n?void 0:n.components)&&void 0!==o?o:[];i.push(...r),i.length>0?e.userData.componentRefs=yield Promise.all(i.map(((i,r)=>this.createComponent(e,t,i,r)))):"asset_mesh"==t.type&&function(e){e.traverse((e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1}));const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}(e)}if(this.inEditor){let t=null;e instanceof H&&(t=function(e){if(e instanceof G)return new d(new r(...e.offset.toArray()),Ae);return null}(e.collisionShape)),null!=t&&(t.layers.disable(0),t.layers.enable(18),t.scale.multiplyScalar(1.1),e.add(t))}return this.objectMap.set(e.uuid,t),this.sceneObjectMap.set(t.id,e),null==i?this.scene.add(e):null==i||i.add(e),null===(c=t.children)||void 0===c||c.forEach((t=>{this.materialize(t,e,a)})),e}}))}createComponent(t,i,r,a){return e(this,void 0,void 0,(function*(){const e=new ue[r.path+"/"+r.className],s=i.id+a;e.id=s,e.object=t;for(const t of r.params)null!=t.value&&(e[t.name]=t.value);return this.components.push(e),s}))}createFromActor(t){var i,r,a;return e(this,void 0,void 0,(function*(){const e=null!==(r=null===(i=this.actorTypes.find((e=>{var i;return e.name===(null===(i=t.actor)||void 0===i?void 0:i.type)})))||void 0===i?void 0:i.type)&&void 0!==r?r:_[null===(a=t.actor)||void 0===a?void 0:a.type];if(null==e)return null;this.inEditor&&this.editorActorParamSnapshot.set(t.id,JSON.stringify(t.actor));const n=yield this.actorProvider.create(e,(new A).fromArray(t.position),(new s).fromArray(t.rotation),!0);return this.materializedActors.set(t.id,n),null==n?void 0:n.container}))}cleanup(){this.materializedActors.clear()}createFromShape(t){var i,r,s;return e(this,void 0,void 0,(function*(){const e=this.inEditor&&t.hidden;let n;if("landscape"==t.shape)n=this.createLandscape(t);else{const s=new p({color:new a("#aaaaaa"),visible:this.inEditor||!t.hidden,wireframe:e}),o=yield this.createMeshByShape(t.shape,s,t.shapeParams);o.castShadow=null===(i=t.castShadow)||void 0===i||i,o.receiveShadow=null!==(r=t.castShadow)&&void 0!==r&&r,t.collisionDetection||(o.collisionShape=null),n=o}return e||((null!==(s=t.materialAssignments)&&void 0!==s?s:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(n,e))),this.applyVertexMaterials(t,n)),n}))}createLandscape(e){var t;if(null==(null===(t=e.landscape)||void 0===t?void 0:t.options))return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new l;const i=X(e.landscape.options);this.applyHeightMaps(i,e.landscape.heightMaps,!0);const r=new Y(e,this.renderingView,i,this.assetManagerService,this.assetsService,this.shaders,(t=>{var i;(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(t,e)))}));return this.landscapeManagers.push(r),r.refreshGeometry(),i}applyHeightMaps(e,t,i=!1){const r=new q(e.sections);for(const e of null!=t?t:[]){const t=r.find(e.x,e.y);if(!t)return;const i=t.geometry.getAttribute("position");for(const t of e.points)i.setY(t.i,t.y);i.needsUpdate=!0}const a=e.sections;a.forEach((e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()})),this.inEditor&&!i||setTimeout((()=>Z(a)),50)}createMeshByShape(t,i,r={}){return e(this,void 0,void 0,(function*(){if("landscape"!==t&&ce.includes(t)){const a=yield function(t){return e(this,void 0,void 0,(function*(){const e={};for(const[i,r]of Object.entries(t)){const t=yield ge(r,null,null,null);null!=t&&(e[i]=t)}return e}))}(null!=r?r:{});return"cylinder"==t&&a.openEnded,new H(le[t].geometry(a),i,le[t].collision(a))}throw new Error(`Unsupported shape '${t}'`)}))}createFromAsset(t){var i,r,a,s;return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);let{scene:n}=yield this.assetManagerService.getMesh(e);Me(t.materialAssignments,e.materialAssignments).forEach((e=>this.applyMaterial(n,e)));const o=null===(r=null!==(i=t.receiveShadow)&&void 0!==i?i:!!e.receiveShadow)||void 0===r||r,l=null!==(s=null!==(a=t.castShadow)&&void 0!==a?a:!!e.castShadow)&&void 0!==s&&s;return n.receiveShadow=o,pe(n,l,o),t.collisionDetection||(n.collisionShapes=[]),this.applyVertexMaterials(t,n),n.traverse((e=>{e instanceof d&&"computeBoundsTree"in e.geometry&&e.geometry.computeBoundsTree()})),n}))}createFromPrefabAsset(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);const i=new l;return e.prefab.objects.filter((e=>"global_fog"!==e.type)).forEach((e=>this.materialize(e,i,!0))),i}))}createParticleSystem(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId),r=new m;return yield b.fromJSONAsync(e.particleSystem,i).then((e=>{const t=new M(r,i);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),r}))}createLight(t){var i;return e(this,void 0,void 0,(function*(){if("point"===t.light.type){const e=new f(t.light.point.color,t.light.point.intensity,t.light.point.distance,t.light.point.decay);if(e.castShadow=null===(i=t.light.point.castShadow)||void 0===i||i,this.inEditor){const t=new y(1,10,10),i=new p({color:new a("#aaaaaa")}),r=new d(t,i);e.add(r)}return e}return"directional"===t.light.type?(this.applyDirectionalLight(t.light.directional),new l):"ambient"===t.light.type?(this.applyDirectionalAmbientLight(null,t.light.ambient),new l):void 0}))}applyDirectionalAmbientLight(e,t){const i=this.scene.children.find((e=>e.name===de));null!=i?(i.intensity=t.intensity,i.color.set(t.color),i.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe()}}function pe(e,t,i){e.castShadow=t,e.receiveShadow=i,e.traverse((e=>{e.castShadow=t,e.receiveShadow=i}))}const me=new Map,fe=new h({color:16711935}),ve=new Map;export function materialFromAsset(t,r,s,n,o,l=!0){var c,d,h,p,m,f,v,y,g;return e(this,void 0,void 0,(function*(){const e=JSON.stringify(t.material);if(l&&me.has(e))return me.get(e);const w={opacity:t.material.params.opacity,map:null,emissive:null!==(c=t.material.params.emissive)&&void 0!==c?c:null,metalness:null!==(d=t.material.params.metalness)&&void 0!==d?d:0,flatShading:null!==(h=t.material.params.flatShading)&&void 0!==h&&h,color:new a(t.material.params.color).convertSRGBToLinear(),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},A={};if(null!=t.material.params.map){const e=t.material.params.map,i=yield s.getAsset(e);null!=i&&(w.map=yield n.getTexture(i))}let S;switch(t.material.type){case"phong":S=new u(Object.assign(Object.assign({},w),A));break;case"water":S=te(w,r);break;case"grassFoliage":S=Q({color:w.color,map:w.map},r);break;case"grass":S=K(Object.assign(Object.assign({},w),{colorTwo:new a(t.material.params.colorTwo),colorThree:new a(t.material.params.colorThree)}),r);break;case"standard":case"lambert":case"shader":const e=null!==(p={standard:ne,lambert:oe}[t.material.type])&&void 0!==p?p:null===(m=o.find((e=>e.name==t.material.shader)))||void 0===m?void 0:m.type;if(e){const i=new e,a=yield ye(null!==(v=null===(f=t.material)||void 0===f?void 0:f.shaderParams)&&void 0!==v?v:{},e,s,n,null,r,o);Object.assign(i,a);try{S=i.build()}catch(e){console.log("Shader runtime error: "+e),ve.has(t.material.shader)||ve.set(t.material.shader,fe.clone()),S=ve.get(t.material.shader)}S.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),S=fe;break;default:throw new Error("Unsupported material type"+t.material.type)}return null==r||r.csm.setupMaterial(S),l&&me.set(e,S),S.side=null!==(g=null!==(y=t.material.side)&&void 0!==y?y:S.side)&&void 0!==g?g:i.FrontSide,S}))}function ye(t,i,r,a,s,n,o){return e(this,void 0,void 0,(function*(){const e={};for(const[i,l]of Object.entries(t)){const t=yield ge(l,r,a,s,n,o);null!=t&&(e[i]=t)}return e}))}function ge(t,i,r,n,o,l){return e(this,void 0,void 0,(function*(){if(null==t||null==t.value||""==t.value)return null;const e=t.value;switch(t.type){case ie.Number:case ie.FloatNode:let c="string"==typeof e?parseFloat(e):e;return t.type===ie.FloatNode?D(c):c;case ie.Texture:return yield r.getTexture(yield i.getAsset(e));case ie.Sampler2DNode:return F(yield r.getTexture(yield i.getAsset(e)));case ie.Boolean:return e;case ie.BooleanNode:return x(e);case ie.Vector2:case ie.Vec2Node:if("object"==typeof e){const i=e instanceof Array?(new w).fromArray(e):new w(i.x,i.y);return t.type===ie.Vec2Node?V(i):i}return null;case ie.Vector3:case ie.Vec3Node:if("object"==typeof e){const i=e instanceof Array?(new A).fromArray(e):new A(i.x,i.y,i.z);return t.type===ie.Vec3Node?z(i):i}return null;case ie.Color:case ie.RgbNode:const d=new a(e).convertSRGBToLinear();return t.type===ie.RgbNode?j(d):d;case ie.String:return e;case ie.BaseActor:const h=e;return null==n&&console.warn("Class parameters can not be prepared as actors are not passed in"),null==n?void 0:n.get(h);case ie.Euler:const u=e;return(new s).fromArray(u);case ie.Mesh:return(yield r.getMesh(yield i.getAsset(e))).scene;case ie.Material:return yield materialFromAsset(yield i.getAsset(e),o,i,r,l);case ie.AudioBuffer:return yield r.getAudio(yield i.getAsset(e))}return null}))}function we(e){var t,i;return"linear"===e.type?new n(new a(e.color),null!==(t=e.near)&&void 0!==t?t:100,null!==(i=e.far)&&void 0!==i?i:1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const Ae=new p({color:4229780});function Se(t,r,a,n){var o;return e(this,void 0,void 0,(function*(){null==n&&(n=(new re).identity()),yield r(t,a,n);const e=n.clone().multiply(function(e,t){return t.compose((new A).fromArray(e.position),(new v).setFromEuler((new s).fromArray(e.rotation)),(new A).fromArray(e.scale))}(t,new i.Matrix4));return Promise.all((null!==(o=t.children)&&void 0!==o?o:[]).map((i=>Se(i,r,t,e))))}))}function be(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ie.Number:t instanceof P||"function"==typeof e.prototype.isFloat?ie.FloatNode:t instanceof g||e===g||e.isTexture?ie.Texture:t instanceof se||e===O?ie.Sampler2DNode:t instanceof Boolean||e===Boolean?ie.Boolean:t instanceof I?ie.BooleanNode:t instanceof a||e==a?ie.Color:t instanceof N||"function"==typeof e.prototype.isRgb?ie.RgbNode:t instanceof w||e==w?ie.Vector2:t instanceof B||"function"==typeof e.prototype.isVec2?ie.Vec2Node:t instanceof A||e==A?ie.Vector3:t instanceof C||"function"==typeof e.prototype.isVec3?ie.Vec3Node:t instanceof String||e===String?ie.String:t instanceof ae||e==ae||e.prototype instanceof ae||e.prototype==ae?ie.BaseActor:t instanceof s||e==s?ie.Euler:t instanceof d||e==d?ie.Mesh:t instanceof c||e==c?ie.Material:t instanceof AudioBuffer||e==AudioBuffer?ie.AudioBuffer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,i={}){return Object.fromEntries(e.map((e=>{var r,a,s;return[e.name,{type:be(e.type),value:null!==(s=null!==(a=null===(r=t[e.name])||void 0===r?void 0:r.value)&&void 0!==a?a:i[e.name])&&void 0!==s?s:Ie.get(be(e.type))}]})))}export function prepareCustomParamsFromType(e,t,i=null){const r=$(e);if(0===r.length)return{};let a;null!=i?he(i,(()=>{a=i.get(e)})):a=new e;const s={};for(const e of r){const t=a[e.name];if(null!=t){const i=serializeCustomParameter(e.type,t);null!=i&&(s[e.name]=i)}}return prepareCustomParams(r,t,s)}export function serializeCustomParameter(e,t){function i(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case w:return t instanceof w?t.toArray():void i();case A:return t instanceof A?t.toArray():void i();case S:return t instanceof S?t.toArray():void i();case a:return t instanceof a?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new a(t).getHexString():void i();case String:return t;case s:return t instanceof s?t.toArray():void i()}}function Me(e,t){return function(e,t,i){const r=[],a=new Set;for(const s of[...null!=e?e:[],...null!=t?t:[]]){const e=i(s);a.has(e)||(a.add(e),r.push(s))}return r}((null!=e?e:[]).filter((e=>xe(e.materialId))),(null!=t?t:[]).filter((e=>xe(e.materialId))),(e=>e.color))}function xe(e){return"null"!=e&&null!=e}const Ie=new Map([[ie.RgbNode,"#000000"],[ie.Color,"#000000"],[ie.Vector4,[0,0,0,0]],[ie.Vec4Node,[0,0,0,0]],[ie.Vector3,[0,0,0]],[ie.Vec3Node,[0,0,0]],[ie.Vector2,[0,0]],[ie.Vec2Node,[0,0]],[ie.Euler,[0,0,0,"XYZ"]]]);
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,8 @@
1
+ import { NodeShaderMaterial } from '../../shader-nodes';
2
+ import { Color, Texture } from 'three';
3
+ import { RenderingView } from '../../rendering';
4
+ export interface GrassFoliageMaterialParameters {
5
+ map: Texture;
6
+ color: Color;
7
+ }
8
+ export declare function createGrassFoliageMaterial(params: GrassFoliageMaterialParameters, renderingView: RenderingView): NodeShaderMaterial;
@@ -0,0 +1,5 @@
1
+ import{attributes as m,float as o,lambertMaterial as l,NodeShaderMaterial as r,rgb as e,rgba as t,select as a,sin as i,smoothstep as p,transformed as n,translateAxis as u,uniformFloat as s,uniformSampler2d as f,varyingFloat as y,varyingVec2 as c}from"../../shader-nodes";import{Vector3 as v}from"three";import{CSMUtil as d}from"../../csm";export function createGrassFoliageMaterial(g,w){const h=n.mvPosition.z().multiply(o(-1)),x=y(p(o(100),o(60),h)),z=m.uv.y(),B=e(11977268),C=o(.2),S=l(e(g.color)).rgb().multiplyScalar(o(.9)).add(B.multiplyScalar(y(z).multiply(C))),b=c(m.uv),F=f("map").sample(b,o(0)),G=t(S,F.x().multiply(x)),L=s("time"),M=o(.5).multiply(a(z.gt(o(0)),z.multiply(z),o(0))).multiply(i(L.multiply(o(.001)))),P=u(new v(1,0,0).normalize(),M),j=new r({color:G,transform:P,uniforms:{map:{value:g.map},time:{value:0}},transparent:!0});return j.onBeforeCompile=m=>{d.onBeforeCompile(j,m)},j.uniforms.map.value=g.map,w.onLoop((()=>{j.uniforms.time.value=performance.now()})),j}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,4 @@
1
+ import * as THREE from 'three';
2
+ import { RenderingView } from '../../rendering';
3
+ export declare function createGrassMaterial(params: any, renderingView: RenderingView): THREE.MeshStandardMaterial;
4
+ export declare function createGrassMaterialOld(params: any, renderingView: RenderingView): THREE.ShaderMaterial;
@@ -0,0 +1,5 @@
1
+ import*as e from"three";import{CSMUtil as r}from"../../csm";import{noiseChunk as n}from"./utils/noise.glsl";export function createGrassMaterial(a,i){var t=new e.MeshStandardMaterial({color:a.color,roughness:.8,metalness:0});return t.onBeforeCompile=(e,i)=>{r.onBeforeCompile(t,e);const l="varying vec3 vViewPosition;",v=`${l}\n varying vec3 vOriginalNormal;\n varying vec2 vNoiseCoord;\n attribute vec3 material;\n varying vec3 vMaterial;\n `,c="#include <fog_vertex>",s=`${c}\n vOriginalNormal = objectNormal;\n vMaterial = material;\n vNoiseCoord = position.xz / 5.0;\n `;e.vertexShader=e.vertexShader.replace(l,v),e.vertexShader=e.vertexShader.replace(c,s);const d="uniform vec3 diffuse;",m=`${d}\n varying vec3 vOriginalNormal;\n varying vec3 vMaterial;\n varying vec2 vNoiseCoord;\n\n ${n}\n `,g=o(a.color),f=o(a.colorTwo),h=`\n float thresholdStatic = 0.5;\n float thresholdWithNoise = thresholdStatic + snoise(vNoiseCoord) * 0.1;\n vec3 painted = (\n vMaterial.y > thresholdWithNoise \n ? ${o(a.colorThree)}\n : (vMaterial.x > thresholdWithNoise\n ? ${f}\n : ${g}\n )\n );\n\n float colorAngle = pow(vOriginalNormal.y, 3.0);\n vec4 diffuseColor = vec4(mix(painted, ${f}, smoothstep(colorAngle-0.0003, colorAngle, 0.9)), opacity);\n `.trim();e.fragmentShader=e.fragmentShader.replace(d,m),e.fragmentShader=e.fragmentShader.replace("vec4 diffuseColor = vec4( diffuse, opacity );",h)},t.userData.instancing=!1,t.userData.grass=!0,t}function o(e){return`vec3(${e.r.toFixed(5)}, ${e.g.toFixed(5)}, ${e.b.toFixed(5)})`}export function createGrassMaterialOld(r,n){return new e.ShaderMaterial({uniforms:{colorOne:{value:r.color}},vertexShader:"\n uniform float time;\n varying vec3 vNormal;\n void main() {\n vNormal = normal;\n #include <begin_vertex>\n #include <project_vertex>\n #include <fog_vertex>\n }",fragmentShader:"\n varying vec3 vNormal;\n uniform vec3 colorOne;\n void main() {\n gl_FragColor = vec4(mix(colorOne, vec3(.86,.8,.7), step(pow(vNormal.y, 3.0), 0.9)), 1.0);\t\n\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n }"})}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,2 @@
1
+ import { Mesh, BufferAttribute } from "three";
2
+ export declare function getMaterialAttribute(mesh: Mesh, recreate?: boolean): BufferAttribute;
@@ -0,0 +1,5 @@
1
+ import{BufferAttribute as t}from"three";export function getMaterialAttribute(e,r=!1){if(!e.geometry.hasAttribute("material")||r){const r=new Float32Array(e.geometry.getAttribute("position").array.length);e.geometry.setAttribute("material",new t(r,3))}return e.geometry.getAttribute("material")}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1 @@
1
+ export declare const noiseChunk = "\n// Some useful functions\nvec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }\n\n//\n// Description : GLSL 2D simplex noise function\n// Author : Ian McEwan, Ashima Arts\n// Maintainer : ijm\n// Lastmod : 20110822 (ijm)\n// License :\n// Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n//\nfloat snoise(vec2 v) {\n\n // Precompute values for skewed triangular grid\n const vec4 C = vec4(0.211324865405187,\n // (3.0-sqrt(3.0))/6.0\n 0.366025403784439,\n // 0.5*(sqrt(3.0)-1.0)\n -0.577350269189626,\n // -1.0 + 2.0 * C.x\n 0.024390243902439);\n // 1.0 / 41.0\n\n // First corner (x0)\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n\n // Other two corners (x1, x2)\n vec2 i1 = vec2(0.0);\n i1 = (x0.x > x0.y)? vec2(1.0, 0.0):vec2(0.0, 1.0);\n vec2 x1 = x0.xy + C.xx - i1;\n vec2 x2 = x0.xy + C.zz;\n\n // Do some permutations to avoid\n // truncation effects in permutation\n i = mod289(i);\n vec3 p = permute(\n permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0 ));\n\n vec3 m = max(0.5 - vec3(\n dot(x0,x0),\n dot(x1,x1),\n dot(x2,x2)\n ), 0.0);\n\n m = m*m ;\n m = m*m ;\n\n // Gradients:\n // 41 pts uniformly over a line, mapped onto a diamond\n // The ring size 17*17 = 289 is close to a multiple\n // of 41 (41*7 = 287)\n\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n\n // Normalise gradients implicitly by scaling m\n // Approximation of: m *= inversesqrt(a0*a0 + h*h);\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0+h*h);\n\n // Compute final noise value at P\n vec3 g = vec3(0.0);\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * vec2(x1.x,x2.x) + h.yz * vec2(x1.y,x2.y);\n return 130.0 * dot(m, g);\n}\n";
@@ -0,0 +1,5 @@
1
+ export const noiseChunk="\n// Some useful functions\nvec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }\n\n//\n// Description : GLSL 2D simplex noise function\n// Author : Ian McEwan, Ashima Arts\n// Maintainer : ijm\n// Lastmod : 20110822 (ijm)\n// License :\n// Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n//\nfloat snoise(vec2 v) {\n\n // Precompute values for skewed triangular grid\n const vec4 C = vec4(0.211324865405187,\n // (3.0-sqrt(3.0))/6.0\n 0.366025403784439,\n // 0.5*(sqrt(3.0)-1.0)\n -0.577350269189626,\n // -1.0 + 2.0 * C.x\n 0.024390243902439);\n // 1.0 / 41.0\n\n // First corner (x0)\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n\n // Other two corners (x1, x2)\n vec2 i1 = vec2(0.0);\n i1 = (x0.x > x0.y)? vec2(1.0, 0.0):vec2(0.0, 1.0);\n vec2 x1 = x0.xy + C.xx - i1;\n vec2 x2 = x0.xy + C.zz;\n\n // Do some permutations to avoid\n // truncation effects in permutation\n i = mod289(i);\n vec3 p = permute(\n permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0 ));\n\n vec3 m = max(0.5 - vec3(\n dot(x0,x0),\n dot(x1,x1),\n dot(x2,x2)\n ), 0.0);\n\n m = m*m ;\n m = m*m ;\n\n // Gradients:\n // 41 pts uniformly over a line, mapped onto a diamond\n // The ring size 17*17 = 289 is close to a multiple\n // of 41 (41*7 = 287)\n\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n\n // Normalise gradients implicitly by scaling m\n // Approximation of: m *= inversesqrt(a0*a0 + h*h);\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0+h*h);\n\n // Compute final noise value at P\n vec3 g = vec3(0.0);\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * vec2(x1.x,x2.x) + h.yz * vec2(x1.y,x2.y);\n return 130.0 * dot(m, g);\n}\n";
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,3 @@
1
+ import * as THREE from 'three';
2
+ import { RenderingView } from '../../rendering';
3
+ export declare function createWaterMaterial(params: any, renderingView: RenderingView): THREE.ShaderMaterial;
@@ -0,0 +1,5 @@
1
+ import*as e from"three";import{Color as n,DoubleSide as r,PerspectiveCamera as t}from"three";export function createWaterMaterial(a,o){var i;const l=(new e.TextureLoader).load("https://i.imgur.com/hOIsXiZ.png"),m=(new e.TextureLoader).load("assets/images/shaders/water_normal_map.jpg");m.wrapS=e.MirroredRepeatWrapping,m.wrapT=e.MirroredRepeatWrapping;const c={time:{value:0},threshold:{value:.1},tDudv:{value:null},tDepth:{value:null},cameraNear:{value:0},cameraFar:{value:0},resolution:{value:new e.Vector2},foamColor:{value:new e.Color},waterColor:{value:new e.Color},normalMap:{value:null}};l.wrapS=l.wrapT=e.RepeatWrapping;var s=!!o.renderer.extensions.get("WEBGL_depth_texture"),u=new e.ShaderMaterial({defines:{DEPTH_PACKING:!0===s?0:1,ORTHOGRAPHIC_CAMERA:0},uniforms:e.UniformsUtils.merge([e.UniformsLib.fog,c]),transparent:!0,vertexShader:"\n #include <fog_pars_vertex>\n\n varying vec2 vUv;\n\n void main() {\n\n \tvUv = uv;\n\n \t#include <begin_vertex>\n \t#include <project_vertex>\n \t#include <fog_vertex>\n\n }",fragmentShader:"\n #include <common>\n #include <packing>\n #include <fog_pars_fragment>\n\n varying vec2 vUv;\n uniform sampler2D tDepth;\n uniform sampler2D tDudv;\n uniform vec3 waterColor;\n uniform vec3 foamColor;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float time;\n uniform float threshold;\n uniform vec2 resolution;\n uniform sampler2D normalMap;\n\n float getDepth( const in vec2 screenPosition ) {\n #if DEPTH_PACKING == 1\n return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n #else\n return texture2D( tDepth, screenPosition ).x;\n #endif\n }\n\n float getViewZ( const in float depth ) {\n #if ORTHOGRAPHIC_CAMERA == 1\n return orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n #else\n return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n #endif\n }\n\n void main() {\n\n vec2 screenUV = gl_FragCoord.xy / resolution;\n\n float fragmentLinearEyeDepth = getViewZ( gl_FragCoord.z );\n float linearEyeDepth = getViewZ( getDepth( screenUV ) );\n\n float diff = saturate(fragmentLinearEyeDepth - linearEyeDepth);\n // Increase foam length by negating more\n //float diff = saturate(fragmentLinearEyeDepth - linearEyeDepth - 5.0);\n\n vec2 displacement = texture2D( tDudv, ( vUv * 2.0 ) - time * 0.01 ).rb;\n displacement = ( ( displacement * 2.0 ) - 1.0 ) * 1.0;\n diff += displacement.x*0.3; // How much of the texture to apply\n/*\n if (diff < 0.4 * ((sin(time*.5)*1.5+2.0)/5.0) && diff > 0.1 * ((sin(time*.5)*1.5+2.0)/5.0)) {\n diff = 1.0; \n // This illustrates how one can create stripes of foam so it does not start at the short\n }*/\n\n float depth = (linearEyeDepth - fragmentLinearEyeDepth) / linearEyeDepth;\n vec3 waterDiffuse = mix( foamColor, mix(vec3(0.2, 0.3, 0.7), waterColor, 1.0 - depth), step( 0.9*((sin(time*.5)*2.0+3.0)/5.0), diff ) );\n gl_FragColor.a = 0.8-clamp(depth, 0.3, 0.8)/3.0;\n\n\n // This light direction is hard coded but should be coming from the directional lights\n vec3 lightDirection = normalize(vec3(0.5, -1.0, -0.6) * -1.0);\n vec2 waterCoord = vUv;\n // Create some randomnes when picking coordinates.\n waterCoord.x *= 1.5 - cos(time) * 0.02;\n waterCoord.y *= 1.5 - sin(time+5.0) * 0.01;\n vec3 wNormal = texture2D(normalMap, waterCoord).rgb;\n float dotNL = clamp(dot(wNormal, lightDirection), 0.0, 1.0);\n vec3 irradience = dotNL * vec3(1.0);\n\n gl_FragColor.rgb = waterDiffuse * 0.2 + waterDiffuse * irradience * 1.3;\n\n //gl_FragColor.rgb = irradience;//texture2D(normalMap, vUv * 2.0).rgb;\n //gl_FragColor.a = 1.0;\n\n\n //vec4 foam = vec4(foamColor, 1.0);\n //vec4 murky = vec4(0.2, 0.3, 0.7, 0.9);\n //vec4 water = vec4(waterColor, 0.5);\n //gl_FragColor = mix(foam, mix(murky, water, 1.0 - depth), step( 0.9*((sin(time*.5)*2.0+3.0)/5.0), diff ) );\n\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n\n }",fog:!0,side:r,blendSrc:e.OneMinusSrcColorFactor,blendDst:e.SrcColorFactor});u.uniforms.cameraNear.value=o.camera instanceof t?o.camera.near:1,u.uniforms.cameraFar.value=o.camera instanceof t?o.camera.far:500,u.uniforms.foamColor.value.set(new n(16777215)),u.uniforms.waterColor.value.set(null!==(i=a.color)&&void 0!==i?i:new n(2084067)),u.uniforms.resolution.value.set(o.container.clientWidth*o.renderer.getPixelRatio(),o.container.clientHeight*o.renderer.getPixelRatio()),u.uniforms.tDudv.value=l,u.uniforms.tDepth.value=!0===s?o.depthRenderTarget.depthTexture:o.depthRenderTarget.texture,u.uniforms.normalMap.value=m;let f=0;return o.onLoop((e=>{f+=e,u.uniforms.threshold.value=.5,u.uniforms.time.value=f,u.uniforms.resolution.value.set(o.container.clientWidth*o.renderer.getPixelRatio(),o.container.clientHeight*o.renderer.getPixelRatio())})),u.userData.water=!0,u}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,96 @@
1
+ import { AttachedComponent, ActorSettings, SceneObject } from './materializer';
2
+ import { ParticleSystemConfig } from '../effects/particles/particle-system-config';
3
+ import { LandscapeInitOptions } from '../scene/landscape/landscape';
4
+ import { LibraryShapeType } from './objects/shapes';
5
+ import { Side } from 'three';
6
+ export type AssetType = 'mesh' | 'material' | 'shape' | 'particles' | 'light' | 'texture' | 'actor' | 'audio' | 'prefab';
7
+ export type ShapeType = LibraryShapeType | 'landscape';
8
+ export type LightType = 'point' | 'directional' | 'ambient';
9
+ export declare enum SerializedParamType {
10
+ FloatNode = 0,
11
+ Number = 1,
12
+ Texture = 2,
13
+ Sampler2DNode = 3,
14
+ Boolean = 4,
15
+ BooleanNode = 5,
16
+ Vector2 = 6,
17
+ Vec2Node = 7,
18
+ Vector3 = 8,
19
+ Vec3Node = 9,
20
+ Color = 10,
21
+ RgbNode = 11,
22
+ String = 12,
23
+ BaseActor = 13,
24
+ Euler = 14,
25
+ Mesh = 15,
26
+ Material = 16,
27
+ AudioBuffer = 17,
28
+ Vector4 = 18,
29
+ Vec4Node = 19
30
+ }
31
+ export type CustomParamValue = {
32
+ type: SerializedParamType;
33
+ value: unknown;
34
+ };
35
+ export interface Asset {
36
+ id: string;
37
+ name: string;
38
+ path?: string;
39
+ type: AssetType;
40
+ sourceFile?: string;
41
+ fileKey?: string;
42
+ fileFormat?: string;
43
+ collisionDetection?: boolean;
44
+ shape?: ShapeType;
45
+ landscape?: LandscapeInitOptions;
46
+ lightType?: LightType;
47
+ materialAssignments?: MaterialAssignment[];
48
+ material?: {
49
+ type: MaterialType;
50
+ side: Side;
51
+ params: Partial<MaterialParameters>;
52
+ shaderParams?: Record<string, CustomParamValue>;
53
+ shader?: string;
54
+ };
55
+ mesh?: {
56
+ rescale?: number;
57
+ };
58
+ prefab?: {
59
+ objects: SceneObject[];
60
+ };
61
+ particleSystem?: ParticleSystemConfig;
62
+ components?: AttachedComponent[];
63
+ actor?: ActorSettings;
64
+ receiveShadow?: boolean;
65
+ castShadow?: boolean;
66
+ }
67
+ export type MaterialType = 'standard' | 'phong' | 'lambert' | 'shader' | 'water' | 'grass' | 'grassFoliage';
68
+ export type MaterialParameters = {
69
+ opacity: number;
70
+ transparent: boolean;
71
+ color: string;
72
+ colorTwo?: string;
73
+ colorThree?: string;
74
+ colorFour?: string;
75
+ map?: string;
76
+ emissive: string;
77
+ metalness: number;
78
+ flatShading: boolean;
79
+ [key: string]: unknown;
80
+ };
81
+ export type AssetId = string;
82
+ export interface MaterialAssignment {
83
+ color: string;
84
+ materialId: AssetId;
85
+ }
86
+ export interface SceneData {
87
+ id: string;
88
+ name: string;
89
+ fileKey: string;
90
+ }
91
+ export interface SceneBlob {
92
+ id: string;
93
+ name: string;
94
+ data: string;
95
+ sceneId: string;
96
+ }
@@ -0,0 +1,5 @@
1
+ export var SerializedParamType;!function(e){e[e.FloatNode=0]="FloatNode",e[e.Number=1]="Number",e[e.Texture=2]="Texture",e[e.Sampler2DNode=3]="Sampler2DNode",e[e.Boolean=4]="Boolean",e[e.BooleanNode=5]="BooleanNode",e[e.Vector2=6]="Vector2",e[e.Vec2Node=7]="Vec2Node",e[e.Vector3=8]="Vector3",e[e.Vec3Node=9]="Vec3Node",e[e.Color=10]="Color",e[e.RgbNode=11]="RgbNode",e[e.String=12]="String",e[e.BaseActor=13]="BaseActor",e[e.Euler=14]="Euler",e[e.Mesh=15]="Mesh",e[e.Material=16]="Material",e[e.AudioBuffer=17]="AudioBuffer",e[e.Vector4=18]="Vector4",e[e.Vec4Node=19]="Vec4Node"}(SerializedParamType||(SerializedParamType={}));
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,2 @@
1
+ import { BufferGeometry } from "three";
2
+ export declare function rampGeometry(): BufferGeometry;
@@ -0,0 +1,5 @@
1
+ import{BufferAttribute as e,BufferGeometry as t}from"three";import*as r from"three/examples/jsm/utils/BufferGeometryUtils.js";export function rampGeometry(){const n=new t;return n.setAttribute("position",new e(o,3)),n.computeVertexNormals(),r.mergeVertices(n)}const o=function(){let e=new Float32Array([0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,1,1,1,0,1,1,0,0,0,0,1,0,1,1,0,0,0,1,0,1,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1]);for(let t=0;t<e.length;t+=3)e[t]-=.5,e[t+2]-=.5;return e}();
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,121 @@
1
+ import { BoxCollisionShape, CapsuleCollisionShape, CollisionShape, ConeCollisionShape, ConvexPolyhedronCollisionShape, CylinderCollisionShape, PlaneCollisionShape, SphereCollisionShape, TrimeshCollisionShape } from "../collision/collision-shape";
2
+ import { BoxGeometry, PlaneGeometry, BufferGeometry, CylinderGeometry, SphereGeometry, TorusGeometry, ConeGeometry, CircleGeometry, CapsuleGeometry } from "three";
3
+ import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry';
4
+ import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry';
5
+ type ShapeParameterDef<T = boolean | number | string> = {
6
+ type: T extends number ? 'number' : T extends string ? 'string' : T extends boolean ? 'boolean' : never;
7
+ default: T;
8
+ float?: boolean;
9
+ };
10
+ interface ShapeDefinition {
11
+ geometry(params?: any): BufferGeometry;
12
+ collision(params?: any): CollisionShape;
13
+ parameters?: Record<string, ShapeParameterDef>;
14
+ }
15
+ type ParamsType<T extends ShapeDefinition> = Partial<{
16
+ [K in keyof T['parameters']]: T['parameters'][K]['default'];
17
+ }>;
18
+ declare class CylinderDefinition implements ShapeDefinition {
19
+ parameters: {
20
+ radialSegments: ShapeParameterDef<number>;
21
+ heightSegments: ShapeParameterDef<number>;
22
+ openEnded: ShapeParameterDef<boolean>;
23
+ };
24
+ geometry(params?: ParamsType<this>): CylinderGeometry;
25
+ collision(params?: ParamsType<this>): CylinderCollisionShape;
26
+ }
27
+ declare class SphereDefinition implements ShapeDefinition {
28
+ parameters: {
29
+ withSegments: ShapeParameterDef<number>;
30
+ heightSegments: ShapeParameterDef<number>;
31
+ };
32
+ geometry(params?: ParamsType<this>): SphereGeometry;
33
+ collision(): SphereCollisionShape;
34
+ }
35
+ declare class TorusDefinition implements ShapeDefinition {
36
+ parameters: {
37
+ radius: ShapeParameterDef<number>;
38
+ tube: ShapeParameterDef<number>;
39
+ radialSegments: ShapeParameterDef<number>;
40
+ tubularSegments: ShapeParameterDef<number>;
41
+ };
42
+ geometry(params?: ParamsType<this>): TorusGeometry;
43
+ collision(params?: ParamsType<this>): TrimeshCollisionShape;
44
+ }
45
+ declare class PlaneDefinition implements ShapeDefinition {
46
+ parameters: {
47
+ widthSegments: ShapeParameterDef<number>;
48
+ heightSegments: ShapeParameterDef<number>;
49
+ };
50
+ geometry(params?: ParamsType<this>): PlaneGeometry;
51
+ collision(params?: ParamsType<this>): PlaneCollisionShape;
52
+ }
53
+ declare class ConeDefinition implements ShapeDefinition {
54
+ parameters: {
55
+ radialSegments: ShapeParameterDef<number>;
56
+ heightSegments: ShapeParameterDef<number>;
57
+ openEnded: ShapeParameterDef<boolean>;
58
+ };
59
+ geometry(params?: ParamsType<this>): ConeGeometry;
60
+ collision(params?: ParamsType<this>): ConeCollisionShape;
61
+ }
62
+ declare class CircleDefinition implements ShapeDefinition {
63
+ parameters: {
64
+ segments: ShapeParameterDef<number>;
65
+ };
66
+ geometry(params?: ParamsType<this>): CircleGeometry;
67
+ collision(params?: ParamsType<this>): TrimeshCollisionShape;
68
+ }
69
+ declare class CapsuleDefinition implements ShapeDefinition {
70
+ parameters: {
71
+ radius: ShapeParameterDef<number>;
72
+ length: ShapeParameterDef<number>;
73
+ capSegments: ShapeParameterDef<number>;
74
+ radialSegments: ShapeParameterDef<number>;
75
+ };
76
+ geometry(params?: ParamsType<this>): CapsuleGeometry;
77
+ collision(params?: ParamsType<this>): CapsuleCollisionShape;
78
+ }
79
+ declare class RoundedBoxDefinition implements ShapeDefinition {
80
+ parameters: {
81
+ width: ShapeParameterDef<number>;
82
+ height: ShapeParameterDef<number>;
83
+ depth: ShapeParameterDef<number>;
84
+ segments: ShapeParameterDef<number>;
85
+ radius: ShapeParameterDef<number>;
86
+ };
87
+ geometry(params?: ParamsType<this>): RoundedBoxGeometry;
88
+ collision(params?: ParamsType<this>): BoxCollisionShape;
89
+ }
90
+ declare class TextDefinition implements ShapeDefinition {
91
+ parameters: {
92
+ text: ShapeParameterDef<string>;
93
+ size: ShapeParameterDef<number>;
94
+ depth: ShapeParameterDef<number>;
95
+ };
96
+ geometry(params?: ParamsType<this>): TextGeometry;
97
+ collision(params?: ParamsType<this>): ConvexPolyhedronCollisionShape;
98
+ }
99
+ declare const shapes: {
100
+ box: {
101
+ geometry(): BoxGeometry;
102
+ collision(): BoxCollisionShape;
103
+ };
104
+ ramp: {
105
+ geometry(): BufferGeometry;
106
+ collision(): ConvexPolyhedronCollisionShape;
107
+ };
108
+ plane: PlaneDefinition;
109
+ cylinder: CylinderDefinition;
110
+ sphere: SphereDefinition;
111
+ torus: TorusDefinition;
112
+ cone: ConeDefinition;
113
+ circle: CircleDefinition;
114
+ capsule: CapsuleDefinition;
115
+ roundedBox: RoundedBoxDefinition;
116
+ text: TextDefinition;
117
+ };
118
+ export type LibraryShapeType = keyof typeof shapes;
119
+ export declare const ShapeLibrary: Record<LibraryShapeType, ShapeDefinition>;
120
+ export declare const ShapeLibraryKeys: ("sphere" | "box" | "ramp" | "plane" | "cylinder" | "torus" | "cone" | "circle" | "capsule" | "roundedBox" | "text")[];
121
+ export {};
@@ -0,0 +1,5 @@
1
+ import{BoxCollisionShape as e,CapsuleCollisionShape as t,ConeCollisionShape as r,ConvexPolyhedronCollisionShape as s,CylinderCollisionShape as n,PlaneCollisionShape as o,SphereCollisionShape as a,TrimeshCollisionShape as i}from"../collision/collision-shape";import{BoxGeometry as m,PlaneGeometry as h,Vector3 as l,CylinderGeometry as c,SphereGeometry as g,Euler as u,TorusGeometry as p,ConeGeometry as d,CircleGeometry as w,CapsuleGeometry as S}from"three";import{rampGeometry as y}from"./ramp-geometry";import{RoundedBoxGeometry as f}from"three/examples/jsm/geometries/RoundedBoxGeometry";import{TextGeometry as x}from"three/examples/jsm/geometries/TextGeometry";import{Font as b}from"three/examples/jsm/loaders/FontLoader";import*as j from"three/examples/fonts/helvetiker_regular.typeface.json";function L(e){return{type:"number",default:e}}function z(e){return{type:"number",default:e,float:!0}}function E(e){return{type:"boolean",default:e}}function k(e,t){const r={};for(let s in t)null==e[s]?r[s]=t[s].default:r[s]=e[s];return r}const v={box:{geometry:()=>new m(1,1,1),collision:()=>new e(new l(1,1,1))},ramp:{geometry:()=>y(),collision:()=>new s(y())},plane:new class{constructor(){this.parameters={widthSegments:L(1),heightSegments:L(1)}}geometry(e={}){const t=k(e,this.parameters);return new h(1,1,t.widthSegments,t.heightSegments)}collision(e={}){return new o(1,1)}},cylinder:new class{constructor(){this.parameters={radialSegments:L(12),heightSegments:L(1),openEnded:E(!1)}}geometry(e={}){const t=k(e,this.parameters);return new c(.5,.5,1,t.radialSegments,t.heightSegments,t.openEnded)}collision(e={}){const t=k(e,this.parameters);return new n(.5,.5,1,t.radialSegments,new u(0,1,0))}},sphere:new class{constructor(){this.parameters={withSegments:L(12),heightSegments:L(12)}}geometry(e={}){const t=k(e,this.parameters);return new g(.5,t.withSegments,t.heightSegments)}collision(){return new a(.5)}},torus:new class{constructor(){this.parameters={radius:z(1),tube:z(.3),radialSegments:L(16),tubularSegments:L(50)}}geometry(e={}){const t=k(e,this.parameters);return new p(t.radius,t.tube,t.radialSegments,t.tubularSegments)}collision(e={}){return new i(this.geometry(e))}},cone:new class{constructor(){this.parameters={radialSegments:L(12),heightSegments:L(1),openEnded:E(!1)}}geometry(e={}){const t=k(e,this.parameters);return new d(.5,1,t.radialSegments,t.heightSegments)}collision(e={}){return new r(1,.5)}},circle:new class{constructor(){this.parameters={segments:L(32)}}geometry(e={}){const t=k(e,this.parameters);return new w(.5,t.segments)}collision(e={}){return new i(this.geometry(e))}},capsule:new class{constructor(){this.parameters={radius:z(.5),length:z(1),capSegments:L(8),radialSegments:L(32)}}geometry(e={}){const t=k(e,this.parameters);return new S(t.radius,t.length,t.capSegments,t.radialSegments)}collision(e={}){const r=k(e,this.parameters);return new t(r.length,r.radius)}},roundedBox:new class{constructor(){this.parameters={width:z(1),height:z(1),depth:z(1),segments:L(4),radius:z(.1)}}geometry(e={}){const t=k(e,this.parameters);return new f(t.width,t.height,t.depth,t.segments,t.radius)}collision(t={}){const r=k(t,this.parameters);return new e(new l(r.width,r.height,r.depth))}},text:new class{constructor(){var e;this.parameters={text:(e="Text",{type:"string",default:e}),size:z(1),depth:z(.2)}}geometry(e={}){const t=k(e,this.parameters);return new x(t.text,{font:new b(j),size:t.size,height:t.depth})}collision(e={}){return k(e,this.parameters).text.trim().length,null}}};export const ShapeLibrary=v;export const ShapeLibraryKeys=Object.keys(ShapeLibrary);
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,14 @@
1
+ import { AssetsProvider } from '../scene/assets-provider';
2
+ import { Subject } from 'rxjs';
3
+ import { Asset } from '../scene/model';
4
+ import { RuntimeBackendService } from './runtime-backend-service';
5
+ export declare class RuntimeAssetsService implements AssetsProvider {
6
+ private backend;
7
+ private assets;
8
+ onCreate: Subject<Asset>;
9
+ onDelete: Subject<Asset>;
10
+ onUpdate: Subject<Asset>;
11
+ constructor(backend: RuntimeBackendService);
12
+ getAssets(): Promise<Asset[]>;
13
+ getAsset(id: string): Promise<Asset>;
14
+ }
@@ -0,0 +1,5 @@
1
+ import{__awaiter as t}from"tslib";import{Subject as s}from"rxjs";export class RuntimeAssetsService{constructor(t){this.backend=t,this.assets=new Map,this.onCreate=new s,this.onDelete=new s,this.onUpdate=new s}getAssets(){return t(this,void 0,void 0,(function*(){return Array.from(this.assets.values())}))}getAsset(s){var n;return t(this,void 0,void 0,(function*(){return null!==(n=this.assets.get(s))&&void 0!==n?n:function(s,n){return t(this,void 0,void 0,(function*(){return e.has(s)||e.set(s,n(s)),e.get(s)}))}(s,(()=>this.backend.getAsset(s)))}))}}const e=new Map;
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,12 @@
1
+ import { Asset, SceneData } from './model';
2
+ export declare class RuntimeBackendService {
3
+ private sceneStorage;
4
+ private sceneBlobStorage;
5
+ private assetStorage;
6
+ constructor(dataDir: string);
7
+ getAssets(): Promise<Asset[]>;
8
+ getAsset(id: string): Promise<Asset>;
9
+ getScenes(): Promise<SceneData[]>;
10
+ getScene(idOrName: string): Promise<SceneData>;
11
+ getSceneData(sceneId: string): Promise<string>;
12
+ }
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{ObjectStorage as t}from"./storage/storage";export class RuntimeBackendService{constructor(e){this.sceneStorage=new t("scene"),this.sceneBlobStorage=new t("scene-blob"),this.assetStorage=new t("asset"),this.sceneStorage.setBasePath(e),this.sceneBlobStorage.setBasePath(e),this.assetStorage.setBasePath(e)}getAssets(){return this.assetStorage.getAll()}getAsset(e){return this.assetStorage.get(e)}getScenes(){return this.sceneStorage.getAll()}getScene(e){return this.sceneStorage.get(e)}getSceneData(t){return e(this,void 0,void 0,(function*(){const e=yield this.sceneBlobStorage.get(t);return null==e?void 0:e.data}))}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,33 @@
1
+ import { SceneDataProvider, SceneObject } from '../scene/materializer';
2
+ import { BehaviorSubject } from 'rxjs';
3
+ import { Matrix4 } from 'three';
4
+ export declare class SceneDataService implements SceneDataProvider {
5
+ private objects;
6
+ private callbacks;
7
+ private removeCallbacks;
8
+ objectChange: BehaviorSubject<SceneObject[]>;
9
+ constructor();
10
+ initiate(data: string, addDefaultFog?: boolean): void;
11
+ removeOnUpdateCallback(callback: (sceneObject: SceneObject) => void): void;
12
+ onUpdate(callback: (sceneObject: SceneObject) => void): void;
13
+ onRemove(callback: (sceneObject: SceneObject) => void): void;
14
+ getObjects(): SceneObject[];
15
+ addObject(object: SceneObject): void;
16
+ updateObject(object: SceneObject): void;
17
+ findObjectById(id: string): SceneObject;
18
+ findAncestorsById(id: string): SceneObject[];
19
+ /**
20
+ * This is a breath first search in the tree until it is found with a worst case of O(N) time complexity.
21
+ * TODO Maintain direct references to parents in addition to having children.
22
+ * Separate the serialized and deserialized representation of objects.
23
+ */
24
+ findParentById(id: string): SceneObject;
25
+ private _findParentById;
26
+ updateParent(object: SceneObject, newParent: SceneObject): void;
27
+ getMatrixWorld(object: SceneObject): Matrix4;
28
+ getLocalMatrix(object: SceneObject): Matrix4;
29
+ removeObject(object: SceneObject): void;
30
+ private removeRecursive;
31
+ save(): void;
32
+ serialize(): string;
33
+ }
@@ -0,0 +1,5 @@
1
+ import{BehaviorSubject as t}from"rxjs";import{Matrix4 as e,Vector3 as s,Quaternion as i,Euler as o}from"three";export class SceneDataService{constructor(){this.objects=[],this.callbacks=[],this.removeCallbacks=[],this.objectChange=new t([])}initiate(t,e=!1){var s;this.objects=t&&null!==(s=JSON.parse(t))&&void 0!==s?s:[];!this.objects.some((t=>"global_fog"===t.type))&&e&&this.objects.unshift({id:"auto-global-fog",name:"Global fog",type:"global_fog",position:[0,0,0],scale:[1,1,1],rotation:[0,0,0],collisionDetection:!1,fog:{type:"density",color:"#b8f8ff",density:.005,near:100,far:1e3}}),this.objectChange.next(this.objects)}removeOnUpdateCallback(t){this.callbacks.splice(this.callbacks.indexOf(t),1)}onUpdate(t){this.callbacks.push(t)}onRemove(t){this.removeCallbacks.push(t)}getObjects(){return this.objects}addObject(t){this.objects.push(t),this.callbacks.forEach((e=>e(t))),this.objectChange.next(this.objects)}updateObject(t){const e=this.findObjectById(t.id);e?(Object.assign(e,t),this.callbacks.forEach((e=>e(t)))):this.addObject(t),this.objectChange.next(this.objects)}findObjectById(t){const e=[...this.objects];for(;e.length>0;){const s=e.pop();if(s.id===t)return s;s.children&&e.push(...s.children)}}findAncestorsById(t){const e=this.findParentById(t);return null==e?[]:[e,...this.findAncestorsById(e.id)]}findParentById(t){return this._findParentById(t,this.objects)}_findParentById(t,e,s=null){return e.some((e=>e.id===t))?s:e.filter((t=>null!=t.children)).map((e=>this._findParentById(t,e.children,e))).find((t=>null!=t))}updateParent(t,n){var r,c;const l=this.findParentById(t.id);{const r=null!=n?this.getMatrixWorld(n).invert():(new e).identity();null!=l&&r.multiply(this.getMatrixWorld(l));const c=this.getLocalMatrix(t),a=r.multiply(c),h=new s,d=new i,b=new s;a.decompose(h,d,b),t.position=h.toArray(),t.rotation=(new o).setFromQuaternion(d).toArray(),t.scale=b.toArray()}this.removeRecursive(t.id,null!==(r=null==l?void 0:l.children)&&void 0!==r?r:this.objects),null!=n?(null!==(c=n.children)&&void 0!==c||(n.children=[]),n.children.push(t)):this.objects.push(t),this.objectChange.next(this.objects),this.callbacks.forEach((e=>e(t)))}getMatrixWorld(t){const e=this.findAncestorsById(t.id).reverse();e.push(t);const s=this.getLocalMatrix(e.shift());for(const t of e){const e=this.getLocalMatrix(t);s.multiply(e)}return s}getLocalMatrix(t){const n=new e,r=(new s).fromArray(t.position),c=(new i).setFromEuler((new o).fromArray(t.rotation)),l=(new s).fromArray(t.scale);return n.compose(r,c,l),n}removeObject(t){this.removeRecursive(t.id,this.objects),this.removeCallbacks.forEach((e=>e(t))),this.objectChange.next(this.objects)}removeRecursive(t,e){var s;const i=e.findIndex((e=>e.id===t));if(i>-1)e.splice(i,1);else for(const i of e)this.removeRecursive(t,null!==(s=i.children)&&void 0!==s?s:[])}save(){}serialize(){return JSON.stringify(this.objects)}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,3 @@
1
+ import * as THREE from "three";
2
+ export declare function basicSceneSetup(scene: THREE.Scene): void;
3
+ export declare const ambientLightName = "default_ambient";
@@ -0,0 +1,5 @@
1
+ import*as e from"three";import{AmbientLight as a,FogExp2 as o}from"three";import{attributes as r,NodeShaderMaterial as t,uniforms as i,vec4 as n,varyingVec3 as s,float as h,normalize as c,rgb as d,mix as m,max as w,pow as p}from"three-shader-graph";export function basicSceneSetup(g){!function(o){new a(16777215,.5);var l=new e.HemisphereLight(16777215,273,.5);l.name=ambientLightName,l.position.set(0,100,0),o.add(l);new e.HemisphereLightHelper(l,10);var f=new e.DirectionalLight(16777215,.7);f.position.set(-30,50,30),f.castShadow=!0,f.shadow.mapSize.width=2048,f.shadow.mapSize.height=2048;var g=250;f.shadow.normalBias=.3,f.shadow.camera.left=-g,f.shadow.camera.right=g,f.shadow.camera.top=g,f.shadow.camera.bottom=-g,f.shadow.camera.far=500,f.shadow.bias=-5e-4;new e.DirectionalLightHelper(f,10);var S=new e.PointLight(16777215,1,50);S.castShadow=!0,S.position.set(0,40,0),S.shadow.camera.near=1,S.shadow.camera.far=60,S.shadow.bias=-.005;const L=h(5),b=h(.6),v=l.color.clone().convertSRGBToLinear(),u=new e.Color(13431551).convertSRGBToLinear();var y=new e.SphereGeometry(300,10,15);const B=s(i.modelMatrix.multiplyVec(n(r.position,1)).xyz()),x=c(B.addScalar(L)).y(),H=w(p(w(x,h(0)),h(b)),h(0)),R=n(m(d(u),d(v),H),h(1)),z=new t({color:R.rgba()});z.side=e.BackSide,z.depthTest=!1;var G=new e.Mesh(y,z);o.add(G),G.renderOrder=-999;const T=o.onBeforeRender;o.onBeforeRender=(e,a,o,r,t,i)=>{G.position.copy(o.position),T(e,a,o,r,t,i)},G.raycast=()=>{}}(g),function(e){e.fog=new o(l,f)}(g)}export const ambientLightName="default_ambient";const l=157554,f=.005;
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,39 @@
1
+ interface Entity {
2
+ id: string;
3
+ name: string;
4
+ fileKey?: string;
5
+ path?: string;
6
+ }
7
+ type ObjectIndexEntry = {
8
+ id: string;
9
+ name: string;
10
+ path?: string;
11
+ };
12
+ export declare class ObjectStorage<T extends Entity> {
13
+ private name;
14
+ private filePathFn?;
15
+ private path;
16
+ private basePathUpdates;
17
+ private basePath;
18
+ private loaded;
19
+ private cachedIndex;
20
+ constructor(name: string, filePathFn?: (o: ObjectIndexEntry) => string);
21
+ setBasePath(path: string): void;
22
+ getAll(): Promise<T[]>;
23
+ get(id: string): Promise<T>;
24
+ save(obj: T): Promise<T>;
25
+ rename(obj: T, name: string): Promise<T>;
26
+ delete(obj: T): Promise<void>;
27
+ create(obj: Partial<T>): Promise<T>;
28
+ private updateIndex;
29
+ private get indexFilePath();
30
+ private loadIndex;
31
+ ensureResourceDir(): Promise<void>;
32
+ saveFile(asset: T, file: File): Promise<any>;
33
+ getAssetPath(asset: T): any;
34
+ replaceFile(asset: T, replacementFile: String): Promise<any>;
35
+ deleteFile(fileKey: string): Promise<any>;
36
+ private privateObjectPath;
37
+ }
38
+ export declare function tokenizeName(name: string): string;
39
+ export {};
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{randomUUID as t}from"../../utils/uuid";import{pathJoin as i}from"../../utils/files";import{firstValueFrom as n,map as r,Subject as s,tap as o}from"rxjs";import{sleepDelay as a}from"../../utils/async";const d={},h={},l={};null==d.read&&window.require&&(Object.assign(d,window.require("fs")),Object.assign(h,d.promises),Object.assign(l,window.require("path")));const u=null!=d.existsSync;const c=/^[A-Z]:/;function p(...e){return 0===e.length?"":c.test(e[0])?l.join(...e):i(...e)}export class ObjectStorage{constructor(e,t){this.name=e,this.filePathFn=t,this.basePathUpdates=new s,this.basePath=this.basePathUpdates.pipe(r((e=>p(function(){if(u){const e="--path=",t=window.process.argv.find((t=>t.startsWith(e)));return t?t.substring(e.length):""}return""}(),e))),o((e=>{this.path=p(e,this.name),f(this.path)}))),this.loaded=n(this.basePath)}setBasePath(e){this.basePathUpdates.next(e)}getAll(){return e(this,void 0,void 0,(function*(){y(),yield this.loaded;const e=(yield h.readdir(this.path)).filter((e=>!/^[\._]/.test(e)));return(yield Promise.all(e.map((e=>h.readFile(p(this.path,e)))))).map((e=>JSON.parse(e.toString())))}))}get(t){var i;return e(this,void 0,void 0,(function*(){const e=yield this.loadIndex(),n=null!==(i=e[t])&&void 0!==i?i:Object.values(e).find((e=>e.name===t));if(null==n)return;const r=this.privateObjectPath(n);if(!u)return(yield fetch(r)).json();return(yield v(r))?JSON.parse((yield h.readFile(r)).toString()):null}))}save(t){return e(this,void 0,void 0,(function*(){return y(),yield this.loaded,yield h.writeFile(this.privateObjectPath(t),JSON.stringify(t,null,2)),yield this.updateIndex(),t}))}rename(t,i){return e(this,void 0,void 0,(function*(){const e=Object.assign(Object.assign({},t),{name:i}),n=this.privateObjectPath(t),r=this.privateObjectPath(e);try{yield h.rename(n,r)}catch(e){console.error(e),console.warn("Rename failed, retrying",{currentPath:n,newPath:r}),yield a(400),yield h.rename(n,r)}return yield this.save(e),yield this.updateIndex(),e}))}delete(t){return e(this,void 0,void 0,(function*(){yield h.unlink(this.privateObjectPath(t)),this.updateIndex()}))}create(i){return e(this,void 0,void 0,(function*(){return y(),yield this.loaded,i.id=t(),yield h.writeFile(this.privateObjectPath(i),JSON.stringify(i,null,2)),yield this.updateIndex(),i}))}updateIndex(){var t;return e(this,void 0,void 0,(function*(){y();const e=yield this.getAll(),i={};for(const n of e)i[n.id]={id:n.id,name:null!==(t=n.name)&&void 0!==t?t:n.id,path:n.path};this.cachedIndex=i,u&&(yield h.writeFile(this.indexFilePath,JSON.stringify(i,null,2)))}))}get indexFilePath(){return p(this.path,"_meta.json")}loadIndex(){return e(this,void 0,void 0,(function*(){return null==this.cachedIndex&&(u?yield this.updateIndex():this.cachedIndex=yield(yield fetch(this.indexFilePath)).json()),this.cachedIndex}))}ensureResourceDir(){return e(this,void 0,void 0,(function*(){yield f(p(this.path+"-resources"))}))}saveFile(t,i){return e(this,void 0,void 0,(function*(){return y(),yield f(p(this.path+"-resources")),h.copyFile(i.path,p(this.path+"-resources",t.fileKey))}))}getAssetPath(e){return window&&"function"==typeof window.require?window.require("path").join(this.path+"-resources",e.fileKey):p(this.path+"-resources",e.fileKey)}replaceFile(t,i){return e(this,void 0,void 0,(function*(){if(yield v(i))return h.copyFile(i,p(this.path+"-resources",t.fileKey));console.error("Failed to replace file using path "+i)}))}deleteFile(t){return e(this,void 0,void 0,(function*(){if(null==t)return;y();const e=p(this.path+"-resources",t);return(yield v(e))?h.unlink(e):void 0}))}privateObjectPath(e){var t;return this.filePathFn?p(this.path,this.filePathFn(e)):p(this.path,tokenizeName(null!==(t=e.name)&&void 0!==t?t:e.id)+".json")}}export function tokenizeName(e){return e.trim().replace(/\s/g,"_").replace(/[^a-z0-9_\-\.]/gi,"")}function f(t){return e(this,void 0,void 0,(function*(){u&&((yield v(t))||(yield h.mkdir(t,{recursive:!0})))}))}function v(e){return!!u&&new Promise((function(t,i){d.exists(e,(function(e){t(e)}))}))}function y(){if(!u)throw new Error("Must have direct access to filesystem")}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,2 @@
1
+ export * from './standard-shader';
2
+ export * from './lambert-shader';
@@ -0,0 +1,5 @@
1
+ export*from"./standard-shader";export*from"./lambert-shader";
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,19 @@
1
+ import { Color, Material, Texture } from 'three';
2
+ import { Shader } from "../shader";
3
+ export declare class LambertShader extends Shader {
4
+ color?: Color;
5
+ emissive?: Color;
6
+ emissiveIntensity?: number;
7
+ emissiveMap?: Texture;
8
+ map?: Texture;
9
+ lightMap?: Texture;
10
+ lightMapIntensity?: number;
11
+ aoMap?: Texture;
12
+ aoMapIntensity?: number;
13
+ specularMap?: Texture;
14
+ alphaMap?: Texture;
15
+ envMap?: Texture;
16
+ reflectivity?: number;
17
+ refractionRatio?: number;
18
+ build(): Material;
19
+ }
@@ -0,0 +1,5 @@
1
+ import{__decorate as e,__metadata as t}from"tslib";import{Color as i,Texture as a,MeshLambertMaterial as r}from"three";import{Shader as p}from"../shader";import{Parameter as o}from"../parameter";export class LambertShader extends p{build(){return new r({color:this.color,emissive:this.emissive,emissiveIntensity:this.emissiveIntensity,emissiveMap:this.emissiveMap,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,specularMap:this.specularMap,alphaMap:this.alphaMap,envMap:this.envMap,reflectivity:this.reflectivity,refractionRatio:this.refractionRatio})}}e([o(),t("design:type",i)],LambertShader.prototype,"color",void 0),e([o(),t("design:type",i)],LambertShader.prototype,"emissive",void 0),e([o({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"emissiveIntensity",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"emissiveMap",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"map",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"lightMap",void 0),e([o(),t("design:type",Number)],LambertShader.prototype,"lightMapIntensity",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"aoMap",void 0),e([o(),t("design:type",Number)],LambertShader.prototype,"aoMapIntensity",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"specularMap",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"alphaMap",void 0),e([o(),t("design:type",a)],LambertShader.prototype,"envMap",void 0),e([o({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"reflectivity",void 0),e([o({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"refractionRatio",void 0);
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */