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,156 @@
|
|
|
1
|
+
import { GUI } from 'dat.gui';
|
|
2
|
+
import { addRenderGraphGuiAddon } from "@examples/rendergraph_gui"
|
|
3
|
+
import Stats from "stats.js";
|
|
4
|
+
import {
|
|
5
|
+
MeshMaterial3D,
|
|
6
|
+
WebGLRenderer,
|
|
7
|
+
TextureLoader,
|
|
8
|
+
PerspectiveProjection,
|
|
9
|
+
Camera,
|
|
10
|
+
WebGLRenderDevice,
|
|
11
|
+
PlaneMeshBuilder,
|
|
12
|
+
MeshMaterialPlugin,
|
|
13
|
+
Material,
|
|
14
|
+
TextureType,
|
|
15
|
+
Texture,
|
|
16
|
+
basicVertex,
|
|
17
|
+
Sampler,
|
|
18
|
+
CanvasTarget,
|
|
19
|
+
CameraPlugin
|
|
20
|
+
} from 'chorama';
|
|
21
|
+
|
|
22
|
+
// Material to view the texture array
|
|
23
|
+
class TextureArrayMaterial extends Material {
|
|
24
|
+
/**
|
|
25
|
+
* @param {Texture} image
|
|
26
|
+
*/
|
|
27
|
+
constructor(image){
|
|
28
|
+
super()
|
|
29
|
+
this.image = image
|
|
30
|
+
this.layer = 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @override
|
|
35
|
+
*/
|
|
36
|
+
vertex(){
|
|
37
|
+
return basicVertex
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @override
|
|
42
|
+
*/
|
|
43
|
+
fragment(){
|
|
44
|
+
return `
|
|
45
|
+
precision mediump float;
|
|
46
|
+
precision mediump sampler2DArray;
|
|
47
|
+
|
|
48
|
+
in vec2 v_uv;
|
|
49
|
+
|
|
50
|
+
uniform MaterialBlock {
|
|
51
|
+
uint layer;
|
|
52
|
+
};
|
|
53
|
+
uniform sampler2DArray color_image;
|
|
54
|
+
|
|
55
|
+
out vec4 fragment_color;
|
|
56
|
+
|
|
57
|
+
void main(){
|
|
58
|
+
vec4 sample_color = texture(color_image, vec3(v_uv, layer));
|
|
59
|
+
fragment_color = vec4(sample_color.rgb, 1.0);
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @override
|
|
66
|
+
*/
|
|
67
|
+
getData(){
|
|
68
|
+
return new Uint32Array([this.layer]).buffer
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @override
|
|
73
|
+
* @returns {[string, number, Texture | undefined, Sampler | undefined][]}
|
|
74
|
+
*/
|
|
75
|
+
getTextures(){
|
|
76
|
+
return [
|
|
77
|
+
['color_image',0,this.image, undefined]
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// performance monitor
|
|
82
|
+
const stats = new Stats()
|
|
83
|
+
stats.showPanel(1)
|
|
84
|
+
document.body.append(stats.dom)
|
|
85
|
+
stats.dom.removeAttribute('style')
|
|
86
|
+
stats.dom.classList.add('performance-monitor')
|
|
87
|
+
|
|
88
|
+
const canvas = document.createElement('canvas')
|
|
89
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
90
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
91
|
+
depth:true
|
|
92
|
+
})
|
|
93
|
+
const renderer = new WebGLRenderer({
|
|
94
|
+
plugins:[
|
|
95
|
+
new CameraPlugin(),
|
|
96
|
+
new MeshMaterialPlugin(),
|
|
97
|
+
]
|
|
98
|
+
})
|
|
99
|
+
const camera = new Camera(renderTarget)
|
|
100
|
+
const textureLoader = new TextureLoader()
|
|
101
|
+
const texture = textureLoader.load({
|
|
102
|
+
paths: [
|
|
103
|
+
"/images/skybox/miramar_right.png",
|
|
104
|
+
"/images/skybox/miramar_left.png",
|
|
105
|
+
"/images/skybox/miramar_top.png",
|
|
106
|
+
"/images/skybox/miramar_bottom.png",
|
|
107
|
+
"/images/skybox/miramar_back.png",
|
|
108
|
+
"/images/skybox/miramar_front.png",
|
|
109
|
+
],
|
|
110
|
+
type:TextureType.Texture2DArray
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const mesh = new PlaneMeshBuilder().build()
|
|
114
|
+
const material = new TextureArrayMaterial(texture)
|
|
115
|
+
|
|
116
|
+
const object1 = new MeshMaterial3D(mesh, material)
|
|
117
|
+
|
|
118
|
+
camera.transform.position.z = 2
|
|
119
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
120
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
document.body.append(canvas)
|
|
124
|
+
updateView()
|
|
125
|
+
addEventListener("resize", updateView)
|
|
126
|
+
requestAnimationFrame(update)
|
|
127
|
+
|
|
128
|
+
function update() {
|
|
129
|
+
stats.begin()
|
|
130
|
+
renderer.render([object1, camera], renderDevice)
|
|
131
|
+
stats.end()
|
|
132
|
+
|
|
133
|
+
requestAnimationFrame(update)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function updateView() {
|
|
137
|
+
canvas.style.width = innerWidth + "px"
|
|
138
|
+
canvas.style.height = innerHeight + "px"
|
|
139
|
+
canvas.width = innerWidth * devicePixelRatio
|
|
140
|
+
canvas.height = innerHeight * devicePixelRatio
|
|
141
|
+
|
|
142
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
143
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// gui controls
|
|
148
|
+
const controls = new GUI()
|
|
149
|
+
const optFolder = controls.addFolder('Settings')
|
|
150
|
+
|
|
151
|
+
optFolder.add(material,'layer',0, 5, 1).name('Layer')
|
|
152
|
+
optFolder.open()
|
|
153
|
+
addRenderGraphGuiAddon({
|
|
154
|
+
gui: controls,
|
|
155
|
+
renderer
|
|
156
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Stats from "stats.js";
|
|
2
|
+
import {
|
|
3
|
+
MeshMaterial3D,
|
|
4
|
+
TextureWrap,
|
|
5
|
+
BasicMaterial,
|
|
6
|
+
WebGLRenderer,
|
|
7
|
+
TextureLoader,
|
|
8
|
+
PerspectiveProjection,
|
|
9
|
+
Camera,
|
|
10
|
+
WebGLRenderDevice,
|
|
11
|
+
Sampler,
|
|
12
|
+
PlaneMeshBuilder,
|
|
13
|
+
MeshMaterialPlugin,
|
|
14
|
+
CanvasTarget,
|
|
15
|
+
CameraPlugin
|
|
16
|
+
} from 'chorama';
|
|
17
|
+
|
|
18
|
+
// performance monitor
|
|
19
|
+
const stats = new Stats()
|
|
20
|
+
stats.showPanel(1)
|
|
21
|
+
document.body.append(stats.dom)
|
|
22
|
+
stats.dom.removeAttribute('style')
|
|
23
|
+
stats.dom.classList.add('performance-monitor')
|
|
24
|
+
|
|
25
|
+
const canvas = document.createElement('canvas')
|
|
26
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
27
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
28
|
+
depth:true
|
|
29
|
+
})
|
|
30
|
+
const renderer = new WebGLRenderer({
|
|
31
|
+
plugins:[
|
|
32
|
+
new CameraPlugin(),
|
|
33
|
+
new MeshMaterialPlugin(),
|
|
34
|
+
]
|
|
35
|
+
})
|
|
36
|
+
const camera = new Camera(renderTarget)
|
|
37
|
+
const textureLoader = new TextureLoader()
|
|
38
|
+
const texture = textureLoader.load({
|
|
39
|
+
paths: ["/images/uv.jpg"]
|
|
40
|
+
})
|
|
41
|
+
const sampler1 = new Sampler({
|
|
42
|
+
wrapS: TextureWrap.Clamp,
|
|
43
|
+
wrapT: TextureWrap.Clamp
|
|
44
|
+
})
|
|
45
|
+
const sampler2 = new Sampler({
|
|
46
|
+
wrapS: TextureWrap.Repeat,
|
|
47
|
+
wrapT: TextureWrap.Repeat
|
|
48
|
+
})
|
|
49
|
+
const sampler3 = new Sampler({
|
|
50
|
+
wrapS: TextureWrap.MirrorRepeat,
|
|
51
|
+
wrapT: TextureWrap.MirrorRepeat
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const mesh = new PlaneMeshBuilder().build()
|
|
55
|
+
const buffer = mesh.attributes.get('uv')
|
|
56
|
+
|
|
57
|
+
if(buffer){
|
|
58
|
+
const uvs = new Float32Array(
|
|
59
|
+
buffer.buffer,
|
|
60
|
+
buffer.byteOffset,
|
|
61
|
+
buffer.byteLength / Float32Array.BYTES_PER_ELEMENT
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
for (let i in uvs) {
|
|
65
|
+
// SAFETY: It is a number
|
|
66
|
+
uvs[i] = /**@type {number}*/(uvs[i]) * 2
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const material1 = new BasicMaterial({
|
|
71
|
+
mainTexture: texture,
|
|
72
|
+
mainSampler: sampler1
|
|
73
|
+
})
|
|
74
|
+
const material2 = new BasicMaterial({
|
|
75
|
+
mainTexture: texture,
|
|
76
|
+
mainSampler: sampler2
|
|
77
|
+
})
|
|
78
|
+
const material3 = new BasicMaterial({
|
|
79
|
+
mainTexture: texture,
|
|
80
|
+
mainSampler: sampler3
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const object1 = new MeshMaterial3D(mesh, material1)
|
|
84
|
+
const object2 = new MeshMaterial3D(mesh, material2)
|
|
85
|
+
const object3 = new MeshMaterial3D(mesh, material3)
|
|
86
|
+
|
|
87
|
+
object1.transform.position.x = -1.2
|
|
88
|
+
object2.transform.position.x = 0
|
|
89
|
+
object3.transform.position.x = 1.2
|
|
90
|
+
|
|
91
|
+
camera.transform.position.z = 2
|
|
92
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
93
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
document.body.append(canvas)
|
|
97
|
+
updateView()
|
|
98
|
+
addEventListener("resize", updateView)
|
|
99
|
+
requestAnimationFrame(update)
|
|
100
|
+
|
|
101
|
+
function update() {
|
|
102
|
+
stats.begin()
|
|
103
|
+
renderer.render([object1, object2, object3, camera],renderDevice)
|
|
104
|
+
stats.end()
|
|
105
|
+
|
|
106
|
+
requestAnimationFrame(update)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function updateView() {
|
|
110
|
+
canvas.style.width = innerWidth + "px"
|
|
111
|
+
canvas.style.height = innerHeight + "px"
|
|
112
|
+
canvas.width = innerWidth * devicePixelRatio
|
|
113
|
+
canvas.height = innerHeight * devicePixelRatio
|
|
114
|
+
|
|
115
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
116
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import Stats from "stats.js";
|
|
2
|
+
import {
|
|
3
|
+
MeshMaterial3D,
|
|
4
|
+
CuboidMeshBuilder,
|
|
5
|
+
Quaternion,
|
|
6
|
+
WebGLRenderer,
|
|
7
|
+
TextureLoader,
|
|
8
|
+
BasicMaterial,
|
|
9
|
+
PerspectiveProjection,
|
|
10
|
+
Camera,
|
|
11
|
+
WebGLRenderDevice,
|
|
12
|
+
MeshMaterialPlugin,
|
|
13
|
+
LightPlugin,
|
|
14
|
+
CanvasTarget,
|
|
15
|
+
CameraPlugin
|
|
16
|
+
} from 'chorama';
|
|
17
|
+
|
|
18
|
+
// performance monitor
|
|
19
|
+
const stats = new Stats()
|
|
20
|
+
stats.showPanel(1)
|
|
21
|
+
document.body.append(stats.dom)
|
|
22
|
+
stats.dom.removeAttribute('style')
|
|
23
|
+
stats.dom.classList.add('performance-monitor')
|
|
24
|
+
|
|
25
|
+
const canvas = document.createElement('canvas')
|
|
26
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
27
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
28
|
+
depth:true
|
|
29
|
+
})
|
|
30
|
+
const renderer = new WebGLRenderer({
|
|
31
|
+
plugins:[
|
|
32
|
+
new CameraPlugin(),
|
|
33
|
+
new LightPlugin(),
|
|
34
|
+
new MeshMaterialPlugin(),
|
|
35
|
+
]
|
|
36
|
+
})
|
|
37
|
+
const camera = new Camera(renderTarget)
|
|
38
|
+
|
|
39
|
+
const textureLoader = new TextureLoader()
|
|
40
|
+
const texture = textureLoader.load({
|
|
41
|
+
paths: ["/images/uv.jpg"],
|
|
42
|
+
textureSettings:{
|
|
43
|
+
flipY:true
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
const meshBuilder = new CuboidMeshBuilder()
|
|
47
|
+
meshBuilder.width = 0.5
|
|
48
|
+
meshBuilder.height = 0.5
|
|
49
|
+
meshBuilder.depth = 0.5
|
|
50
|
+
|
|
51
|
+
const mesh = meshBuilder.build()
|
|
52
|
+
const material = new BasicMaterial({
|
|
53
|
+
mainTexture: texture
|
|
54
|
+
})
|
|
55
|
+
const parent = new MeshMaterial3D(mesh, material)
|
|
56
|
+
const child = new MeshMaterial3D(mesh, material)
|
|
57
|
+
|
|
58
|
+
child.transform.position.x = 1
|
|
59
|
+
camera.transform.position.z = 2
|
|
60
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
61
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
62
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
63
|
+
}
|
|
64
|
+
parent.add(child)
|
|
65
|
+
|
|
66
|
+
const rotation = Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
67
|
+
|
|
68
|
+
document.body.append(canvas)
|
|
69
|
+
updateView()
|
|
70
|
+
addEventListener("resize", updateView)
|
|
71
|
+
requestAnimationFrame(update)
|
|
72
|
+
|
|
73
|
+
function update() {
|
|
74
|
+
stats.begin()
|
|
75
|
+
parent.transform.orientation.multiply(rotation)
|
|
76
|
+
|
|
77
|
+
renderer.render([parent, camera],renderDevice)
|
|
78
|
+
stats.end()
|
|
79
|
+
|
|
80
|
+
requestAnimationFrame(update)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function updateView() {
|
|
84
|
+
canvas.style.width = innerWidth + "px"
|
|
85
|
+
canvas.style.height = innerHeight + "px"
|
|
86
|
+
canvas.width = innerWidth * devicePixelRatio
|
|
87
|
+
canvas.height = innerHeight * devicePixelRatio
|
|
88
|
+
|
|
89
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
90
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chorama",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "A rendering library",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rendering",
|
|
7
|
+
"3D",
|
|
8
|
+
"draw",
|
|
9
|
+
"game"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/waynemwashuma/chorama#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/waynemwashuma/chorama/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/waynemwashuma/chorama.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Wayne Mwashuma",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"directories": {
|
|
24
|
+
"example": "examples"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "npm run dev",
|
|
28
|
+
"dev": "astro dev",
|
|
29
|
+
"test": "node test",
|
|
30
|
+
"tsc": "tsc -b tsconfig.json",
|
|
31
|
+
"build-website": "npm run build-src && astro build && node scripts/stage-chorama.mjs",
|
|
32
|
+
"build-src": "rollup --config rollup.config.js",
|
|
33
|
+
"build": "npm run build-website"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
37
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
38
|
+
"@types/dat.gui": "^0.7.13",
|
|
39
|
+
"@types/node": "^25.3.3",
|
|
40
|
+
"@types/stats.js": "^0.17.4",
|
|
41
|
+
"astro": "^5.18.0",
|
|
42
|
+
"remark-gfm": "^4.0.1",
|
|
43
|
+
"remark-github-blockquote-alert": "^2.0.1",
|
|
44
|
+
"rollup": "^4.52.5",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vite": "^7.1.12"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"dat.gui": "^0.7.9",
|
|
50
|
+
"hisabati": "^0.1.0",
|
|
51
|
+
"marangi": "^0.1.0",
|
|
52
|
+
"stats.js": "^0.17.0",
|
|
53
|
+
"vifaa": "file:../vifaa"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFileSync } from "fs"
|
|
2
|
+
import { resolve } from "path"
|
|
3
|
+
import { cwd } from "process"
|
|
4
|
+
import nodeResolve from "@rollup/plugin-node-resolve"
|
|
5
|
+
|
|
6
|
+
const pkg = JSON.parse(readFileSync(resolve(cwd(), "./package.json")).toString())
|
|
7
|
+
|
|
8
|
+
const input = "src/index.js"
|
|
9
|
+
const created = `2023-${new Date().getFullYear()}`
|
|
10
|
+
const name = pkg.name.toUpperCase()
|
|
11
|
+
.replace("@", "")
|
|
12
|
+
.replaceAll("/", "_")
|
|
13
|
+
.replaceAll("-", "_")
|
|
14
|
+
const banner = `/*
|
|
15
|
+
* @author ${pkg.author}
|
|
16
|
+
* @copyright ${created} ${pkg.author}
|
|
17
|
+
* {@link ${pkg.repository.url}}
|
|
18
|
+
*
|
|
19
|
+
* @license ${pkg.license}
|
|
20
|
+
* @version ${pkg.version}
|
|
21
|
+
*/`
|
|
22
|
+
|
|
23
|
+
function glsl() {
|
|
24
|
+
return {
|
|
25
|
+
name: "glsl",
|
|
26
|
+
load(id) {
|
|
27
|
+
if (!id.endsWith(".glsl")) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
return `export default ${JSON.stringify(readFileSync(id, "utf8"))}`
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const plugins = [
|
|
36
|
+
glsl(),
|
|
37
|
+
nodeResolve()
|
|
38
|
+
]
|
|
39
|
+
export default [{
|
|
40
|
+
|
|
41
|
+
// UMD
|
|
42
|
+
input,
|
|
43
|
+
plugins,
|
|
44
|
+
output: {
|
|
45
|
+
file: "dist/index.umd.js",
|
|
46
|
+
format: "umd",
|
|
47
|
+
name,
|
|
48
|
+
esModule: false,
|
|
49
|
+
exports: "named",
|
|
50
|
+
sourcemap: true,
|
|
51
|
+
banner
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
|
|
56
|
+
// ESM
|
|
57
|
+
input,
|
|
58
|
+
plugins,
|
|
59
|
+
output: {
|
|
60
|
+
file: "dist/index.module.js",
|
|
61
|
+
format: "esm",
|
|
62
|
+
exports: "named",
|
|
63
|
+
sourcemap: true,
|
|
64
|
+
banner
|
|
65
|
+
},
|
|
66
|
+
}]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const sourceModule = resolve('dist/index.module.js');
|
|
5
|
+
const sourceMap = resolve('dist/index.module.js.map');
|
|
6
|
+
const targetDir = resolve('dist/website/vendor/chorama');
|
|
7
|
+
const targetModule = resolve(targetDir, 'index.module.js');
|
|
8
|
+
const targetMap = resolve(targetDir, 'index.module.js.map');
|
|
9
|
+
const sourceAddonsDir = resolve('examples/addons');
|
|
10
|
+
const targetAddonsDir = resolve('dist/website/examples/addons');
|
|
11
|
+
|
|
12
|
+
if (!existsSync(sourceModule)) {
|
|
13
|
+
console.error('Missing dist/index.module.js. Run "npm run build-src" first.');
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
mkdirSync(targetDir, { recursive: true });
|
|
18
|
+
cpSync(sourceModule, targetModule);
|
|
19
|
+
|
|
20
|
+
if (existsSync(sourceMap)) {
|
|
21
|
+
cpSync(sourceMap, targetMap);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (existsSync(sourceAddonsDir)) {
|
|
25
|
+
mkdirSync(targetAddonsDir, { recursive: true });
|
|
26
|
+
cpSync(sourceAddonsDir, targetAddonsDir, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log('Staged chorama module and example addons into dist/website/.');
|