ris-framework 0.2.0-dev.11 → 0.2.0-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -29
- package/README.md +99 -150
- package/dist/Framework.d.ts +26 -8
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +43 -0
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +1 -1
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +5 -57
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +24 -21
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/lights/LightsBuffer.d.ts +13 -6
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
- package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
- package/dist/api/loaders/ObjLoader.d.ts +61 -0
- package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +1 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
- package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
- package/dist/api/loaders/obj/index.d.ts +1 -1
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
- package/dist/api/material/ICameraMaterial.d.ts +18 -0
- package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
- package/dist/api/material/ILightsMaterial.d.ts +26 -0
- package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +2 -8
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +2 -2
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
- package/dist/api/material/UnlitMaterial.d.ts +4 -3
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +2 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +29 -34
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +13 -8
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/Mesh.d.ts +11 -57
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +6 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +3 -5
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +95 -0
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +2 -1
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +28 -1
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +7 -0
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/renderer-interface.d.ts +1 -31
- package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
- package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
- package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
- package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +30 -21
- package/dist/api/scene/Scene.d.ts.map +1 -1
- package/dist/api/scene/SceneMesh.d.ts +27 -0
- package/dist/api/scene/SceneMesh.d.ts.map +1 -0
- package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +5 -5
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4006 -1355
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/webgl/WebGlRenderer.d.ts +1 -3
- package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
- package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
- package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
- package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
- package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
- package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
- package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
- package/dist/webgpu/WebGpuTypes.d.ts +355 -0
- package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
- package/package.json +2 -2
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
- package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
- package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
- package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
- package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
- package/shaders/wgsl/sprite.wgsl +40 -0
- package/shaders/wgsl/unlit_material.wgsl +49 -0
- package/src/Framework.ts +121 -37
- package/src/api/IFramework.ts +55 -0
- package/src/api/_export.ts +1 -1
- package/src/api/content/ContentManager.ts +46 -180
- package/src/api/content/IContentManager.ts +25 -21
- package/src/api/lights/LightsBuffer.ts +13 -6
- package/src/api/loaders/ObjGeometryMapper.ts +2 -2
- package/src/api/loaders/ObjLoader.ts +126 -0
- package/src/api/loaders/_export.ts +1 -0
- package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
- package/src/api/loaders/obj/ObjTypes.ts +19 -1
- package/src/api/loaders/obj/index.ts +1 -1
- package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
- package/src/api/material/ICameraMaterial.ts +22 -0
- package/src/api/material/ILightsMaterial.ts +32 -0
- package/src/api/material/IMaterial.ts +2 -9
- package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
- package/src/api/material/SpriteMaterial.ts +2 -2
- package/src/api/material/UnlitMaterial.ts +4 -3
- package/src/api/material/_export.ts +2 -0
- package/src/api/meshes/IMesh.ts +32 -37
- package/src/api/meshes/IMeshFactory.ts +14 -8
- package/src/api/meshes/IRenderableMesh.ts +58 -0
- package/src/api/meshes/Mesh.ts +17 -132
- package/src/api/meshes/MeshFactory.ts +14 -5
- package/src/api/meshes/QuadMesh.ts +4 -6
- package/src/api/meshes/RenderableMesh.ts +207 -0
- package/src/api/meshes/_export.ts +6 -5
- package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
- package/src/api/rendering/IRenderer.ts +34 -1
- package/src/api/rendering/enums.ts +10 -0
- package/src/api/rendering/renderer-interface.ts +1 -36
- package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
- package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
- package/src/api/rendering/texture/TextureFormat.ts +128 -14
- package/src/api/rendering/texture/TextureUtilities.ts +225 -10
- package/src/api/scene/Scene.ts +102 -69
- package/src/api/scene/SceneMesh.ts +61 -0
- package/src/api/sprites/SpriteBatchMesh.ts +1 -1
- package/src/api/utilities/AlignUtilities.ts +2 -1
- package/src/api/window/WindowManager.ts +1 -1
- package/src/core/rendering/ARenderer.ts +24 -15
- package/src/index.ts +0 -1
- package/src/main.ts +2 -3
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
- package/src/webgl/WebGlGpuInfo.ts +1 -1
- package/src/webgl/WebGlRenderer.ts +2 -5
- package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
- package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
- package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
- package/src/webgl/utilities/WebGlConstants.ts +136 -0
- package/src/webgl/utilities/WebGlConverter.ts +91 -22
- package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
- package/src/webgl/utilities/WebGlUtilities.ts +4 -0
- package/src/webgpu/WebGpuGpuInfo.ts +61 -0
- package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
- package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
- package/src/webgpu/WebGpuRenderer.ts +49 -0
- package/src/webgpu/WebGpuTypes.ts +288 -0
- package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
- package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
- package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
- package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
- package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
- package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
- package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
- package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
- package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
- package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
- package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
- package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
- package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
- package/src/webgpu/shader/WgslShaderContent.ts +20 -0
- package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
- package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
- package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
- package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
- package/src/wgsl-raw.d.ts +4 -0
- package/dist/api/FrameworkConfiguration.d.ts +0 -23
- package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/IFrameworkConfiguration.d.ts +0 -25
- package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
- package/dist/api/meshes/SubMesh.d.ts +0 -47
- package/dist/api/meshes/SubMesh.d.ts.map +0 -1
- package/src/api/FrameworkConfiguration.ts +0 -29
- package/src/api/IFrameworkConfiguration.ts +0 -30
- package/src/api/meshes/SubMesh.ts +0 -71
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type ObjColor,
|
|
4
4
|
type ObjLoadResult,
|
|
5
5
|
type ObjLoadOptions,
|
|
6
|
+
type ObjModel,
|
|
6
7
|
type ObjMaterialRange,
|
|
7
8
|
} from "./ObjTypes.ts";
|
|
8
9
|
|
|
@@ -22,10 +23,11 @@ function readColor(parts: string[]): ObjColor | undefined {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
* Engine-independent; uses only `fetch` and `URL
|
|
26
|
+
* Parses .obj models (and their .mtl materials) from text or a URL into plain data.
|
|
27
|
+
* Engine-independent; uses only `fetch` and `URL`, and creates no GPU resources.
|
|
28
|
+
* `framework.objLoader` (or the static `ObjLoader.parseAsync`) builds on it.
|
|
27
29
|
*/
|
|
28
|
-
export class
|
|
30
|
+
export class ObjParser {
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* Parses .mtl text.
|
|
@@ -260,11 +262,40 @@ export class ObjLoader {
|
|
|
260
262
|
}
|
|
261
263
|
materials.push(...this.parseMtl(await mtlResponse.text()));
|
|
262
264
|
} catch (error) {
|
|
263
|
-
console.warn(`
|
|
265
|
+
console.warn(`ObjParser: could not load material library '${library}'.`, error);
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
|
|
268
270
|
return this.fromText(text, materials);
|
|
269
271
|
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Loads an .obj file (and its .mtl files) into an {@link ObjModel}: the geometry plus one sub mesh per `usemtl`
|
|
275
|
+
* range with its resolved material definition.
|
|
276
|
+
* @param filePath The .obj URL.
|
|
277
|
+
* @param options Optional: how to resolve `mtllib` names, or skip materials.
|
|
278
|
+
* @returns The model.
|
|
279
|
+
*/
|
|
280
|
+
public async parseAsync(filePath: string, options?: ObjLoadOptions): Promise<ObjModel> {
|
|
281
|
+
return ObjParser.toModel(await this.loadAsync(filePath, options));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Turns a load result into an {@link ObjModel}.
|
|
286
|
+
* @param result The load result.
|
|
287
|
+
* @returns The model.
|
|
288
|
+
*/
|
|
289
|
+
public static toModel(result: ObjLoadResult): ObjModel {
|
|
290
|
+
const byName = new Map(result.materials.map(m => [m.name, m]));
|
|
291
|
+
return {
|
|
292
|
+
...result,
|
|
293
|
+
subMeshes: result.geometry.materialRanges.map(range => ({
|
|
294
|
+
materialName: range.materialName,
|
|
295
|
+
material: range.materialName === undefined ? undefined : byName.get(range.materialName),
|
|
296
|
+
indexStart: range.indexStart,
|
|
297
|
+
indexCount: range.indexCount,
|
|
298
|
+
})),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
270
301
|
}
|
|
@@ -111,7 +111,7 @@ export interface ObjLoadResult {
|
|
|
111
111
|
readonly raw: ObjRawData;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/** Options for {@link
|
|
114
|
+
/** Options for {@link ObjParser.loadAsync} and `ObjLoader.loadAsync`. */
|
|
115
115
|
export interface ObjLoadOptions {
|
|
116
116
|
/**
|
|
117
117
|
* Maps an `mtllib` name to the URL to fetch.
|
|
@@ -122,3 +122,21 @@ export interface ObjLoadOptions {
|
|
|
122
122
|
/** Skip fetching .mtl files. */
|
|
123
123
|
ignoreMaterials?: boolean;
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
/** One `usemtl` range of an {@link ObjModel}: its index range and resolved material definition. */
|
|
127
|
+
export interface ObjSubMesh {
|
|
128
|
+
/** The material name from `usemtl`, or undefined for faces before any `usemtl`. */
|
|
129
|
+
readonly materialName?: string;
|
|
130
|
+
/** The material definition from the .mtl files, or undefined when there is none. */
|
|
131
|
+
readonly material?: ObjMaterialDefinition;
|
|
132
|
+
/** First index in `geometry.indices`. */
|
|
133
|
+
readonly indexStart: number;
|
|
134
|
+
/** Number of indices. */
|
|
135
|
+
readonly indexCount: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A parsed OBJ model (C# `ObjModel`): geometry, sub meshes and material definitions. No GPU resources. */
|
|
139
|
+
export interface ObjModel extends ObjLoadResult {
|
|
140
|
+
/** One entry per `usemtl` range, in file order. */
|
|
141
|
+
readonly subMeshes: ObjSubMesh[];
|
|
142
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
2
2
|
import type {ITexture2D} from "../rendering/texture/ITexture2D.ts";
|
|
3
3
|
import type {ISampler} from "../rendering/sampler/ISampler.ts";
|
|
4
4
|
import {GeometryFormat} from "../geometry/GeometryFormat.ts";
|
|
@@ -11,6 +11,11 @@ import {Color} from "../data/Color.ts";
|
|
|
11
11
|
import type {IPrimitiveState} from "../rendering/primitive/IPrimitiveState.ts";
|
|
12
12
|
import type {ICamera} from "../camera/ICamera.ts";
|
|
13
13
|
import type {LightsBuffer} from "../lights/LightsBuffer.ts";
|
|
14
|
+
import type {AmbientLight} from "../lights/AmbientLight.ts";
|
|
15
|
+
import type {DirectionalLight} from "../lights/DirectionalLight.ts";
|
|
16
|
+
import type {PointLight} from "../lights/PointLight.ts";
|
|
17
|
+
import type {ICameraMaterial} from "./ICameraMaterial.ts";
|
|
18
|
+
import type {ILightsMaterial} from "./ILightsMaterial.ts";
|
|
14
19
|
import type {IForwardBlinnPhongRenderPipeline} from "../rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts";
|
|
15
20
|
|
|
16
21
|
/**
|
|
@@ -27,9 +32,6 @@ export class ForwardBlinnPhongMaterialDescriptor {
|
|
|
27
32
|
|
|
28
33
|
/** The camera position buffer. */
|
|
29
34
|
public cameraPositionBuffer!: IUniformBuffer;
|
|
30
|
-
|
|
31
|
-
/** The lights buffer. The shader is compiled for its light counts. Can also be set later through `material.lightsBuffer`. */
|
|
32
|
-
public lightsBuffer?: LightsBuffer;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
|
|
@@ -37,11 +39,17 @@ export class ForwardBlinnPhongMaterialDescriptor {
|
|
|
37
39
|
* The Blinn-Phong material with forward calculated lighting.
|
|
38
40
|
* @public
|
|
39
41
|
*/
|
|
40
|
-
export class ForwardBlinnPhongMaterial {
|
|
42
|
+
export class ForwardBlinnPhongMaterial implements ICameraMaterial, ILightsMaterial {
|
|
43
|
+
|
|
44
|
+
/** The directional light slots of the material's lights buffer and shader. */
|
|
45
|
+
public static readonly MAX_DIRECTIONAL_LIGHTS = 3;
|
|
46
|
+
|
|
47
|
+
/** The point light slots of the material's lights buffer and shader. */
|
|
48
|
+
public static readonly MAX_POINT_LIGHTS = 5;
|
|
41
49
|
|
|
42
50
|
private readonly _framework: IFramework;
|
|
43
51
|
|
|
44
|
-
private _lightsBuffer
|
|
52
|
+
private readonly _lightsBuffer: LightsBuffer;
|
|
45
53
|
private _diffuseColorCache: Color;
|
|
46
54
|
private _ambientColorCache: Color;
|
|
47
55
|
private _specularColorCache: Color;
|
|
@@ -94,7 +102,11 @@ export class ForwardBlinnPhongMaterial {
|
|
|
94
102
|
this._cameraPositionBuffer = descriptor.cameraPositionBuffer;
|
|
95
103
|
this._materialBuffer = framework.bufferFactory.createUniformBuffer(this._materialData, usage);
|
|
96
104
|
this._primitiveState = descriptor.primitiveState;
|
|
97
|
-
|
|
105
|
+
// Owned by the material, like C#: 3 directional + 5 point slots (88 floats), uploaded only when the lights changed.
|
|
106
|
+
this._lightsBuffer = framework.lightsFactory.__createLightsBuffer({
|
|
107
|
+
maxDirectionalLights: ForwardBlinnPhongMaterial.MAX_DIRECTIONAL_LIGHTS,
|
|
108
|
+
maxPointLights: ForwardBlinnPhongMaterial.MAX_POINT_LIGHTS,
|
|
109
|
+
});
|
|
98
110
|
// The pipeline is created once a model buffer is assigned (see modelBuffer).
|
|
99
111
|
}
|
|
100
112
|
|
|
@@ -105,9 +117,9 @@ export class ForwardBlinnPhongMaterial {
|
|
|
105
117
|
modelBuffer,
|
|
106
118
|
materialBuffer: this._materialBuffer,
|
|
107
119
|
cameraPositionBuffer: this._cameraPositionBuffer,
|
|
108
|
-
lightsBuffer: this._lightsBuffer
|
|
109
|
-
maxDirectionalLights: this._lightsBuffer
|
|
110
|
-
maxPointLights: this._lightsBuffer
|
|
120
|
+
lightsBuffer: this._lightsBuffer.buffer,
|
|
121
|
+
maxDirectionalLights: this._lightsBuffer.maxDirectionalLights,
|
|
122
|
+
maxPointLights: this._lightsBuffer.maxPointLights,
|
|
111
123
|
primitiveState: this._primitiveState,
|
|
112
124
|
});
|
|
113
125
|
if (this._pendingTexture) {
|
|
@@ -175,19 +187,31 @@ export class ForwardBlinnPhongMaterial {
|
|
|
175
187
|
}
|
|
176
188
|
}
|
|
177
189
|
|
|
178
|
-
/**
|
|
179
|
-
public get
|
|
180
|
-
return this._lightsBuffer;
|
|
190
|
+
/** @inheritDoc Defaults to a black ambient light; a `Scene` assigns its active ambient light. */
|
|
191
|
+
public get ambientLight(): AmbientLight {
|
|
192
|
+
return this._lightsBuffer.ambientLight;
|
|
181
193
|
}
|
|
182
194
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
public set ambientLight(value: AmbientLight) {
|
|
196
|
+
this._lightsBuffer.ambientLight = value;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @inheritDoc Only the first 3 are used. A `Scene` assigns its own list. */
|
|
200
|
+
public get directionalLights(): DirectionalLight[] {
|
|
201
|
+
return this._lightsBuffer.directionalLights;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public set directionalLights(value: DirectionalLight[]) {
|
|
205
|
+
this._lightsBuffer.directionalLights = value;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @inheritDoc Only the first 5 are used. A `Scene` assigns its own list. */
|
|
209
|
+
public get pointLights(): PointLight[] {
|
|
210
|
+
return this._lightsBuffer.pointLights;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public set pointLights(value: PointLight[]) {
|
|
214
|
+
this._lightsBuffer.pointLights = value;
|
|
191
215
|
}
|
|
192
216
|
|
|
193
217
|
/**
|
|
@@ -256,6 +280,7 @@ export class ForwardBlinnPhongMaterial {
|
|
|
256
280
|
|
|
257
281
|
/** @inheritDoc */
|
|
258
282
|
public beforeRender(): void {
|
|
283
|
+
this._lightsBuffer.update();
|
|
259
284
|
|
|
260
285
|
|
|
261
286
|
if (!this._diffuseColorCache.equals(this.diffuseColor)
|
|
@@ -281,7 +306,7 @@ export class ForwardBlinnPhongMaterial {
|
|
|
281
306
|
}
|
|
282
307
|
|
|
283
308
|
/** @inheritDoc */
|
|
284
|
-
public renderMesh(mesh:
|
|
309
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
285
310
|
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
286
311
|
}
|
|
287
312
|
|
|
@@ -298,5 +323,6 @@ export class ForwardBlinnPhongMaterial {
|
|
|
298
323
|
this._pipeline?.dispose();
|
|
299
324
|
this._pipeline = undefined;
|
|
300
325
|
this._materialBuffer.dispose();
|
|
326
|
+
this._lightsBuffer.dispose();
|
|
301
327
|
}
|
|
302
328
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IMaterial } from "./IMaterial.ts";
|
|
2
|
+
import type { ICamera } from "../camera/ICamera.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A material that renders with a camera (unlit, Blinn-Phong, inspect mips).
|
|
6
|
+
* A `Scene` assigns its camera to these materials in `scene.update()`.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ICameraMaterial extends IMaterial {
|
|
10
|
+
|
|
11
|
+
/** The camera. Setting it binds the camera's buffers. */
|
|
12
|
+
camera?: ICamera;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether a material is an {@link ICameraMaterial}.
|
|
17
|
+
* @param material The material.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export function isCameraMaterial(material: IMaterial | undefined): material is ICameraMaterial {
|
|
21
|
+
return !!material && "camera" in material;
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IMaterial } from "./IMaterial.ts";
|
|
2
|
+
import type { AmbientLight } from "../lights/AmbientLight.ts";
|
|
3
|
+
import type { DirectionalLight } from "../lights/DirectionalLight.ts";
|
|
4
|
+
import type { PointLight } from "../lights/PointLight.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A material lit by an ambient light, directional lights and point lights (Blinn-Phong).
|
|
8
|
+
* The material owns its lights buffer and uploads it only when the lights changed.
|
|
9
|
+
* A `Scene` hands each lights material its active ambient light and its own light lists (the same arrays, not copies)
|
|
10
|
+
* in `scene.update()`, so lights added to the scene reach every lit material.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface ILightsMaterial extends IMaterial {
|
|
14
|
+
|
|
15
|
+
/** The ambient light. */
|
|
16
|
+
ambientLight: AmbientLight;
|
|
17
|
+
|
|
18
|
+
/** The directional lights. The list is used by reference and may be edited; extra lights beyond the slots are ignored. */
|
|
19
|
+
directionalLights: DirectionalLight[];
|
|
20
|
+
|
|
21
|
+
/** The point lights. The list is used by reference and may be edited; extra lights beyond the slots are ignored. */
|
|
22
|
+
pointLights: PointLight[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a material is an {@link ILightsMaterial}.
|
|
27
|
+
* @param material The material.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function isLightsMaterial(material: IMaterial | undefined): material is ILightsMaterial {
|
|
31
|
+
return !!material && "directionalLights" in material && "pointLights" in material && "ambientLight" in material;
|
|
32
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { IDisposable } from "../core/IDisposable.ts";
|
|
2
2
|
import {GeometryFormat} from "../geometry/GeometryFormat.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IRenderableMesh } from "../meshes/IRenderableMesh.ts";
|
|
4
4
|
import type { IVertexBuffer } from "../rendering/buffers/IVertexBuffer.ts";
|
|
5
5
|
import type { IIndexBuffer } from "../rendering/buffers/IIndexBuffer.ts";
|
|
6
|
-
import type { ICamera } from "../camera/ICamera.ts";
|
|
7
6
|
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -12,12 +11,6 @@ import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
|
12
11
|
*/
|
|
13
12
|
export interface IMaterial extends IDisposable {
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* The camera this material renders with, for materials that use one (unlit, Blinn-Phong).
|
|
17
|
-
* A `Scene` assigns its camera to the materials of its meshes in `scene.update()`.
|
|
18
|
-
*/
|
|
19
|
-
camera?: ICamera;
|
|
20
|
-
|
|
21
14
|
/**
|
|
22
15
|
* The model buffer (std140 `mat4`) for materials that use one (unlit, Blinn-Phong, inspect mips).
|
|
23
16
|
* A mesh owns it and assigns it before drawing, like the scene assigns its camera; materials never dispose it.
|
|
@@ -37,7 +30,7 @@ export interface IMaterial extends IDisposable {
|
|
|
37
30
|
* Renders the mesh with this material, honouring the mesh's index range.
|
|
38
31
|
* @param mesh - The mesh.
|
|
39
32
|
*/
|
|
40
|
-
renderMesh(mesh:
|
|
33
|
+
renderMesh(mesh: IRenderableMesh): void;
|
|
41
34
|
|
|
42
35
|
/**
|
|
43
36
|
* Renders the material.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
2
2
|
import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
|
|
3
3
|
import type { IInspectTextureMipsRenderPipeline } from "../rendering/render-pipelines/IInspectTextureMipsRenderPipeline.ts";
|
|
4
4
|
import type { ISampler } from "../rendering/sampler/ISampler.ts";
|
|
@@ -130,7 +130,7 @@ export class InspectTextureMipsMaterial {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/** @inheritDoc */
|
|
133
|
-
public renderMesh(mesh:
|
|
133
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
134
134
|
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GeometryFormat } from "../geometry/GeometryFormat.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
3
3
|
import type { IVertexBuffer } from "../rendering/buffers/IVertexBuffer.ts";
|
|
4
4
|
import type { IIndexBuffer } from "../rendering/buffers/IIndexBuffer.ts";
|
|
5
5
|
import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
|
|
@@ -61,7 +61,7 @@ export class SpriteMaterial implements IMaterial {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** @inheritDoc */
|
|
64
|
-
public renderMesh(mesh:
|
|
64
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
65
65
|
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type {ICameraMaterial} from "./ICameraMaterial.ts";
|
|
1
2
|
|
|
2
|
-
import type {
|
|
3
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
3
4
|
import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
|
|
4
5
|
import type { ISampler } from "../rendering/sampler/ISampler.ts";
|
|
5
6
|
import {mat4} from "gl-matrix";
|
|
@@ -28,7 +29,7 @@ export class UnlitMaterialDescriptor {
|
|
|
28
29
|
/**
|
|
29
30
|
* Unlit material.
|
|
30
31
|
*/
|
|
31
|
-
export class UnlitMaterial {
|
|
32
|
+
export class UnlitMaterial implements ICameraMaterial {
|
|
32
33
|
|
|
33
34
|
private readonly _framework: IFramework;
|
|
34
35
|
private _color = Color.white();
|
|
@@ -191,7 +192,7 @@ export class UnlitMaterial {
|
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
/** @inheritDoc */
|
|
194
|
-
public renderMesh(mesh:
|
|
195
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
195
196
|
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
196
197
|
}
|
|
197
198
|
|
package/src/api/meshes/IMesh.ts
CHANGED
|
@@ -1,59 +1,54 @@
|
|
|
1
1
|
import type { IVertexBuffer } from "../rendering/buffers/IVertexBuffer.ts";
|
|
2
2
|
import type { IDisposable } from "../core/IDisposable.ts";
|
|
3
3
|
import type { IIndexBuffer } from "../rendering/buffers/IIndexBuffer.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
4
|
+
import type { IGeometry } from "../geometry/IGeometry.ts";
|
|
5
|
+
import type { GeometryFormat } from "../geometry/GeometryFormat.ts";
|
|
6
|
+
import type { State } from "../data/State.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* A mesh: geometry and the vertex and index buffers created from it.
|
|
10
|
+
* It has no material and no transform; see {@link IRenderableMesh} for a mesh that can be drawn.
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export interface IMesh extends IDisposable {
|
|
14
14
|
|
|
15
|
-
/** The
|
|
16
|
-
readonly
|
|
15
|
+
/** The state of the mesh. */
|
|
16
|
+
readonly state: State;
|
|
17
17
|
|
|
18
|
-
/** The
|
|
19
|
-
readonly
|
|
18
|
+
/** The positions, when set through `setMesh`. */
|
|
19
|
+
readonly positions?: number[];
|
|
20
20
|
|
|
21
|
-
/** The
|
|
22
|
-
|
|
21
|
+
/** The colors, when set through `setMesh`. */
|
|
22
|
+
readonly colors?: number[];
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
readonly
|
|
24
|
+
/** The texture coordinates, when set through `setMesh`. */
|
|
25
|
+
readonly textureCoords?: number[];
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
readonly
|
|
27
|
+
/** The normals, when set through `setMesh`. */
|
|
28
|
+
readonly normals?: number[];
|
|
29
29
|
|
|
30
|
-
/** The
|
|
31
|
-
readonly
|
|
30
|
+
/** The indices, when set through `setMesh`. */
|
|
31
|
+
readonly indices?: number[];
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/** The geometry the buffers were created from with `setGeometry`, if any. */
|
|
34
|
+
readonly geometry?: IGeometry;
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
* Defaults to (0, 0, 0). In-place edits are detected.
|
|
39
|
-
*/
|
|
40
|
-
rotation: vec3;
|
|
36
|
+
/** The vertex buffer, if created. */
|
|
37
|
+
readonly vertexBuffer?: IVertexBuffer;
|
|
41
38
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
39
|
+
/** The index buffer, if created. */
|
|
40
|
+
readonly indexBuffer?: IIndexBuffer;
|
|
44
41
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
*/
|
|
48
|
-
readonly modelMatrix: mat4;
|
|
42
|
+
/** Creates the buffers from the current data. */
|
|
43
|
+
initialize(): void;
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
46
|
+
* Creates the vertex and index buffers from a geometry.
|
|
47
|
+
* @param geometry The geometry.
|
|
48
|
+
* @param geometryFormat The vertex layout.
|
|
54
49
|
*/
|
|
55
|
-
|
|
50
|
+
setGeometry(geometry: IGeometry, geometryFormat?: GeometryFormat): void;
|
|
56
51
|
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
}
|
|
52
|
+
/** Re-creates (or updates) the buffers from the current data. */
|
|
53
|
+
applyChanges(): void;
|
|
54
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { GeometryFormat } from "../geometry/GeometryFormat.ts";
|
|
1
2
|
import type { IGeometry } from "../geometry/IGeometry.ts";
|
|
2
3
|
import {QuadMesh} from "./QuadMesh.ts";
|
|
3
4
|
import {vec2} from "gl-matrix";
|
|
4
5
|
import type { IMesh } from "./IMesh.ts";
|
|
5
6
|
import type { IMaterial } from "../material/IMaterial.ts";
|
|
6
|
-
import type {
|
|
7
|
+
import type { IRenderableMesh } from "./IRenderableMesh.ts";
|
|
7
8
|
|
|
8
9
|
/** Describes one submesh: a material and the index range it draws. */
|
|
9
10
|
export interface SubMeshDescriptor {
|
|
@@ -21,24 +22,29 @@ export interface SubMeshDescriptor {
|
|
|
21
22
|
export interface IMeshFactory {
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Creates a mesh
|
|
25
|
-
* @param
|
|
25
|
+
* Creates a plain mesh (buffers only, no material or transform) from a geometry.
|
|
26
|
+
* @param geometry - The geometry.
|
|
27
|
+
* @param geometryFormat - The vertex layout.
|
|
28
|
+
* @returns The mesh.
|
|
29
|
+
*/
|
|
30
|
+
createMesh(geometry: IGeometry, geometryFormat: GeometryFormat): IMesh;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a renderable mesh with one material. Add it to a scene with `scene.add(mesh)`.
|
|
26
34
|
* @param geometry - The geometry.
|
|
27
35
|
* @param material - The material.
|
|
28
36
|
* @returns The mesh.
|
|
29
37
|
*/
|
|
30
|
-
create(
|
|
38
|
+
create(geometry: IGeometry, material: IMaterial): IRenderableMesh;
|
|
31
39
|
|
|
32
40
|
/**
|
|
33
41
|
* Creates a mesh made of submeshes that share one vertex and one index buffer.
|
|
34
|
-
* The mesh
|
|
35
|
-
* Only the mesh is added to the scene, not the submeshes.
|
|
36
|
-
* @param scene - The scene the mesh adds itself to.
|
|
42
|
+
* The root mesh has no material; `mesh.render()` draws its submeshes. Add the root to a scene with `scene.add(mesh)`.
|
|
37
43
|
* @param geometry - The geometry.
|
|
38
44
|
* @param subMeshes - One entry per submesh. All materials must use the same geometry format.
|
|
39
45
|
* @returns The mesh.
|
|
40
46
|
*/
|
|
41
|
-
createWithSubMeshes(
|
|
47
|
+
createWithSubMeshes(geometry: IGeometry, subMeshes: SubMeshDescriptor[]): IRenderableMesh;
|
|
42
48
|
|
|
43
49
|
/**
|
|
44
50
|
* Creates the quad mesh.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { mat4, vec3 } from "gl-matrix";
|
|
2
|
+
import type { IMesh } from "./IMesh.ts";
|
|
3
|
+
import type { IMaterial } from "../material/IMaterial.ts";
|
|
4
|
+
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A mesh that can be drawn: a mesh plus an optional material, an index range and sub meshes.
|
|
8
|
+
*
|
|
9
|
+
* - A root mesh owns the vertex and index buffers. Sub meshes share them and only store their index range.
|
|
10
|
+
* - Rendering: a mesh with a material draws its range, then its sub meshes draw theirs.
|
|
11
|
+
* A root without a material only draws its sub meshes.
|
|
12
|
+
* - The transform (position, rotation, scale) and the model buffer live on the root and are shared by all sub meshes,
|
|
13
|
+
* so a mesh uploads its model matrix once per change, whatever the number of materials.
|
|
14
|
+
* - Disposing the root disposes the sub meshes and the buffers once. Materials are not disposed by the mesh
|
|
15
|
+
* (a `SceneMesh` does that).
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface IRenderableMesh extends IMesh {
|
|
19
|
+
|
|
20
|
+
/** The material, if any. A root mesh made only of sub meshes has none. */
|
|
21
|
+
material?: IMaterial;
|
|
22
|
+
|
|
23
|
+
/** The parent for a sub mesh; undefined for a root mesh. */
|
|
24
|
+
readonly parent?: IRenderableMesh;
|
|
25
|
+
|
|
26
|
+
/** The sub meshes. */
|
|
27
|
+
readonly subMeshes: readonly IRenderableMesh[];
|
|
28
|
+
|
|
29
|
+
/** First index of the range to draw. Defaults to 0. */
|
|
30
|
+
readonly indexStart: number;
|
|
31
|
+
|
|
32
|
+
/** Number of indices to draw; -1 (the default) draws all indices. */
|
|
33
|
+
readonly indexCount: number;
|
|
34
|
+
|
|
35
|
+
/** World position. Defaults to the origin. In-place edits are detected. A sub mesh uses the root's. */
|
|
36
|
+
position: vec3;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Euler rotation in radians, applied in Y, X, Z order (yaw, pitch, roll): `R = Ry * Rx * Rz`.
|
|
40
|
+
* Defaults to (0, 0, 0). In-place edits are detected. A sub mesh uses the root's.
|
|
41
|
+
*/
|
|
42
|
+
rotation: vec3;
|
|
43
|
+
|
|
44
|
+
/** Scale. Defaults to (1, 1, 1). In-place edits are detected. A sub mesh uses the root's. */
|
|
45
|
+
scale: vec3;
|
|
46
|
+
|
|
47
|
+
/** The model matrix `T * R * S`, recomputed only when position, rotation or scale changed. */
|
|
48
|
+
readonly modelMatrix: mat4;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The model buffer (std140 `mat4`) holding {@link modelMatrix}. Owned by the root mesh (sub meshes share it),
|
|
52
|
+
* uploaded when the transform changed and assigned to the material(s) before drawing. Created on first use.
|
|
53
|
+
*/
|
|
54
|
+
readonly modelBuffer: IUniformBuffer;
|
|
55
|
+
|
|
56
|
+
/** Draws the mesh's range with its material (if any), then the sub meshes. */
|
|
57
|
+
render(): void;
|
|
58
|
+
}
|