@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*as e from"three";import{Mesh as t,Matrix4 as i,ShaderMaterial as r,PerspectiveCamera as s,ShaderChunk as n}from"three";import{EffectComposer as a}from"three-stdlib";import{RenderPass as o}from"three-stdlib";import{ShaderPass as h}from"three-stdlib";import{FXAAShader as d}from"three-stdlib";import{CSM as l}from"three-stdlib";import{CSMUtil as c}from"./csm";import{GammaCorrectionShader as m}from"three-stdlib";import{Reflector as p}from"three-stdlib";import{depthUniformName as u,resolutionUniformName as g,supportsDepthTextureExtension as v,nearUniformName as f,farUniformName as w}from"./shader-nodes/depth";import{elapsedTimeUniformName as x}from"./shader-nodes/time";import{OutlinePass as b}from"./utils/three/outline-pass";import C from"./utils/three/stats";import{lambertVertexShaderOverride as R}from"./rendering/shader-override";import{DepthPass as y}from"./utils/three/depth-pass";const P=new e.MeshDepthMaterial;P.depthPacking=e.RGBADepthPacking,P.blending=e.NoBlending;n.lights_pars_begin;n.lights_lambert_vertex=R;export class RenderingView{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.camera instanceof s&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(window.devicePixelRatio*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=1,this.onResize=()=>{this.resizeRender(),this.paused||this.composer.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,window.renderer=this.renderer=new e.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new e.Scene,this.renderer.setPixelRatio(window.devicePixelRatio*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.composer=new a(this.renderer);var r=t.clientWidth/t.clientHeight;const s=new e.PerspectiveCamera(45,r,.5,500);s.layers.enable(19),this.setCamera(s),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=e.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=!1,this.renderer.outputEncoding=e.sRGBEncoding,this.renderer.physicallyCorrectLights=!1,this.renderer.gammaFactor=1.4,c.renderingView=this,c.patchThreeAdd(),this.isDepthTextureExtensionSupported=v(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=RenderingView.createDepthRenderTarget(this.renderer,this.container);const n=new o(this.scene,this.camera);if(this.composer.addPass(n),this.outlinePass=new b(new e.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new h(d);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e);var l=new h(m);l.clear=!1,this.composer.addPass(l)}}setCamera(t){this.camera=t,this.composer.passes.forEach((e=>{e instanceof o?e.camera=t:e instanceof b?e.renderCamera=t:e instanceof y&&(e.camera=t)})),null==this.csm?this.csm=new l({maxFar:200,lightFar:300,cascades:5,shadowMapSize:2048,lightDirection:new e.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5,camera:this.camera,parent:this.scene}):(this.csm.camera=this.camera,this.camera instanceof s&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(t,i){var r=!!t.extensions.get("WEBGL_depth_texture");const s=new e.WebGLRenderTarget(i.clientWidth*t.getPixelRatio(),i.clientHeight*t.getPixelRatio());return s.texture.minFilter=e.NearestFilter,s.texture.magFilter=e.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,!0===r&&(s.depthTexture=new e.DepthTexture(128,128),s.depthTexture.type=e.UnsignedShortType,s.depthTexture.minFilter=e.NearestFilter,s.depthTexture.magFilter=e.NearestFilter),s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);this.onLoopCallbacks.splice(t,1)}loop(r,s=!1){var n=C();n.showPanel(0);performance.now();e.Ray.prototype.intersectTriangle;let a=0;const o=new i,h=new i,d=e=>{var i,s;const l=this.renderer.getContext();if(this.paused&&this.running&&l.drawingBufferHeight>1)return void setTimeout((()=>d(e)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,n.begin();let c=(e*=.001)-a;if(a=e,o.copy(this.camera.matrixWorld),c>1){let e=c;for(;e>.05;)r(T),e-=T;r(e)}else r(c);this.onLoopCallbacks.forEach((e=>e(c))),null===(i=this.camera)||void 0===i||i.updateMatrixWorld(),h.copy(this.camera.matrixWorld),h.equals(o)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender();const m=[],g=[];if(this.scene.traverse((i=>{var r,s,n,a,o,h;i instanceof t&&i.visible&&((null===(s=null===(r=i.material)||void 0===r?void 0:r.userData)||void 0===s?void 0:s.water)||(null===(n=i.material)||void 0===n?void 0:n.uniforms)&&null!=(null===(a=i.material)||void 0===a?void 0:a.uniforms[u]))?(i.visible=!1,m.push(i),this.initDepthUniform(i.material),i.renderOrder=100):i instanceof p&&(i.visible=!1,g.push(i)),i instanceof t&&(null===(o=i.material)||void 0===o?void 0:o.uniforms)&&null!=(null===(h=i.material)||void 0===h?void 0:h.uniforms[x])&&(i.material.uniforms[x].value=e)})),m.length>0){if(this.scene.overrideMaterial=P,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0));try{!this.paused&&this.running&&(this.composer.render(c),this.renderOverlay())}catch(e){console.warn(e)}n.end(),null===(s=this.csm)||void 0===s||s.update(),this.running&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(d)}),1e3/this.fpsCap):requestAnimationFrame(d))};requestAnimationFrame(d)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let r=0;r<e.length;r++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*r+this.insetMargin*r,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[r])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(){this.composer.render()}initDepthUniform(e){e instanceof r&&(e.uniforms[u].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[g]&&e.uniforms[g].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof s&&(e.uniforms[f].value=this.camera.near,e.uniforms[w].value=this.camera.far))}}export function setRenderingPaused(e){var t,i;null!=(null===(i=null===(t=window.editor)||void 0===t?void 0:t.viewer)||void 0===i?void 0:i.renderingView)&&(window.editor.viewer.renderingView.paused=e)}const T=.05;
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,32 @@
1
+ import { Group, Texture } from 'three';
2
+ import { Asset } from './model';
3
+ import { CollisionShape } from './collision/collision-shape';
4
+ export declare class AssetResourceLoader {
5
+ private basePath;
6
+ private cache;
7
+ private textureCache;
8
+ private loadingManager;
9
+ private glbLoader;
10
+ private fbxLoader;
11
+ private textureLoader;
12
+ private audioLoader;
13
+ private makeReady;
14
+ private ready;
15
+ constructor();
16
+ setDataDir(path: string): void;
17
+ private getUri;
18
+ getTexture(asset: Asset): Promise<Texture>;
19
+ getMesh(asset: Asset): Promise<LoadedMesh>;
20
+ getAudio(asset: Asset): Promise<AudioBuffer>;
21
+ private collisionShapeCache;
22
+ private computeCollisionShapes;
23
+ private loadMesh;
24
+ private loadByAsset;
25
+ }
26
+ export interface LoadedMesh {
27
+ scene: AssetMeshInstance;
28
+ }
29
+ export declare class AssetMeshInstance extends Group {
30
+ collisionShapes?: CollisionShape[];
31
+ }
32
+ export declare function getElectronArg(name: string): string;
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{AudioLoader as t,Group as i,LoadingManager as s,TextureLoader as o}from"three";import{GLTFLoader as r}from"three-stdlib";import{FBXLoader as n}from"three-stdlib";import{cloneMesh as a}from"../utils/mesh";import{pathJoin as h}from"../utils/files";import{Subject as l,firstValueFrom as d}from"rxjs";import{importCollisionShapes as c}from"./collision/collision-shape-import";const u=["glb","fbx"];export class AssetResourceLoader{constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new s,this.glbLoader=new r(this.loadingManager),this.fbxLoader=new n(this.loadingManager),this.textureLoader=new o(this.loadingManager),this.audioLoader=new t(this.loadingManager),this.makeReady=new l,this.ready=d(this.makeReady),this.collisionShapeCache=new Map}setDataDir(e){this.basePath=h(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return h(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}getTexture(t){return e(this,void 0,void 0,(function*(){return null==t?null:(yield this.ready,this.cache.has(t.id)||(yield this.textureLoader.loadAsync(this.getUri(t.fileKey)).then((e=>(e.flipY=!1,this.textureCache.set(t.id,e),e)))),this.textureCache.get(t.id))}))}getMesh(t){var s;return e(this,void 0,void 0,(function*(){if(yield this.ready,!u.includes(null===(s=t.fileFormat)||void 0===s?void 0:s.toLowerCase()))return console.error("Unsupported mesh file format "+t.fileFormat,t),{scene:new i};this.cache.has(t.fileKey)||(yield this.loadMesh(t));const{scene:e}=this.cache.get(t.fileKey),o=this.computeCollisionShapes(t,e),r=(new AssetMeshInstance).copy(a(e));return r.collisionShapes=o,{scene:r}}))}getAudio(t){return e(this,void 0,void 0,(function*(){return yield this.ready,this.audioLoader.loadAsync(this.getUri(t.fileKey))}))}computeCollisionShapes(e,t){return this.collisionShapeCache.get(e.id)||this.collisionShapeCache.set(e.id,c(t)),this.collisionShapeCache.get(e.id)}loadMesh(t){return e(this,void 0,void 0,(function*(){return yield this.ready,yield this.loadByAsset(t).then((e=>(e.scene.animations=[],this.cache.set(t.fileKey,e),e)))}))}loadByAsset(e){const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":return this.glbLoader.loadAsync(t).then((e=>({scene:e.scene})));case"fbx":return this.fbxLoader.loadAsync(t).then((e=>({scene:e})))}}}export class AssetMeshInstance extends i{}export function getElectronArg(e){var t;const i=`--${e}=`,s=null===(t=window.process)||void 0===t?void 0:t.argv.find((e=>e.startsWith(i)));return null==s?void 0:s.substring(i.length)}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,9 @@
1
+ import { Subject } from "rxjs";
2
+ import { Asset, AssetId } from "./model";
3
+ export interface AssetsProvider {
4
+ onCreate: Subject<Asset>;
5
+ onDelete: Subject<Asset>;
6
+ onUpdate: Subject<Asset>;
7
+ getAsset(assetId: AssetId): Promise<Asset>;
8
+ getAssets(): Promise<Asset[]>;
9
+ }
@@ -0,0 +1,5 @@
1
+ export{};
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,21 @@
1
+ import * as THREE from 'three';
2
+ import { RenderingView } from '../rendering';
3
+ import { AssetResourceLoader } from './asset-resource-loader';
4
+ import { ActorProvider, SceneMaterializer } from './materializer';
5
+ import { RuntimeBackendService } from './runtime-backend-service';
6
+ import { RuntimeAssetsService } from './runtime-asset-service';
7
+ import { ShaderType, ActorType } from '../shader/shader';
8
+ export type ShaderDefinitions = {
9
+ [name: string]: ShaderType;
10
+ };
11
+ export type ActorDefinitions = {
12
+ [name: string]: ActorType;
13
+ };
14
+ export declare function loadScene(view: RenderingView, sceneName: string, dataDir: string, shaders: ShaderDefinitions, actors: ActorDefinitions, actorProvider: ActorProvider, backendService: RuntimeBackendService, assetsService: RuntimeAssetsService, assetResourceLoader: AssetResourceLoader): Promise<{
15
+ scene: THREE.Scene;
16
+ view: RenderingView;
17
+ materializer: SceneMaterializer;
18
+ assetResourceLoader: AssetResourceLoader;
19
+ assetsService: RuntimeAssetsService;
20
+ actors: import("../gameplay").BaseActor[];
21
+ }>;
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{polyfill as t}from"../utils/polyfill";import{SceneDataService as i}from"./scene-data-service";import{SceneMaterializer as n}from"./materializer";import{basicSceneSetup as r}from"./sky";export function loadScene(o,s,a,c,m,l,d,p,f){return e(this,void 0,void 0,(function*(){t();const{scene:e,renderer:a,camera:u}=o;r(e);const y=yield d.getScene(s);if(null==y)throw Error(`Could not find scene with name ${s}`);const v=yield d.getSceneData(y.id),w=new i;w.initiate(v,!0);const h=Object.entries(c).map((([e,t])=>({name:e,type:t}))),S=Object.entries(m).map((([e,t])=>({name:e,type:t}))),b=new n(e,w,p,f,o,h,S,l);return yield b.initWithInstancing(),{scene:e,view:o,materializer:b,assetResourceLoader:f,assetsService:p,actors:b.actorInstances}}))}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,4 @@
1
+ import { Object3D } from "three";
2
+ import { CollisionShape } from "./collision-shape";
3
+ export declare function importCollisionShapes(group: Object3D): CollisionShape[];
4
+ export declare function isCollisionMesh(object: Object3D): boolean;
@@ -0,0 +1,5 @@
1
+ import{Box3 as e,Euler as t,Mesh as n,Quaternion as o,Vector3 as i}from"three";import{BoxCollisionShape as r,ConvexPolyhedronCollisionShape as s,SphereCollisionShape as a,TrimeshCollisionShape as m}from"./collision-shape";const c=new o;export function importCollisionShapes(o){const x=[];return o.traverse((o=>{if(o instanceof n||o.isMesh){const n=function(t){if(t.name.startsWith(u.convex))return new s(t);if(t.name.startsWith(u.box)){const n=t.clone();n.quaternion.set(0,0,0,1),n.updateMatrixWorld();const o=(new e).setFromObject(n);return isFinite(o.min.lengthSq())?new r(new i(o.max.x-o.min.x,o.max.y-o.min.y,o.max.z-o.min.z)):null}if(t.name.startsWith(u.sphere)){t.geometry.computeBoundingSphere();const e=t.geometry.boundingSphere.radius*Math.max(t.scale.x,t.scale.y,t.scale.z);return new a(e)}if(t.name.startsWith(u.trimesh))return new m(t.geometry);{t.geometry.computeBoundingBox();const e=function(e){const t=e.max.x-e.min.x,n=e.max.y-e.min.y,o=e.max.z-e.min.z;return t+n+o}(h.copy(t.geometry.boundingBox).applyMatrix4(t.matrixWorld));if(e>.001)return new s(t)}}(o);null!=n&&(n.offset=o.getWorldPosition(new i),n.rotation=(new t).setFromQuaternion(o.getWorldQuaternion(c)),x.push(n),isCollisionMesh(o)&&(o.visible=!1))}})),x}export function isCollisionMesh(e){return e.name.startsWith(u.convex)||e.name.startsWith(u.box)||e.name.startsWith(u.sphere)||e.name.startsWith(u.trimesh)}var u;!function(e){e.convex="UCX_",e.box="UBX_",e.sphere="USP_",e.trimesh="UTM_"}(u||(u={}));const h=new e;
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,59 @@
1
+ import { BoxGeometry, BufferGeometry, Euler, Material, Mesh, Vector3 } from "three";
2
+ export declare class CollisionShape {
3
+ offset: Vector3;
4
+ rotation: Euler;
5
+ withOffset(vector: Vector3): this;
6
+ withRotation(rotation: Euler): this;
7
+ }
8
+ export declare class BoxCollisionShape extends CollisionShape {
9
+ readonly dimensions: Vector3;
10
+ constructor(dimensions: Vector3);
11
+ }
12
+ export declare class PlaneCollisionShape extends CollisionShape {
13
+ readonly width: number;
14
+ readonly height: number;
15
+ constructor(width: number, height: number);
16
+ }
17
+ export declare class SphereCollisionShape extends CollisionShape {
18
+ readonly radius: number;
19
+ constructor(radius: number);
20
+ }
21
+ export declare class CylinderCollisionShape extends CollisionShape {
22
+ readonly radiusTop: number;
23
+ readonly radiusBottom: number;
24
+ readonly height: number;
25
+ readonly segments: number;
26
+ readonly orentation: Euler;
27
+ constructor(radiusTop: number, radiusBottom: number, height: number, segments: number, orentation: Euler);
28
+ }
29
+ export declare class ConeCollisionShape extends CollisionShape {
30
+ readonly radiusBottom: number;
31
+ readonly height: number;
32
+ constructor(radiusBottom: number, height: number);
33
+ }
34
+ export declare class ConvexPolyhedronCollisionShape extends CollisionShape {
35
+ readonly mesh: Mesh | BufferGeometry;
36
+ constructor(mesh: Mesh | BufferGeometry);
37
+ }
38
+ export declare class TrimeshCollisionShape extends CollisionShape {
39
+ readonly geometry: BufferGeometry;
40
+ constructor(geometry: BufferGeometry);
41
+ }
42
+ export declare class MeshCollisionShape extends CollisionShape {
43
+ readonly geometry: BufferGeometry;
44
+ constructor(geometry: BufferGeometry);
45
+ }
46
+ export declare class CapsuleCollisionShape extends CollisionShape {
47
+ length: number;
48
+ radius: number;
49
+ constructor(length: number, radius: number);
50
+ }
51
+ export declare class PhysicalShapeMesh extends Mesh {
52
+ collisionShape: CollisionShape;
53
+ isPhysicalShapeMesh: boolean;
54
+ constructor(geometry: BufferGeometry, material: Material, collisionShape: CollisionShape);
55
+ }
56
+ export declare class PhysicalBoxMesh extends PhysicalShapeMesh {
57
+ isPhysicalBoxMesh: boolean;
58
+ constructor(geometry: BoxGeometry, material: Material);
59
+ }
@@ -0,0 +1,5 @@
1
+ import{Euler as s,Mesh as e,Vector3 as o}from"three";export class CollisionShape{constructor(){this.offset=new o,this.rotation=new s}withOffset(s){return this.offset.copy(s),this}withRotation(s){return this.rotation.copy(s),this}}export class BoxCollisionShape extends CollisionShape{constructor(s){super(),this.dimensions=s}}export class PlaneCollisionShape extends CollisionShape{constructor(s,e){super(),this.width=s,this.height=e}}export class SphereCollisionShape extends CollisionShape{constructor(s){super(),this.radius=s}}export class CylinderCollisionShape extends CollisionShape{constructor(s,e,o,t,i){super(),this.radiusTop=s,this.radiusBottom=e,this.height=o,this.segments=t,this.orentation=i}}export class ConeCollisionShape extends CollisionShape{constructor(s,e){super(),this.radiusBottom=s,this.height=e}}export class ConvexPolyhedronCollisionShape extends CollisionShape{constructor(s){super(),this.mesh=s}}export class TrimeshCollisionShape extends CollisionShape{constructor(s){super(),this.geometry=s}}export class MeshCollisionShape extends CollisionShape{constructor(s){super(),this.geometry=s}}export class CapsuleCollisionShape extends CollisionShape{constructor(s,e){super(),this.length=s,this.radius=e}}export class PhysicalShapeMesh extends e{constructor(s,e,o){super(s,e),this.collisionShape=o,this.isPhysicalShapeMesh=!0}}export class PhysicalBoxMesh extends PhysicalShapeMesh{constructor(s,e){super(s,e,new BoxCollisionShape(new o(s.parameters.width,s.parameters.height,s.parameters.depth))),this.isPhysicalBoxMesh=!0}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,43 @@
1
+ import { SceneObject } from '../../scene/materializer';
2
+ import { RenderingView } from '../../rendering';
3
+ import { Mesh, Vector3 } from 'three';
4
+ import { LandscapeGroup } from './landscape';
5
+ import { AssetResourceLoader } from '../asset-resource-loader';
6
+ import { AssetsProvider } from '../../scene/assets-provider';
7
+ import { ShaderImpl } from '../../shader/shader';
8
+ /**
9
+ * Creates landscape with varying level of detail depending on the
10
+ */
11
+ export declare class LandscapeManager {
12
+ readonly source: SceneObject;
13
+ private view;
14
+ private landscape;
15
+ private assetManagerService;
16
+ private assetService;
17
+ private shaders;
18
+ private applyMaterial;
19
+ private scatterMeshes;
20
+ private loadedScatterSquares;
21
+ private refreshRequests;
22
+ private defaultLandscapeMaterial;
23
+ private onLoopHandler;
24
+ constructor(source: SceneObject, view: RenderingView, landscape: LandscapeGroup, assetManagerService: AssetResourceLoader, assetService: AssetsProvider, shaders: ShaderImpl[], applyMaterial: (object: Mesh) => void);
25
+ updateShaders(shaders: ShaderImpl[]): void;
26
+ private sectionCache;
27
+ private grassGeometry;
28
+ private grassMaterial;
29
+ private loadGrass;
30
+ refreshGeometry(): void;
31
+ private applyHeightMap;
32
+ private deleteOldScatterMeshes;
33
+ private _matrix;
34
+ queueRefreshScatter(origin: Vector3, force?: boolean, predicate?: (mesh: Mesh) => boolean): void;
35
+ private scatterGeometryCache;
36
+ refreshScatter(origin: Vector3, force?: boolean, predicate?: (mesh: Mesh) => boolean): Promise<void>;
37
+ stop(): void;
38
+ private _lastUpdatePosition;
39
+ private _cameraPosition;
40
+ private update;
41
+ clear(): void;
42
+ private createLandscapeMesh;
43
+ }
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{materialFromAsset as t}from"../../scene/materializer";import{Mesh as s,PlaneGeometry as o,Vector3 as n,InstancedMesh as i,Matrix4 as a,MeshLambertMaterial as r,Color as c,Vector2 as l,Triangle as h,Box3 as u,MathUtils as d,MeshStandardMaterial as f,ShaderMaterial as m,DoubleSide as p,PerspectiveCamera as w}from"three";import{indexBy as y}from"../../utils/collections";import{smoothNormalsCrossMeshes as v}from"./utils";import*as M from"three";import{defaultLandscapeMaterial as g,LandscapeMesh as x}from"./landscape";import{meanVectors3withWeight as S,clamp as b}from"../../utils/math";import{whenIdle as A}from"../../utils/async";import{Subject as P,debounceTime as z}from"rxjs";new n,new n;const L=new n,B=new n,G=new n;export class LandscapeManager{constructor(e,t,s,o,i,r,c){this.source=e,this.view=t,this.landscape=s,this.assetManagerService=o,this.assetService=i,this.shaders=r,this.applyMaterial=c,this.scatterMeshes=new Map,this.loadedScatterSquares=new Set,this.refreshRequests=new P,this.defaultLandscapeMaterial=g.clone(),this.onLoopHandler=()=>this.update(),this.sectionCache=new Map,this._matrix=new a,this.scatterGeometryCache=new Map,this._lastUpdatePosition=new n,this._cameraPosition=new n,this.view.onLoop(this.onLoopHandler),this.defaultLandscapeMaterial.color=g.color,this.refreshRequests.pipe(z(500)).subscribe((e=>this.refreshScatter(e.origin,e.force,e.predicate)))}updateShaders(e){this.shaders=e}loadGrass(){return e(this,void 0,void 0,(function*(){const e=yield this.assetService.getAsset("6ij937n72g");yield this.assetManagerService.getMesh(e);this.grassGeometry=new o(2,2,3,3);const t=this.grassGeometry.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.needsUpdate=!0,this.grassMaterial=new f({color:3765785})}))}refreshGeometry(){const e=this.source.landscape.options,t=(new n,new n);this.view.camera.getWorldPosition(t);const s=[];G.fromArray(this.source.position);const o=this.view.camera instanceof w?Math.min(this.view.camera.far,1e3):1e3,i=1.1*o,a=e.sections.y*e.sectionSize/-2,r=e.sections.x*e.sectionSize/-2;for(let n=0;n<e.sections.x;n++)if(L.x=r+n*e.sectionSize,!(Math.abs(t.x-L.x)>i))for(let c=0;c<e.sections.y;c++){L.z=a+c*e.sectionSize,B.copy(G).add(L);const l=B.distanceTo(t),h=`${n},${c}`,u=this.landscape.sections.find((e=>e.x===n&&e.y===c));if(l<=o){if(null==u){this.sectionCache.has(h)||this.sectionCache.set(h,this.createLandscapeMesh(this.source,e,r,a,n,c));const t=this.sectionCache.get(h);this.applyMaterial(t),this.landscape.add(t),s.push(t)}}else l>i&&this.landscape.remove(u)}v(s)}applyHeightMap(e,t,s,o=1){var n,i,a,r;const c=Math.pow(s+1,2),l=e.getAttribute("position"),h=y(null!==(n=t.points)&&void 0!==n?n:[],(e=>e.i));if(1===o)for(const e of t.points)l.setY(e.i,e.y);else for(let e=0;e<l.count;e++){const t=$(e,l.count,c);let s=0;s=t%1==0?null!==(a=null===(i=h.get(t))||void 0===i?void 0:i.y)&&void 0!==a?a:0:Math.floor(null===(r=h.get(t))||void 0===r?void 0:r.y),l.setY(e,s)}l.needsUpdate=!0,e.computeVertexNormals()}deleteOldScatterMeshes(){var e,t;const s=new Set;for(const[o,n]of null!==(t=null===(e=this.source.grass)||void 0===e?void 0:e.layers.entries())&&void 0!==t?t:[])for(const[e,t]of n.meshes.entries()){const t=`${o}-${e}`;s.add(t)}for(const e of this.scatterMeshes.keys())if(!s.has(e)){this.scatterMeshes.get(e).forEach((e=>{var t;null===(t=e.parent)||void 0===t||t.remove(e),e.dispose()})),this.scatterMeshes.delete(e)}}queueRefreshScatter(e,t=!1,s=(()=>!0)){this.refreshRequests.next({origin:e,force:t,predicate:s})}refreshScatter(a,l=!1,u=(()=>!0)){var f,w,v,g;return e(this,void 0,void 0,(function*(){l&&this.scatterGeometryCache.clear(),this.deleteOldScatterMeshes();for(const[x,P]of null!==(w=null===(f=this.source.grass)||void 0===f?void 0:f.layers.entries())&&void 0!==w?w:[])for(const[f,w]of P.meshes.entries()){const P=`${x}-${f}`;this.scatterMeshes.has(P)||this.scatterMeshes.set(P,new Map);const z=this.scatterMeshes.get(P),L=yield this.assetService.getAsset(w.assetId),B=yield this.assetManagerService.getMesh(L),G=[];if(B.scene.traverse((e=>{e instanceof s&&G.push(e)})),1!==G.length){console.log(B),console.warn("Dynamic grass only works for meshes with a single geometry.");continue}if(!(G[0]instanceof s)){console.warn("Only meshes can be used for dynamic grass. Found:",B.scene);continue}const $=G[0];let _=$.geometry;this.scatterGeometryCache.has($.geometry.uuid)?_=this.scatterGeometryCache.get($.geometry.uuid):(_=$.geometry.clone(),!0===w.normalsUp&&E(_),this.scatterGeometryCache.set($.geometry.uuid,_),null==_.userData.updatedMatrix&&(B.scene.updateMatrixWorld(),_.applyMatrix4($.matrixWorld),_.userData.updatedMatrix=!0));const U=_.getIndex().count/3;if(U>400){console.warn(`The triangle count of ${L.name} is too big ${U}. Keep it below 400`);continue}const D=null!=L.materialAssignments&&L.materialAssignments.length>0?L.materialAssignments[0].materialId:null,I=null!=D&&"null"!==D?yield t(yield this.assetService.getAsset(D),null,this.assetService,this.assetManagerService,this.shaders,!1):null;let O=null!=I?I:$.material;O instanceof m&&(O.side=p);const Y=d.degToRad(null!==(v=w.maxSlope)&&void 0!==v?v:90),X=Math.cos(Y),F=this.landscape.sections,N=F.filter(k(a,w.viewDistance)).filter((e=>!z.has(e.uuid)||l)).filter((e=>u(e)));F.filter(C(a,2*w.viewDistance)).forEach((e=>{var t;const s=z.get(e.uuid);null===(t=null==s?void 0:s.parent)||void 0===t||t.remove(s),z.delete(e.uuid)}));performance.now();const Z=this.source.landscape.options,K=Z.sectionSize,V=null!==(g=w.density)&&void 0!==g?g:1,J=null!=V?V:1,Q=Z.density,ee=K/Q,te=J,se=ee/Math.sqrt(te),oe=Math.pow(Q,2),ne=se/ee,ie=Math.floor(oe*te),ae=[0,0,0];for(const t of N)yield A((()=>e(this,void 0,void 0,(function*(){var e,s,a,u,d,f,m;t.updateWorldMatrix(!0,!1);const p=this._matrix,v=new n,g=t.geometry.getAttribute("position"),A=t.geometry.getAttribute("normal"),P=(null!==(e=this.source.vertexMaterials)&&void 0!==e?e:[]).filter((e=>e.m===t.name)),L=y(P,(e=>e.i));let B=z.get(t.uuid);if(null==B||B.count==ie&&!l||(null===(s=B.parent)||void 0===s||s.remove(B),z.delete(t.uuid),B=null),null==B){const e=new o(.15,.75).getAttribute("normal");for(let t=0;t<e.count;t++);new r({color:new c(3765785),side:M.DoubleSide});B=new i(_,O,ie),B.raycast=()=>{},B.receiveShadow=!0}const G=new h(new n,new n,new n);let[$,C,k,U]=[new n,new n,new n,new n],[D,I,Y]=[[],[],[]],[E,F,N]=[new n,new n,new n,new n];const Z=new n,K=new n,V=new n,J=new n,ee=new h(new n,new n,new n),re=new h(new n,new n,new n),ce=new h(new n,new n,new n),le=new h(new n,new n,new n);let he=0;e:for(let e=0;e<oe;e++){const s=Math.floor(e/Q);$.fromBufferAttribute(g,e+s),J.copy($).applyMatrix4(t.matrixWorld),ee.a.copy($),ee.b.fromBufferAttribute(g,e+1+s),ee.c.fromBufferAttribute(g,e+Q+1+s),re.a.copy(ee.b),re.b.copy(ee.c),re.c.fromBufferAttribute(g,e+Q+2+s),ce.a.fromBufferAttribute(A,e+s),ce.b.fromBufferAttribute(A,e+1+s),ce.c.fromBufferAttribute(A,e+Q+1+s),le.a.copy(ce.b),le.b.copy(ce.c),le.c.fromBufferAttribute(A,e+Q+2+s);const o=[];o[0]=null===(a=L.get(e+s))||void 0===a?void 0:a.w,o[1]=null===(u=L.get(e+1+s))||void 0===u?void 0:u.w,o[2]=null===(d=L.get(e+Q+1+s))||void 0===d?void 0:d.w,o[3]=null===(f=L.get(e+Q+2+s))||void 0===f?void 0:f.w;let n=0;for(let e=0;e<1;e+=ne)for(let s=0;s<1;s+=ne){if(he>ie)break e;if(n++,n>te)continue e;1-e>s?(C=ee.a,k=ee.b,U=ee.c,E=ce.a,F=ce.b,N=ce.c,D=o[0],I=o[1],Y=o[2]):(C=re.a,k=re.b,U=re.c,E=le.a,F=le.b,N=le.c,D=o[1],I=o[2],Y=o[3]),G.a.copy(C),G.b.copy(k),G.c.copy(U),q(G),Z.set($.x,0,$.z);const i=1.5;Z.x+=(2*Math.random()-1)*i*se,Z.z+=(2*Math.random()-1)*i*se,G.getBarycoord(Z,v).toArray(ae);if(R([D,I,Y],ae,.2)!==x-1)continue;const a=[C,k,U];S(a,ae,K),S([E,F,N],ae,V);const r=a.map((e=>e.y)),c=Math.max(...r),l=Math.min(...r);if(K.y=b(K.y,l,c),null!=w.maxSlope&&w.maxSlope<90&&V.y<X)continue;const h=K.applyMatrix4(t.matrixWorld);h.y+=T(w.offsetMin,w.offsetMax);const u=T(w.scaleMin,w.scaleMax);p.makeScale(1,1,1),p.setPosition(h),p.scale(W(u)),w.alignToNormal&&H(p,h,B.matrixWorld,V),!1!==w.randomRotation&&j(p),B.setMatrixAt(he,p),he++}}B.instanceMatrix.count=he,p.makeScale(0,0,0);for(let e=he;e<ie;e++)B.setMatrixAt(e,p);B.instanceMatrix.needsUpdate=!0,z.has(t.uuid)||null===(m=this.landscape)||void 0===m||m.attach(B),z.set(t.uuid,B)}))));performance.now()}}))}stop(){this.view.removeOnLoop(this.onLoopHandler)}update(){this.view.camera&&(this.view.camera.getWorldPosition(this._cameraPosition),this._cameraPosition.distanceTo(this._lastUpdatePosition)>10&&(this._lastUpdatePosition.copy(this._cameraPosition),this.refreshGeometry(),this.refreshScatter(this._cameraPosition)))}clear(){this.scatterMeshes.forEach((e=>e.forEach((e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.remove(e)}))))}createLandscapeMesh(e,t,s,n,i,a){const r=new o(t.sectionSize,t.sectionSize,t.density,t.density);r.rotateX(Math.PI/-2);const c=this.defaultLandscapeMaterial,l=new x(r,c);l.position.x=s+i*t.sectionSize,l.position.z=n+a*t.sectionSize,l.receiveShadow=!0,l.castShadow=!1,l.userData.landscape={x:i,y:a},l.x=i,l.y=a,l.name=`${i},${a}`;const h=e.landscape.heightMaps.find((e=>e.x===i&&e.y===a));return null!=h&&this.applyHeightMap(r,h,t.density,1),r.computeBoundsTree(),l}}function $(e,t,s){const o=Math.sqrt(t),n=Math.floor(e/o)/(o-1),i=e%o/(o-1),a=Math.sqrt(s);return(s-1)*n-(a-1)*n+(a-1)*i}new Map,new l(0,0),new l(1,0),new l(0,1),new l(1,0),new l(0,1),new l(1,1),new n;const _=new u;function C(e,t){return function(s){return _.setFromObject(s).distanceToPoint(e)>t}}function k(e,t){return function(s){return _.setFromObject(s).distanceToPoint(e)<t}}function q(e){e.a.y=0,e.b.y=0,e.c.y=0}function R(e,t,s=.5){let o=-1,n=0;for(let i=0;i<e.length;i++)if(null!=e[i])for(let a=0;a<e[i].length;a++){const r=e[i][a]*t[i];r>s&&r>n&&(n=r,o=a)}return o}function T(e,t){let s=t-e,o=Math.random();return o*=s,o+=e,o}const U=new n;function W(e){return U.set(e,e,e)}new n;const D=new n,I=new n(0,1,0),O=(new a).makeRotationX(Math.PI/-2);function H(e,t,s,o){e.lookAt(D,o,I).multiply(O)}const Y=new a;function j(e){e.multiply(Y.makeRotationY(Math.random()*Math.PI/2))}function E(e){const t=e.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.needsUpdate=!0}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,20 @@
1
+ import { Group, Mesh } from 'three';
2
+ import { NodeShaderMaterial } from "three-shader-graph";
3
+ export interface LandscapeInitOptions {
4
+ sectionSize: number;
5
+ sections: {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ density: number;
10
+ }
11
+ export declare function initLandscape(opts: LandscapeInitOptions): LandscapeGroup;
12
+ export declare function createLandscapeDefaultMaterial(): NodeShaderMaterial;
13
+ export declare const defaultLandscapeMaterial: NodeShaderMaterial;
14
+ export declare class LandscapeMesh extends Mesh {
15
+ x: number;
16
+ y: number;
17
+ }
18
+ export declare class LandscapeGroup extends Group {
19
+ get sections(): LandscapeMesh[];
20
+ }
@@ -0,0 +1,5 @@
1
+ import{Group as e,Mesh as a}from"three";import{Color as r}from"three";import{varyingAttributes as t,float as o,mod as s,dot as n,vec2 as c,step as i,fract as l,mix as p,rgb as d,NodeShaderMaterial as u,rgba as m,standardMaterial as f}from"three-shader-graph";import{mixColorsByLayer as h,select as x}from"../../shader-nodes";export function initLandscape(e){e.sections.y,e.sectionSize,e.sections.x,e.sectionSize;return new LandscapeGroup}export function createLandscapeDefaultMaterial(){const e=t.uv,a=o(10),x=o(7),L=s(n(c(1,1),i(c(.5,.5),l(e.multiplyScalar(a)))),o(2)),y=s(n(c(1,1),i(c(.5,.5),l(e.multiplyScalar(x.multiply(a))))),o(2)),M=p(d(4473924),d(5592405),L),S=p(M,M.addScalar(o(.1)),y),D=h({layerColors:[m(S).rgb(),...["#55DDE0","#33658A","#2F4858"].map((e=>d(e))).reverse()],enableNoise:!1}),g=new u({color:f({color:D})});return g.color=new r("#aaaaaa"),g}export const defaultLandscapeMaterial=createLandscapeDefaultMaterial();export class LandscapeMesh extends a{}export class LandscapeGroup extends e{get sections(){return this.children.filter((e=>e instanceof LandscapeMesh))}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,9 @@
1
+ import { Mesh } from 'three';
2
+ import { LandscapeMesh } from './landscape';
3
+ export declare function smoothNormalsCrossMeshes(meshes: LandscapeMesh[]): void;
4
+ export declare class SectionGrid {
5
+ private grid;
6
+ constructor(meshes: LandscapeMesh[]);
7
+ find(x: number, y: number): Mesh | null;
8
+ }
9
+ export declare function onEdge(i: number, count: number): boolean;
@@ -0,0 +1,5 @@
1
+ import{Vector3 as e}from"three";export function smoothNormalsCrossMeshes(t){const r=new SectionGrid(t);performance.now();const n=new e,o=new e,i=new e,s=new e;for(const e of t){const t=e.geometry.getAttribute("position"),c=e.geometry.getAttribute("normal");for(const d of f(t.count)){const{otherMesh:f,j:a}=u(d,t.count,e,r,o);if(null==f)continue;n.fromBufferAttribute(t,d),n.applyMatrix4(e.matrixWorld);const x=f.geometry.getAttribute("position"),h=f.geometry.getAttribute("normal");f.updateMatrixWorld(),o.fromBufferAttribute(x,a),o.applyMatrix4(f.matrixWorld),i.fromBufferAttribute(c,d),s.fromBufferAttribute(h,a);const l=i.add(s).divideScalar(2);c.setXYZ(d,l.x,l.y,l.z),h.setXYZ(a,l.x,l.y,l.z),c.needsUpdate=!0,h.needsUpdate=!0;const m=(t.getY(d)+x.getY(a))/2;t.setY(d,m),x.setY(a,m)}}performance.now()}export class SectionGrid{constructor(e){this.grid=new Map;for(const t of e){const{x:e,y:r}=t;this.grid.has(e)||this.grid.set(e,new Map),this.grid.get(e).set(r,t)}}find(e,t){var r;return null===(r=this.grid.get(e))||void 0===r?void 0:r.get(t)}}const t={meshPredicate:(e,t)=>e.find(t.x,t.y-1),vertexFunc:(e,t)=>e+t*(t-1)},r={meshPredicate:(e,t)=>e.find(t.x-1,t.y-1),vertexFunc:(e,t)=>t*t-1},n={meshPredicate:(e,t)=>e.find(t.x+1,t.y-1),vertexFunc:(e,t)=>t*t-t},o={meshPredicate:(e,t)=>e.find(t.x,t.y+1),vertexFunc:(e,t)=>e-t*(t-1)},i={meshPredicate:(e,t)=>e.find(t.x-1,t.y+1),vertexFunc:(e,t)=>t-1},s={meshPredicate:(e,t)=>e.find(t.x+1,t.y+1),vertexFunc:(e,t)=>0},c={meshPredicate:(e,t)=>e.find(t.x-1,t.y),vertexFunc:(e,t)=>e+t-1},d={meshPredicate:(e,t)=>e.find(t.x+1,t.y),vertexFunc:(e,t)=>e-t+1};function u(e,u,f,a,x){const h=Math.sqrt(u),l=(e+1)%h==0,m=e%h==0;let y;if(e<h?(y=t,m&&(y=r),l&&(y=n)):e>=u-h?(y=o,m?y=i:l&&(y=s)):m?y=c:l&&(y=d),null==y)return{otherMesh:null,j:null};return{otherMesh:y.meshPredicate(a,f),j:y.vertexFunc(e,h)}}function*f(e){const t=Math.sqrt(e);for(let r=0;r<t;r++)yield r,yield r+e-t;for(let e=1,r=t-1;e<r;e++)yield e*t,yield e*t+t-1}export function onEdge(e,t){const r=Math.sqrt(t);return e<r||e%r==0||e>=t-r||(e+1)%r==0}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,245 @@
1
+ import { Subject } from "rxjs";
2
+ import { Euler, Material, Object3D, Scene, Vector3 } from "three";
3
+ import { GameComponent } from "../game-component/game-component";
4
+ import { RenderingView } from "../rendering";
5
+ import { ParameterType, PropertyParameter } from "../shader/parameter";
6
+ import { ShaderImpl, ActorImpl } from '../shader/shader';
7
+ import { Type } from "../utils/type";
8
+ import { AssetResourceLoader } from './asset-resource-loader';
9
+ import { AssetsProvider } from "./assets-provider";
10
+ import { LandscapeInitOptions } from "./landscape/landscape";
11
+ import { Asset, CustomParamValue, MaterialAssignment, ShapeType } from "./model";
12
+ import { BaseActor } from '../gameplay/actors/actor';
13
+ import { ContainerInstance } from "typedi";
14
+ export type SceneObjectId = string;
15
+ export type SceneObjectType = "asset_mesh" | "light" | "shape_mesh" | "spline" | "landscape" | "particles" | "global_fog" | "global_light" | "actor" | "group" | "prefab";
16
+ export type LightType = "point" | "directional" | "ambient";
17
+ type DirectionalLightSettings = {
18
+ color: string | number;
19
+ intensity: number;
20
+ direction: number[];
21
+ castShadow: boolean;
22
+ };
23
+ type PointLightSettings = {
24
+ color: string | number;
25
+ intensity: number;
26
+ distance: number;
27
+ decay: number;
28
+ castShadow: boolean;
29
+ };
30
+ type AmbientLightSettings = {
31
+ color: string | number;
32
+ intensity: number;
33
+ };
34
+ export interface SceneObject {
35
+ id: SceneObjectId;
36
+ name?: string;
37
+ children?: SceneObject[];
38
+ assetId?: string;
39
+ shape?: ShapeType;
40
+ shapeParams?: Record<string, CustomParamValue>;
41
+ light?: {
42
+ type: 'point';
43
+ point: PointLightSettings;
44
+ } | {
45
+ type: 'directional';
46
+ directional: DirectionalLightSettings;
47
+ } | {
48
+ type: 'ambient';
49
+ ambient: AmbientLightSettings;
50
+ };
51
+ position: number[];
52
+ scale: number[];
53
+ rotation: any[];
54
+ collisionDetection: boolean;
55
+ components?: AttachedComponent[];
56
+ hidden?: boolean;
57
+ materialAssignments?: MaterialAssignment[];
58
+ vertexMaterials?: VertexMaterial[];
59
+ fog?: FogSettings;
60
+ landscape?: LandscapeData;
61
+ grass?: GrassSettings;
62
+ actor?: ActorSettings;
63
+ type: SceneObjectType;
64
+ castShadow?: boolean;
65
+ receiveShadow?: boolean;
66
+ }
67
+ export interface ActorSettings {
68
+ type: string;
69
+ params?: Record<string, CustomParamValue>;
70
+ innerParams?: {
71
+ path: string[];
72
+ params: Record<string, CustomParamValue>;
73
+ }[];
74
+ }
75
+ export interface GrassSettings {
76
+ layers: GrassLayer[];
77
+ }
78
+ export interface GrassLayer {
79
+ meshes: GrassMesh[];
80
+ }
81
+ export interface GrassMesh {
82
+ assetId: string;
83
+ viewDistance: number;
84
+ density: number;
85
+ sparseNoiseThreshold: number;
86
+ sparseNoiseScale: number;
87
+ alignToNormal: boolean;
88
+ maxSlope: number;
89
+ randomRotation: boolean;
90
+ normalsUp: boolean;
91
+ scaleMin: number;
92
+ scaleMax: number;
93
+ offsetMin: number;
94
+ offsetMax: number;
95
+ }
96
+ export type FogType = "linear" | "density";
97
+ export interface FogSettings {
98
+ type: FogType;
99
+ color: string;
100
+ near?: number;
101
+ far?: number;
102
+ density?: number;
103
+ }
104
+ export interface LandscapeData {
105
+ options: LandscapeInitOptions;
106
+ heightMaps: HeighMapSection[];
107
+ }
108
+ export interface HeighMapSection {
109
+ x: number;
110
+ y: number;
111
+ points: HeigtMapPoint[];
112
+ }
113
+ export interface HeigtMapPoint {
114
+ i: number;
115
+ y: number;
116
+ }
117
+ export interface VertexMaterial {
118
+ m?: string;
119
+ i: number;
120
+ w: number[];
121
+ }
122
+ export interface AttachedComponent {
123
+ path: string;
124
+ className: string;
125
+ name: string;
126
+ params: {
127
+ name: string;
128
+ value: any;
129
+ }[];
130
+ }
131
+ export interface SceneDataProvider {
132
+ getObjects(): SceneObject[];
133
+ onUpdate(callback: (sceneObject: SceneObject) => void): any;
134
+ onRemove(callback: (sceneObject: SceneObject) => void): any;
135
+ }
136
+ export declare const shapeDefaultColor = "#aaaaaa";
137
+ export declare class SceneMaterializerLoader {
138
+ private dataProvider;
139
+ private assetsService;
140
+ private assetManagerService;
141
+ constructor(dataProvider: SceneDataProvider, assetsService: AssetsProvider, assetManagerService: AssetResourceLoader);
142
+ get(scene: Scene, renderingView: RenderingView): SceneMaterializer;
143
+ }
144
+ export interface ActorProvider<A = BaseActor> {
145
+ create<T extends BaseActor>(type: Type<T>, position?: Vector3, rotation?: Euler, delayInit?: boolean): Promise<T>;
146
+ initActor(actor: A): Promise<void>;
147
+ }
148
+ /**
149
+ * Reads scene data and subscribes to added objects to it to update the scene with Three.js objects
150
+ */
151
+ export declare class SceneMaterializer {
152
+ private scene;
153
+ private dataProvider;
154
+ private assetsService;
155
+ private assetManagerService;
156
+ private renderingView;
157
+ private shaders;
158
+ private actorTypes;
159
+ private actorProvider;
160
+ private objectMap;
161
+ private sceneObjectMap;
162
+ private updateSubscription;
163
+ readonly components: GameComponent[];
164
+ private readonly landscapeManagers;
165
+ materializedActors: Map<string, BaseActor>;
166
+ inEditor: boolean;
167
+ updated$: Subject<{
168
+ object: Object3D;
169
+ source: SceneObject;
170
+ }>;
171
+ removed$: Subject<{
172
+ object: Object3D;
173
+ source: SceneObject;
174
+ }>;
175
+ error$: Subject<Error>;
176
+ private editorActorParamSnapshot;
177
+ private originalFog;
178
+ constructor(scene: Scene, dataProvider: SceneDataProvider, assetsService: AssetsProvider, assetManagerService: AssetResourceLoader, renderingView: RenderingView, shaders: ShaderImpl[], actorTypes: ActorImpl[], actorProvider: ActorProvider);
179
+ get actorInstances(): BaseActor[];
180
+ private prefetchAssets;
181
+ init(): Promise<void>;
182
+ /**
183
+ * Actors are initialized after first created during materialization because
184
+ * they need to exist to be able to refer to each other.
185
+ * While topolical ordering of materialization could allow referencing
186
+ * each other, it would not support circular references which
187
+ * is however possible if
188
+ * The value this added complexity brings is that it is possible
189
+ * to access another actor in the onInit method of an actor.
190
+ * This should however be discouraged as it may not be initialised,
191
+ * especially if there is a circular dependency in which case that would
192
+ * be impossible to guarantee.
193
+ */
194
+ private initActorsPostInit;
195
+ private applyActorComponentParams;
196
+ private _canBeInstancedCache;
197
+ private canAssetBeInstanced;
198
+ initWithInstancing(): Promise<void>;
199
+ private createInstancedMesh;
200
+ private remove;
201
+ private deleteSceneObject;
202
+ private findByAssetId;
203
+ private applyMaterials;
204
+ private _originalMaterials;
205
+ private applyMaterial;
206
+ private unapplyMaterials;
207
+ updateActors(actors: ActorImpl[]): void;
208
+ updateShaders(shaders: ShaderImpl[]): void;
209
+ private update;
210
+ private materializeAndInitActor;
211
+ private findParent;
212
+ private fixFogColor;
213
+ private findMeshWithGeometry;
214
+ private applyVertexMaterials;
215
+ /**
216
+ * @param source Data used to describe the object
217
+ * @param parent The object the materialized object should be spatially relative to
218
+ * @param anonymous If the object should be possible to select and edit
219
+ * @returns
220
+ */
221
+ materialize(source: SceneObject, parent?: Object3D, anonymous?: boolean): Promise<Object3D>;
222
+ private createComponent;
223
+ private createFromActor;
224
+ cleanup(): void;
225
+ private createFromShape;
226
+ private createLandscape;
227
+ private applyHeightMaps;
228
+ private createMeshByShape;
229
+ private createFromAsset;
230
+ private createFromPrefabAsset;
231
+ private createParticleSystem;
232
+ private createLight;
233
+ private applyDirectionalAmbientLight;
234
+ private applyDirectionalLight;
235
+ dispose(): void;
236
+ }
237
+ export declare function materialFromAsset(asset: Asset, renderingView: RenderingView, assetsService: AssetsProvider, assetManagerService: AssetResourceLoader, shaders: ShaderImpl[], useCache?: boolean): Promise<Material>;
238
+ export declare function prepareCustomParams<T>(propertyParams: PropertyParameter[], previous: Record<string, CustomParamValue>, defaults?: Record<string, unknown>): Record<string, CustomParamValue>;
239
+ export declare function prepareCustomParamsFromType<T>(type: Type<T>, previous: Record<string, CustomParamValue>, diContainer?: ContainerInstance): Record<string, CustomParamValue>;
240
+ /**
241
+ * Returns a serialized version of a custom parameter's value.
242
+ * Returns undefined if
243
+ */
244
+ export declare function serializeCustomParameter(type: ParameterType, value: unknown): unknown;
245
+ export {};