chorama 0.0.0
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/.configs/tsconfig.lib.json +43 -0
- package/.configs/tsconfig.website.json +34 -0
- package/.github/workflows/static.yml +88 -0
- package/.vscode/launch.json +29 -0
- package/.vscode/tasks.json +19 -0
- package/README.md +127 -0
- package/assets/images/disappointed.jpg +0 -0
- package/assets/images/skybox/grimmnight_back.png +0 -0
- package/assets/images/skybox/grimmnight_bottom.png +0 -0
- package/assets/images/skybox/grimmnight_front.png +0 -0
- package/assets/images/skybox/grimmnight_left.png +0 -0
- package/assets/images/skybox/grimmnight_right.png +0 -0
- package/assets/images/skybox/grimmnight_top.png +0 -0
- package/assets/images/skybox/miramar_back.png +0 -0
- package/assets/images/skybox/miramar_bottom.png +0 -0
- package/assets/images/skybox/miramar_front.png +0 -0
- package/assets/images/skybox/miramar_left.png +0 -0
- package/assets/images/skybox/miramar_right.png +0 -0
- package/assets/images/skybox/miramar_top.png +0 -0
- package/assets/images/uv.jpg +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/index.bin +0 -0
- package/assets/models/gltf/flight_helmet/index.gltf +705 -0
- package/assets/models/gltf/object.gltf +23 -0
- package/assets/models/gltf/pirate_girl/index.bin +0 -0
- package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
- package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
- package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
- package/astro.config.mjs +45 -0
- package/content/guide/api-map.md +89 -0
- package/content/guide/camera-and-controls.md +98 -0
- package/content/guide/first-scene.md +176 -0
- package/content/guide/index.md +72 -0
- package/content/guide/installation.md +179 -0
- package/content/guide/materials-and-lighting.md +138 -0
- package/content/guide/plugins-and-render-pipeline.md +124 -0
- package/content/guide/render-targets-and-views.md +147 -0
- package/content/guide/scene-graph-and-transforms.md +113 -0
- package/content/guide/textures-and-assets.md +120 -0
- package/content/guide/troubleshooting.md +49 -0
- package/env.d.ts +19 -0
- package/examples/addons/rendergraph_gui.js +580 -0
- package/examples/camera/orthographic.js +120 -0
- package/examples/camera/perspective.js +138 -0
- package/examples/lights/directional.js +397 -0
- package/examples/lights/multiple_spot_lights.js +304 -0
- package/examples/lights/point.js +337 -0
- package/examples/lights/spot.js +366 -0
- package/examples/loader/gltf_material.js +111 -0
- package/examples/loader/gltfloader.js +78 -0
- package/examples/loader/objloader.js +95 -0
- package/examples/material/cullface.js +111 -0
- package/examples/material/materials.js +126 -0
- package/examples/material/standard/basic.js +164 -0
- package/examples/mesh/circle.js +117 -0
- package/examples/mesh/cuboid.js +151 -0
- package/examples/mesh/cylinder.js +139 -0
- package/examples/mesh/geometries.js +108 -0
- package/examples/mesh/meshTopology.js +103 -0
- package/examples/mesh/plane.js +117 -0
- package/examples/mesh/skinning.js +136 -0
- package/examples/mesh/uvsphere.js +113 -0
- package/examples/other/rotatingCube.js +93 -0
- package/examples/other/rotatingSphere.js +96 -0
- package/examples/rendertarget/basic_canvas.js +130 -0
- package/examples/rendertarget/depth_texture.js +130 -0
- package/examples/rendertarget/image_target.js +140 -0
- package/examples/rendertarget/multiple_views.js +158 -0
- package/examples/rendertarget/render_masks.js +173 -0
- package/examples/rendertarget/split_screen.js +123 -0
- package/examples/rendertarget/split_view.js +137 -0
- package/examples/skybox/skybox.js +111 -0
- package/examples/texture/arrays.js +156 -0
- package/examples/texture/textureWrap.js +118 -0
- package/examples/transform/propagation.js +92 -0
- package/package.json +55 -0
- package/rollup.config.js +66 -0
- package/scripts/stage-chorama.mjs +29 -0
- package/src/caches/cache.js +420 -0
- package/src/caches/index.js +2 -0
- package/src/caches/uniformbuffers.js +104 -0
- package/src/cameracontrols/index.js +258 -0
- package/src/constants/index.js +3 -0
- package/src/constants/mesh.js +197 -0
- package/src/constants/others.js +218 -0
- package/src/constants/texture.js +183 -0
- package/src/core/constants.js +14 -0
- package/src/core/extensions.js +42 -0
- package/src/core/index.js +7 -0
- package/src/core/layouts/index.js +4 -0
- package/src/core/layouts/meshvertex.js +60 -0
- package/src/core/layouts/uniform.js +21 -0
- package/src/core/layouts/uniformbuffer.js +15 -0
- package/src/core/layouts/vertexbuffer.js +43 -0
- package/src/core/limits.js +247 -0
- package/src/core/resources/blendparams.js +89 -0
- package/src/core/resources/framebuffer.js +127 -0
- package/src/core/resources/gpubuffer.js +32 -0
- package/src/core/resources/gpumesh.js +43 -0
- package/src/core/resources/gputexture.js +73 -0
- package/src/core/resources/index.js +5 -0
- package/src/core/shader.js +62 -0
- package/src/core/webgl/bindgroup.js +89 -0
- package/src/core/webgl/descriptors.js +104 -0
- package/src/core/webgl/index.js +5 -0
- package/src/core/webgl/renderpassencoder.js +96 -0
- package/src/core/webgl/renderpipeline.js +54 -0
- package/src/core/webgl/utils.js +371 -0
- package/src/core/webgl/webglrenderdevice.js +235 -0
- package/src/function.js +358 -0
- package/src/index.js +15 -0
- package/src/loader/gltf.js +2172 -0
- package/src/loader/index.js +3 -0
- package/src/loader/loader.js +174 -0
- package/src/loader/obj.js +188 -0
- package/src/loader/texture.js +85 -0
- package/src/loader/utils.js +16 -0
- package/src/material/basic.js +75 -0
- package/src/material/depth.js +73 -0
- package/src/material/index.js +8 -0
- package/src/material/lambert.js +73 -0
- package/src/material/material.js +106 -0
- package/src/material/normal.js +30 -0
- package/src/material/phong.js +86 -0
- package/src/material/raw.js +52 -0
- package/src/material/standard.js +221 -0
- package/src/math/index.js +3 -0
- package/src/math/transform.js +38 -0
- package/src/mesh/attribute/attribute.js +79 -0
- package/src/mesh/attribute/index.js +1 -0
- package/src/mesh/attributedata/index.js +1 -0
- package/src/mesh/attributedata/separate.js +180 -0
- package/src/mesh/builders/base.js +41 -0
- package/src/mesh/builders/circle.js +63 -0
- package/src/mesh/builders/cuboid.js +135 -0
- package/src/mesh/builders/cylinder.js +131 -0
- package/src/mesh/builders/index.js +7 -0
- package/src/mesh/builders/plane.js +73 -0
- package/src/mesh/builders/utils.js +20 -0
- package/src/mesh/builders/uvsphere.js +80 -0
- package/src/mesh/builders/wireframe.js +62 -0
- package/src/mesh/index.js +4 -0
- package/src/mesh/mesh.js +149 -0
- package/src/objects/bone.js +17 -0
- package/src/objects/camera/camera.js +56 -0
- package/src/objects/camera/index.js +2 -0
- package/src/objects/camera/projection.js +203 -0
- package/src/objects/debug/index.js +1 -0
- package/src/objects/debug/skeleton.js +28 -0
- package/src/objects/index.js +7 -0
- package/src/objects/light/ambient.js +20 -0
- package/src/objects/light/directional.js +29 -0
- package/src/objects/light/index.js +5 -0
- package/src/objects/light/point.js +32 -0
- package/src/objects/light/shadow/index.js +1 -0
- package/src/objects/light/shadow/shadow.js +67 -0
- package/src/objects/light/spot.js +56 -0
- package/src/objects/mesh.js +141 -0
- package/src/objects/object3d.js +167 -0
- package/src/objects/skybox.js +38 -0
- package/src/plugins/camera/camera.js +19 -0
- package/src/plugins/camera/index.js +2 -0
- package/src/plugins/camera/nodes/cameraview.js +46 -0
- package/src/plugins/camera/nodes/index.js +2 -0
- package/src/plugins/camera/nodes/opaquepass.js +79 -0
- package/src/plugins/index.js +6 -0
- package/src/plugins/light/index.js +2 -0
- package/src/plugins/light/light.js +23 -0
- package/src/plugins/light/nodes/index.js +1 -0
- package/src/plugins/light/nodes/light.js +127 -0
- package/src/plugins/meshmaterial/index.js +3 -0
- package/src/plugins/meshmaterial/meshmaterial.js +381 -0
- package/src/plugins/meshmaterial/nodes/index.js +1 -0
- package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
- package/src/plugins/meshmaterial/resources/index.js +1 -0
- package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
- package/src/plugins/shadow/index.js +3 -0
- package/src/plugins/shadow/nodes/index.js +3 -0
- package/src/plugins/shadow/nodes/shadow.js +272 -0
- package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
- package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
- package/src/plugins/shadow/resources/ShadowMap.js +99 -0
- package/src/plugins/shadow/resources/index.js +2 -0
- package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
- package/src/plugins/shadow/shadow.js +31 -0
- package/src/plugins/skeletonhelper/index.js +1 -0
- package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
- package/src/plugins/skybox/index.js +3 -0
- package/src/plugins/skybox/nodes/index.js +1 -0
- package/src/plugins/skybox/nodes/skybox.js +143 -0
- package/src/plugins/skybox/resources/index.js +2 -0
- package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
- package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
- package/src/plugins/skybox/skybox.js +137 -0
- package/src/renderer/core/index.js +179 -0
- package/src/renderer/graph/index.js +3 -0
- package/src/renderer/graph/nodes.js +34 -0
- package/src/renderer/graph/rendergraph.js +182 -0
- package/src/renderer/index.js +5 -0
- package/src/renderer/plugin.js +36 -0
- package/src/renderer/renderer.js +179 -0
- package/src/renderer/views.js +28 -0
- package/src/rendertarget/canvastarget.js +30 -0
- package/src/rendertarget/image.js +132 -0
- package/src/rendertarget/index.js +3 -0
- package/src/rendertarget/rendertarget.js +89 -0
- package/src/shader/basicFragment.glsl +30 -0
- package/src/shader/basicVertex.glsl +87 -0
- package/src/shader/common/color.glsl +7 -0
- package/src/shader/common/common.glsl +25 -0
- package/src/shader/common/index.js +4 -0
- package/src/shader/common/light.glsl +437 -0
- package/src/shader/common/math.glsl +12 -0
- package/src/shader/debug/index.js +2 -0
- package/src/shader/debug/skeletonFragment.glsl +8 -0
- package/src/shader/debug/skeletonVertex.glsl +27 -0
- package/src/shader/depthFragment.glsl +37 -0
- package/src/shader/index.js +11 -0
- package/src/shader/lambertFragment.glsl +126 -0
- package/src/shader/normalFragment.glsl +25 -0
- package/src/shader/phongFragment.glsl +140 -0
- package/src/shader/skyboxFragment.glsl +16 -0
- package/src/shader/skyboxVertex.glsl +20 -0
- package/src/shader/standardFragment.glsl +274 -0
- package/src/texture/index.js +2 -0
- package/src/texture/sampler.js +111 -0
- package/src/texture/texture.js +234 -0
- package/src/utils/index.js +115 -0
- package/tsconfig.json +11 -0
- package/website/config/index.ts +1 -0
- package/website/config/navigation.ts +53 -0
- package/website/content.config.ts +92 -0
- package/website/layouts/DocLayout.astro +501 -0
- package/website/layouts/Example.astro +91 -0
- package/website/pages/examples/[...slug].astro +77 -0
- package/website/pages/examples/index.astro +98 -0
- package/website/pages/examples/samples/[...slug].astro +17 -0
- package/website/pages/guide/[slug].astro +30 -0
- package/website/pages/guide/index.astro +21 -0
- package/website/pages/index.astro +9 -0
- package/website/plugins/remark-link-base.js +23 -0
- package/website/utils/url.ts +30 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**@import {WebGLRenderPipelineOptions } from '../core/index.js' */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CullFace,
|
|
5
|
+
FrontFaceDirection
|
|
6
|
+
} from "../constants/index.js"
|
|
7
|
+
import { abstractClass, abstractMethod } from "../utils/index.js"
|
|
8
|
+
import { RawMaterial } from "./raw.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @abstract
|
|
12
|
+
*/
|
|
13
|
+
export class Material extends RawMaterial {
|
|
14
|
+
/**
|
|
15
|
+
* @type {FrontFaceDirection}
|
|
16
|
+
*/
|
|
17
|
+
frontFace = FrontFaceDirection.CCW
|
|
18
|
+
/**
|
|
19
|
+
* @type {CullFace}
|
|
20
|
+
*/
|
|
21
|
+
cullFace = CullFace.Back
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
*/
|
|
26
|
+
depthWrite = true
|
|
27
|
+
|
|
28
|
+
constructor(){
|
|
29
|
+
super()
|
|
30
|
+
abstractClass(this, Material)
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @override
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
vertex() {
|
|
37
|
+
abstractMethod(this, Material, Material.prototype.vertex.name)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @override
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
fragment() {
|
|
45
|
+
abstractMethod(this, Material, Material.prototype.fragment.name)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @override
|
|
50
|
+
* @returns {ArrayBuffer}
|
|
51
|
+
*/
|
|
52
|
+
getData() {
|
|
53
|
+
if (this.constructor === RawMaterial) {
|
|
54
|
+
throw `\`${RawMaterial.name}\` cannot be used directly as a material.`
|
|
55
|
+
}
|
|
56
|
+
throw `Implement \`${this.constructor.name}.uploadUniforms()\``
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @override
|
|
61
|
+
* @returns {bigint}
|
|
62
|
+
*/
|
|
63
|
+
getPipelineBits() {
|
|
64
|
+
let materialKey = MaterialKey.None
|
|
65
|
+
if (this.cullFace === CullFace.Front) {
|
|
66
|
+
materialKey |= MaterialKey.CullFaceFront
|
|
67
|
+
} else if (this.cullFace === CullFace.Back) {
|
|
68
|
+
materialKey |= MaterialKey.CullFaceBack
|
|
69
|
+
} else if (this.cullFace === CullFace.FrontAndBack) {
|
|
70
|
+
materialKey |= MaterialKey.CullFaceBoth
|
|
71
|
+
}
|
|
72
|
+
if (this.depthWrite) {
|
|
73
|
+
materialKey |= MaterialKey.DepthWrite
|
|
74
|
+
}
|
|
75
|
+
if (this.frontFace == FrontFaceDirection.CW) {
|
|
76
|
+
materialKey |= MaterialKey.FrontFaceCW
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return materialKey
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @override
|
|
84
|
+
* @param {WebGLRenderPipelineOptions} descriptor
|
|
85
|
+
*/
|
|
86
|
+
specialize(descriptor) {
|
|
87
|
+
// TODO: Incorporate blending to the pipeline key
|
|
88
|
+
|
|
89
|
+
descriptor.cullFace = this.cullFace
|
|
90
|
+
descriptor.frontFace = this.frontFace
|
|
91
|
+
descriptor.depthWrite = this.depthWrite
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @enum {bigint}
|
|
97
|
+
*/
|
|
98
|
+
export const MaterialKey = /**@type {const}*/({
|
|
99
|
+
None: 0n,
|
|
100
|
+
CullFaceNone: 0n << 0n,
|
|
101
|
+
CullFaceFront: 1n << 0n,
|
|
102
|
+
CullFaceBack: 2n << 0n,
|
|
103
|
+
CullFaceBoth: 3n << 0n,
|
|
104
|
+
FrontFaceCW: 1n << 2n,
|
|
105
|
+
DepthWrite: 1n << 3n
|
|
106
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Material } from "./material.js"
|
|
2
|
+
import { basicVertex, normalFragment} from "../shader/index.js"
|
|
3
|
+
|
|
4
|
+
export class NormalMaterial extends Material {
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @override
|
|
12
|
+
*/
|
|
13
|
+
vertex() {
|
|
14
|
+
return basicVertex
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
fragment() {
|
|
21
|
+
return normalFragment
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @override
|
|
26
|
+
*/
|
|
27
|
+
getData() {
|
|
28
|
+
return new Float32Array([]).buffer
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Material } from "./material.js"
|
|
2
|
+
import { Color } from "../math/index.js"
|
|
3
|
+
import { basicVertex, phongFragment } from "../shader/index.js"
|
|
4
|
+
import { Sampler, Texture } from "../texture/index.js"
|
|
5
|
+
|
|
6
|
+
export class PhongMaterial extends Material {
|
|
7
|
+
/**
|
|
8
|
+
* @type {Color}
|
|
9
|
+
*/
|
|
10
|
+
color
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {Texture | undefined}
|
|
14
|
+
*/
|
|
15
|
+
mainTexture
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {Sampler | undefined}
|
|
19
|
+
*/
|
|
20
|
+
mainSampler
|
|
21
|
+
/**
|
|
22
|
+
* @param {PhongMaterialOptions} param0
|
|
23
|
+
*/
|
|
24
|
+
constructor({
|
|
25
|
+
color = new Color(1, 1, 1),
|
|
26
|
+
mainTexture = undefined,
|
|
27
|
+
mainSampler = undefined,
|
|
28
|
+
specularStrength = 0.5,
|
|
29
|
+
specularShininess = 32,
|
|
30
|
+
} = {}) {
|
|
31
|
+
super()
|
|
32
|
+
this.color = color
|
|
33
|
+
this.mainTexture = mainTexture
|
|
34
|
+
this.mainSampler = mainSampler
|
|
35
|
+
this.specularStrength = specularStrength
|
|
36
|
+
this.specularShininess = specularShininess
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
vertex() {
|
|
43
|
+
return basicVertex
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @override
|
|
48
|
+
*/
|
|
49
|
+
fragment() {
|
|
50
|
+
return phongFragment
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @override
|
|
55
|
+
*/
|
|
56
|
+
getData() {
|
|
57
|
+
const {
|
|
58
|
+
color,
|
|
59
|
+
specularShininess,
|
|
60
|
+
specularStrength
|
|
61
|
+
} = this
|
|
62
|
+
|
|
63
|
+
return new Float32Array([
|
|
64
|
+
...color,
|
|
65
|
+
specularShininess,
|
|
66
|
+
specularStrength
|
|
67
|
+
]).buffer
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @returns {[string, number, Texture | undefined, Sampler | undefined][]}
|
|
72
|
+
* @override
|
|
73
|
+
*/
|
|
74
|
+
getTextures() {
|
|
75
|
+
return [['mainTexture', 0, this.mainTexture, this.mainSampler]]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @typedef PhongMaterialOptions
|
|
81
|
+
* @property {Color} [color]
|
|
82
|
+
* @property {Texture} [mainTexture]
|
|
83
|
+
* @property {Sampler} [mainSampler]
|
|
84
|
+
* @property {number} [specularShininess]
|
|
85
|
+
* @property {number} [specularStrength]
|
|
86
|
+
*/
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**@import { WebGLRenderPipelineOptions } from '../core/index.js' */
|
|
2
|
+
import { Sampler, Texture } from "../texture/index.js"
|
|
3
|
+
import { abstractClass, abstractMethod } from "../utils/index.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @abstract
|
|
7
|
+
*/
|
|
8
|
+
export class RawMaterial {
|
|
9
|
+
|
|
10
|
+
constructor(){
|
|
11
|
+
abstractClass(this, RawMaterial)
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
vertex() {
|
|
17
|
+
abstractMethod(this, RawMaterial, RawMaterial.prototype.vertex.name)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
fragment() {
|
|
24
|
+
abstractMethod(this, RawMaterial, RawMaterial.prototype.fragment.name)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns {ArrayBuffer}
|
|
29
|
+
*/
|
|
30
|
+
getData() {
|
|
31
|
+
abstractMethod(this, RawMaterial, RawMaterial.prototype.getData.name)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @returns {[string, number, Texture | undefined, Sampler | undefined][]}
|
|
36
|
+
*/
|
|
37
|
+
getTextures(){
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns {bigint}
|
|
43
|
+
*/
|
|
44
|
+
getPipelineBits() {
|
|
45
|
+
return 0n
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {WebGLRenderPipelineOptions} _descriptor
|
|
50
|
+
*/
|
|
51
|
+
specialize(_descriptor) { }
|
|
52
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { Color } from "../math/index.js";
|
|
2
|
+
import { basicVertex, standardFragment } from "../shader/index.js";
|
|
3
|
+
import { Sampler, Texture } from "../texture/index.js";
|
|
4
|
+
import { Material } from "./material.js";
|
|
5
|
+
|
|
6
|
+
export class StandardMaterial extends Material {
|
|
7
|
+
/**
|
|
8
|
+
* @type {Color}
|
|
9
|
+
*/
|
|
10
|
+
color
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {Texture | undefined}
|
|
14
|
+
*/
|
|
15
|
+
mainTexture
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {Sampler | undefined}
|
|
19
|
+
*/
|
|
20
|
+
mainSampler
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type {Texture | undefined}
|
|
24
|
+
*/
|
|
25
|
+
normalTexture
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @type {Sampler | undefined}
|
|
29
|
+
*/
|
|
30
|
+
normalSampler
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @type {number}
|
|
34
|
+
*/
|
|
35
|
+
metallic
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @type {Texture | undefined}
|
|
39
|
+
*/
|
|
40
|
+
metallicTexture
|
|
41
|
+
/**
|
|
42
|
+
* @type {Sampler | undefined}
|
|
43
|
+
*/
|
|
44
|
+
metallicSampler
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
roughness
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @type {Texture | undefined}
|
|
53
|
+
*/
|
|
54
|
+
roughnessTexture
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @type {Sampler | undefined}
|
|
58
|
+
*/
|
|
59
|
+
roughnessSampler
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @type {number}
|
|
63
|
+
*/
|
|
64
|
+
occlusionStrength
|
|
65
|
+
/**
|
|
66
|
+
* @type {Texture | undefined}
|
|
67
|
+
*/
|
|
68
|
+
occlusionTexture
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @type {Sampler | undefined}
|
|
72
|
+
*/
|
|
73
|
+
occlusionSampler
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @type {Color}
|
|
77
|
+
*/
|
|
78
|
+
emissiveColor
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @type {number}
|
|
82
|
+
*/
|
|
83
|
+
emissiveIntensity
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @type {Texture | undefined}
|
|
87
|
+
*/
|
|
88
|
+
emissiveTexture
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @type {Sampler | undefined}
|
|
92
|
+
*/
|
|
93
|
+
emissiveSampler
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {StandardMaterialOptions} param0
|
|
97
|
+
*/
|
|
98
|
+
constructor({
|
|
99
|
+
color = new Color(1, 1, 1),
|
|
100
|
+
mainTexture,
|
|
101
|
+
mainSampler,
|
|
102
|
+
normalTexture,
|
|
103
|
+
normalSampler,
|
|
104
|
+
metallic = 1,
|
|
105
|
+
metallicTexture,
|
|
106
|
+
metallicSampler,
|
|
107
|
+
roughness = 0,
|
|
108
|
+
roughnessTexture,
|
|
109
|
+
roughnessSampler,
|
|
110
|
+
occlusionStrength = 1,
|
|
111
|
+
occlusionTexture,
|
|
112
|
+
occlusionSampler,
|
|
113
|
+
emissiveColor = new Color(0, 0, 0),
|
|
114
|
+
emissiveIntensity = 1,
|
|
115
|
+
emissiveTexture,
|
|
116
|
+
emissiveSampler
|
|
117
|
+
} = {}) {
|
|
118
|
+
super()
|
|
119
|
+
this.color = color;
|
|
120
|
+
this.mainTexture = mainTexture;
|
|
121
|
+
this.mainSampler = mainSampler;
|
|
122
|
+
|
|
123
|
+
this.normalTexture = normalTexture;
|
|
124
|
+
this.normalSampler = normalSampler;
|
|
125
|
+
|
|
126
|
+
this.metallic = metallic;
|
|
127
|
+
this.metallicTexture = metallicTexture;
|
|
128
|
+
this.metallicSampler = metallicSampler;
|
|
129
|
+
|
|
130
|
+
this.roughness = roughness;
|
|
131
|
+
this.roughnessTexture = roughnessTexture;
|
|
132
|
+
this.roughnessSampler = roughnessSampler;
|
|
133
|
+
|
|
134
|
+
this.occlusionStrength = occlusionStrength
|
|
135
|
+
this.occlusionTexture = occlusionTexture;
|
|
136
|
+
this.occlusionSampler = occlusionSampler;
|
|
137
|
+
|
|
138
|
+
this.emissiveColor = emissiveColor;
|
|
139
|
+
this.emissiveIntensity = emissiveIntensity;
|
|
140
|
+
this.emissiveTexture = emissiveTexture;
|
|
141
|
+
this.emissiveSampler = emissiveSampler;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @override
|
|
146
|
+
*/
|
|
147
|
+
vertex() {
|
|
148
|
+
return basicVertex
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @override
|
|
153
|
+
*/
|
|
154
|
+
fragment() {
|
|
155
|
+
return standardFragment
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @override
|
|
160
|
+
*/
|
|
161
|
+
getData() {
|
|
162
|
+
const {
|
|
163
|
+
color,
|
|
164
|
+
metallic,
|
|
165
|
+
roughness,
|
|
166
|
+
occlusionStrength,
|
|
167
|
+
emissiveColor,
|
|
168
|
+
emissiveIntensity
|
|
169
|
+
} = this
|
|
170
|
+
|
|
171
|
+
return new Float32Array([
|
|
172
|
+
...color,
|
|
173
|
+
metallic,
|
|
174
|
+
roughness,
|
|
175
|
+
occlusionStrength,
|
|
176
|
+
0,
|
|
177
|
+
emissiveColor.r,
|
|
178
|
+
emissiveColor.g,
|
|
179
|
+
emissiveColor.b,
|
|
180
|
+
emissiveIntensity
|
|
181
|
+
]).buffer
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @override
|
|
186
|
+
* @returns {[string, number, Texture | undefined, Sampler | undefined][]}
|
|
187
|
+
*/
|
|
188
|
+
getTextures() {
|
|
189
|
+
return [
|
|
190
|
+
['mainTexture', 0, this.mainTexture, this.mainSampler],
|
|
191
|
+
['normal_texture', 0, this.normalTexture, this.normalSampler],
|
|
192
|
+
['metallic_texture', 0, this.metallicTexture, this.metallicSampler],
|
|
193
|
+
['roughness_texture', 0, this.roughnessTexture, this.roughnessSampler],
|
|
194
|
+
['occlusion_texture', 0, this.occlusionTexture, this.occlusionSampler],
|
|
195
|
+
['emissive_texture', 0, this.emissiveTexture, this.emissiveSampler]
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @typedef StandardMaterialOptions
|
|
203
|
+
* @property {Color} [color] The base color of the material.
|
|
204
|
+
* @property {Texture} [mainTexture] The color texture applied to the material.
|
|
205
|
+
* @property {Sampler} [mainSampler] The sampler for the color texture.
|
|
206
|
+
* @property {Texture} [normalTexture] The texture used for normal mapping to simulate surface detail.
|
|
207
|
+
* @property {Sampler} [normalSampler] The sampler for the normal map.
|
|
208
|
+
* @property {number} [metallic] The metallic value of the material, typically between 0 and 1.
|
|
209
|
+
* @property {Texture} [metallicTexture] A texture representing metallic values, typically a grayscale image.
|
|
210
|
+
* @property {Sampler} [metallicSampler] The sampler for the metallic texture.
|
|
211
|
+
* @property {number} [roughness] The roughness value of the material, typically between 0 and 1.
|
|
212
|
+
* @property {Texture} [roughnessTexture] A texture representing the roughness values, typically a grayscale image.
|
|
213
|
+
* @property {Sampler} [roughnessSampler] The sampler for the roughness texture.
|
|
214
|
+
* @property {number} [occlusionStrength] The strength of the ambient occlusion.
|
|
215
|
+
* @property {Texture} [occlusionTexture] A texture used for ambient occlusion to simulate shadowing of surfaces.
|
|
216
|
+
* @property {Sampler} [occlusionSampler] The sampler for the ambient occlusion texture.
|
|
217
|
+
* @property {Color} [emissiveColor] The color of emissive light emitted by the material.
|
|
218
|
+
* @property {number} [emissiveIntensity] The intensity of the emissive color.
|
|
219
|
+
* @property {Texture} [emissiveTexture] A texture representing the emissive map.
|
|
220
|
+
* @property {Sampler} [emissiveSampler] The sampler for the emissive texture.
|
|
221
|
+
*/
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Vector3, Quaternion, Affine3 } from "hisabati"
|
|
2
|
+
|
|
3
|
+
export class Transform3D {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.world = new Affine3()
|
|
6
|
+
this.position = new Vector3()
|
|
7
|
+
this.orientation = new Quaternion()
|
|
8
|
+
this.scale = new Vector3(1, 1, 1)
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param {Transform3D} [parent]
|
|
12
|
+
*/
|
|
13
|
+
updateMatrix(parent) {
|
|
14
|
+
this.world.compose(
|
|
15
|
+
this.position,
|
|
16
|
+
this.orientation,
|
|
17
|
+
this.scale
|
|
18
|
+
)
|
|
19
|
+
if(parent){
|
|
20
|
+
Affine3.multiply(parent.world,this.world,this.world)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {Transform3D} other
|
|
26
|
+
*/
|
|
27
|
+
copy(other){
|
|
28
|
+
this.position.copy(other.position)
|
|
29
|
+
this.orientation.copy(other.orientation)
|
|
30
|
+
this.scale.copy(other.scale)
|
|
31
|
+
this.world.copy(other.world)
|
|
32
|
+
|
|
33
|
+
return this
|
|
34
|
+
}
|
|
35
|
+
clone(){
|
|
36
|
+
return new Transform3D().copy(this)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { VertexFormat } from '../../constants/index.js'
|
|
2
|
+
|
|
3
|
+
export class Attribute {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @readonly
|
|
7
|
+
* @type {string}
|
|
8
|
+
*/
|
|
9
|
+
name = ''
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @readonly
|
|
13
|
+
* @type {number}
|
|
14
|
+
*/
|
|
15
|
+
id = 0
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @readonly
|
|
19
|
+
* @type {VertexFormat}
|
|
20
|
+
*/
|
|
21
|
+
format
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} name
|
|
25
|
+
* @param {number} location
|
|
26
|
+
* @param {VertexFormat} format
|
|
27
|
+
*/
|
|
28
|
+
constructor(name, location, format) {
|
|
29
|
+
this.name = name
|
|
30
|
+
this.id = location
|
|
31
|
+
this.format = format
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static Position = new Attribute(
|
|
35
|
+
'position',
|
|
36
|
+
0,
|
|
37
|
+
VertexFormat.Float32x3
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
static UV = new Attribute(
|
|
41
|
+
'uv',
|
|
42
|
+
1,
|
|
43
|
+
VertexFormat.Float32x2
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
static UVB = new Attribute(
|
|
47
|
+
'uvb',
|
|
48
|
+
2,
|
|
49
|
+
VertexFormat.Float32x2
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
static Normal = new Attribute(
|
|
53
|
+
'normal',
|
|
54
|
+
3,
|
|
55
|
+
VertexFormat.Float32x3
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
static Tangent = new Attribute(
|
|
59
|
+
'tangent',
|
|
60
|
+
4,
|
|
61
|
+
VertexFormat.Float32x3
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
static Color = new Attribute(
|
|
65
|
+
'color',
|
|
66
|
+
5,
|
|
67
|
+
VertexFormat.Float32x4
|
|
68
|
+
)
|
|
69
|
+
static JointWeight = new Attribute(
|
|
70
|
+
'joint_weight',
|
|
71
|
+
6,
|
|
72
|
+
VertexFormat.Float32x4
|
|
73
|
+
)
|
|
74
|
+
static JointIndex = new Attribute(
|
|
75
|
+
'joint_index',
|
|
76
|
+
7,
|
|
77
|
+
VertexFormat.Uint16x4
|
|
78
|
+
)
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './attribute.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './separate.js'
|