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,93 @@
|
|
|
1
|
+
import Stats from "stats.js";
|
|
2
|
+
import {
|
|
3
|
+
MeshMaterial3D,
|
|
4
|
+
LambertMaterial,
|
|
5
|
+
Quaternion,
|
|
6
|
+
DirectionalLight,
|
|
7
|
+
WebGLRenderer,
|
|
8
|
+
TextureLoader,
|
|
9
|
+
PerspectiveProjection,
|
|
10
|
+
Camera,
|
|
11
|
+
WebGLRenderDevice,
|
|
12
|
+
CuboidMeshBuilder,
|
|
13
|
+
MeshMaterialPlugin,
|
|
14
|
+
AmbientLight,
|
|
15
|
+
LightPlugin,
|
|
16
|
+
CanvasTarget,
|
|
17
|
+
CameraPlugin
|
|
18
|
+
} from 'chorama';
|
|
19
|
+
|
|
20
|
+
// performance monitor
|
|
21
|
+
const stats = new Stats()
|
|
22
|
+
stats.showPanel(1)
|
|
23
|
+
document.body.append(stats.dom)
|
|
24
|
+
stats.dom.removeAttribute('style')
|
|
25
|
+
stats.dom.classList.add('performance-monitor')
|
|
26
|
+
|
|
27
|
+
const canvas = document.createElement('canvas')
|
|
28
|
+
const renderDevice = new WebGLRenderDevice(canvas, {
|
|
29
|
+
depth: true
|
|
30
|
+
})
|
|
31
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
32
|
+
const renderer = new WebGLRenderer({
|
|
33
|
+
plugins: [
|
|
34
|
+
new CameraPlugin(),
|
|
35
|
+
new LightPlugin(),
|
|
36
|
+
new MeshMaterialPlugin(),
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
const camera = new Camera(renderTarget)
|
|
40
|
+
|
|
41
|
+
// lights
|
|
42
|
+
const ambientLight = new AmbientLight()
|
|
43
|
+
const directionalLight = new DirectionalLight()
|
|
44
|
+
|
|
45
|
+
directionalLight.transform.orientation
|
|
46
|
+
.rotateX(-Math.PI / 4)
|
|
47
|
+
.rotateZ(-Math.PI / 4)
|
|
48
|
+
ambientLight.intensity = 0.15
|
|
49
|
+
|
|
50
|
+
const textureLoader = new TextureLoader()
|
|
51
|
+
const texture = textureLoader.load({
|
|
52
|
+
paths: ["/images/uv.jpg"],
|
|
53
|
+
textureSettings: {
|
|
54
|
+
flipY: true
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
const box = new MeshMaterial3D(
|
|
58
|
+
new CuboidMeshBuilder().build(),
|
|
59
|
+
new LambertMaterial({
|
|
60
|
+
mainTexture: texture
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
camera.transform.position.z = 2
|
|
64
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
65
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const rotation = Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
69
|
+
|
|
70
|
+
document.body.append(canvas)
|
|
71
|
+
updateView()
|
|
72
|
+
addEventListener("resize", updateView)
|
|
73
|
+
requestAnimationFrame(update)
|
|
74
|
+
|
|
75
|
+
function update() {
|
|
76
|
+
stats.begin()
|
|
77
|
+
box.transform.orientation.multiply(rotation)
|
|
78
|
+
renderer.render([box, ambientLight, directionalLight, camera], renderDevice)
|
|
79
|
+
stats.end()
|
|
80
|
+
|
|
81
|
+
requestAnimationFrame(update)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function updateView() {
|
|
85
|
+
canvas.style.width = innerWidth + "px"
|
|
86
|
+
canvas.style.height = innerHeight + "px"
|
|
87
|
+
canvas.width = innerWidth * devicePixelRatio
|
|
88
|
+
canvas.height = innerHeight * devicePixelRatio
|
|
89
|
+
|
|
90
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
91
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import Stats from "stats.js";
|
|
2
|
+
import {
|
|
3
|
+
MeshMaterial3D,
|
|
4
|
+
LambertMaterial,
|
|
5
|
+
Quaternion,
|
|
6
|
+
DirectionalLight,
|
|
7
|
+
WebGLRenderer,
|
|
8
|
+
TextureLoader,
|
|
9
|
+
PerspectiveProjection,
|
|
10
|
+
Camera,
|
|
11
|
+
WebGLRenderDevice,
|
|
12
|
+
UVSphereMeshBuilder,
|
|
13
|
+
AmbientLight,
|
|
14
|
+
LightPlugin,
|
|
15
|
+
MeshMaterialPlugin,
|
|
16
|
+
CanvasTarget,
|
|
17
|
+
CameraPlugin
|
|
18
|
+
} from 'chorama';
|
|
19
|
+
|
|
20
|
+
// performance monitor
|
|
21
|
+
const stats = new Stats()
|
|
22
|
+
stats.showPanel(1)
|
|
23
|
+
document.body.append(stats.dom)
|
|
24
|
+
stats.dom.removeAttribute('style')
|
|
25
|
+
stats.dom.classList.add('performance-monitor')
|
|
26
|
+
|
|
27
|
+
const canvas = document.createElement('canvas')
|
|
28
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
29
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
30
|
+
depth:true
|
|
31
|
+
})
|
|
32
|
+
const renderer = new WebGLRenderer({
|
|
33
|
+
plugins:[
|
|
34
|
+
new CameraPlugin(),
|
|
35
|
+
new LightPlugin(),
|
|
36
|
+
new MeshMaterialPlugin(),
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
const camera = new Camera(renderTarget)
|
|
40
|
+
|
|
41
|
+
const textureLoader = new TextureLoader()
|
|
42
|
+
const texture = textureLoader.load({
|
|
43
|
+
paths: ["/images/uv.jpg"],
|
|
44
|
+
textureSettings:{
|
|
45
|
+
flipY:true
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// lights
|
|
50
|
+
const ambientLight = new AmbientLight()
|
|
51
|
+
const directionalLight = new DirectionalLight()
|
|
52
|
+
|
|
53
|
+
directionalLight.transform.orientation
|
|
54
|
+
.rotateX(-Math.PI / 4)
|
|
55
|
+
.rotateZ(-Math.PI / 4)
|
|
56
|
+
ambientLight.intensity = 0.15
|
|
57
|
+
|
|
58
|
+
camera.transform.position.z = 2
|
|
59
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
60
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
61
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const sphere = new MeshMaterial3D(
|
|
65
|
+
new UVSphereMeshBuilder().build(),
|
|
66
|
+
new LambertMaterial({
|
|
67
|
+
mainTexture: texture,
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
const rotation = Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
71
|
+
|
|
72
|
+
document.body.append(canvas)
|
|
73
|
+
updateView()
|
|
74
|
+
addEventListener("resize", updateView)
|
|
75
|
+
requestAnimationFrame(update)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
function update() {
|
|
79
|
+
stats.begin()
|
|
80
|
+
sphere.transform.orientation.multiply(rotation)
|
|
81
|
+
renderer.render([sphere, directionalLight, ambientLight, camera],renderDevice)
|
|
82
|
+
stats.end()
|
|
83
|
+
|
|
84
|
+
requestAnimationFrame(update)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function updateView() {
|
|
88
|
+
canvas.style.width = innerWidth + "px"
|
|
89
|
+
canvas.style.height = innerHeight + "px"
|
|
90
|
+
canvas.width = innerWidth * devicePixelRatio
|
|
91
|
+
canvas.height = innerHeight * devicePixelRatio
|
|
92
|
+
|
|
93
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
94
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MeshMaterial3D,
|
|
3
|
+
BasicMaterial,
|
|
4
|
+
Quaternion,
|
|
5
|
+
WebGLRenderer,
|
|
6
|
+
TextureLoader,
|
|
7
|
+
PerspectiveProjection,
|
|
8
|
+
Camera,
|
|
9
|
+
WebGLRenderDevice,
|
|
10
|
+
CanvasTarget,
|
|
11
|
+
ViewRectangle,
|
|
12
|
+
TextureType,
|
|
13
|
+
SkyBox,
|
|
14
|
+
CuboidMeshBuilder,
|
|
15
|
+
MeshMaterialPlugin,
|
|
16
|
+
SkyboxPlugin,
|
|
17
|
+
CameraPlugin
|
|
18
|
+
} from "chorama"
|
|
19
|
+
import { GUI } from "dat.gui";
|
|
20
|
+
import { addRenderGraphGuiAddon } from "@examples/rendergraph_gui";
|
|
21
|
+
|
|
22
|
+
const canvas = document.createElement('canvas')
|
|
23
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
24
|
+
depth:true
|
|
25
|
+
})
|
|
26
|
+
const renderTarget = new CanvasTarget(canvas)
|
|
27
|
+
const renderer = new WebGLRenderer({
|
|
28
|
+
plugins:[
|
|
29
|
+
new CameraPlugin(),
|
|
30
|
+
new SkyboxPlugin(),
|
|
31
|
+
new MeshMaterialPlugin(),
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
const camera = new Camera(renderTarget)
|
|
35
|
+
const textureLoader = new TextureLoader()
|
|
36
|
+
const texture = textureLoader.load({
|
|
37
|
+
paths: ["/images/uv.jpg"],
|
|
38
|
+
textureSettings: {
|
|
39
|
+
flipY: true
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
const day = textureLoader.load({
|
|
43
|
+
paths: [
|
|
44
|
+
"/images/skybox/miramar_right.png",
|
|
45
|
+
"/images/skybox/miramar_left.png",
|
|
46
|
+
"/images/skybox/miramar_top.png",
|
|
47
|
+
"/images/skybox/miramar_bottom.png",
|
|
48
|
+
"/images/skybox/miramar_back.png",
|
|
49
|
+
"/images/skybox/miramar_front.png",
|
|
50
|
+
|
|
51
|
+
],
|
|
52
|
+
type: TextureType.TextureCubeMap,
|
|
53
|
+
})
|
|
54
|
+
const material = new BasicMaterial({
|
|
55
|
+
mainTexture: texture
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
//create objects
|
|
59
|
+
const object = new MeshMaterial3D(new CuboidMeshBuilder().build(), material)
|
|
60
|
+
const skyBox = new SkyBox({
|
|
61
|
+
day,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
//set up the camera
|
|
65
|
+
camera.target = renderTarget
|
|
66
|
+
camera.transform.position.z = 1.5
|
|
67
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
68
|
+
camera.projection.fov = Math.PI / 180 * 120
|
|
69
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
document.body.append(canvas)
|
|
73
|
+
updateView()
|
|
74
|
+
addEventListener('resize',updateView)
|
|
75
|
+
requestAnimationFrame(update)
|
|
76
|
+
|
|
77
|
+
function update() {
|
|
78
|
+
object.transform.orientation.multiply(
|
|
79
|
+
Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
renderer.render([skyBox, object, camera], renderDevice)
|
|
83
|
+
requestAnimationFrame(update)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function updateView() {
|
|
87
|
+
const fullWidth = innerWidth * devicePixelRatio
|
|
88
|
+
const fullHeight = innerWidth * devicePixelRatio
|
|
89
|
+
|
|
90
|
+
canvas.style.width = innerWidth + "px"
|
|
91
|
+
canvas.style.height = innerHeight + "px"
|
|
92
|
+
canvas.width = fullWidth
|
|
93
|
+
canvas.height = fullHeight
|
|
94
|
+
if (camera.projection instanceof PerspectiveProjection) {
|
|
95
|
+
camera.projection.aspect = innerWidth / innerHeight
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// gui controls
|
|
100
|
+
const settings = {
|
|
101
|
+
enableScissors: false
|
|
102
|
+
}
|
|
103
|
+
const controls = new GUI()
|
|
104
|
+
const canvasopts = controls.addFolder("Canvas Render Target")
|
|
105
|
+
canvasopts.add(renderTarget.viewport.offset, 'x', 0, 1).name("Viewport X")
|
|
106
|
+
canvasopts.add(renderTarget.viewport.offset, 'y', 0, 1).name("Viewport Y")
|
|
107
|
+
canvasopts.add(renderTarget.viewport.size, 'x', 0, 1).name("Viewport Width")
|
|
108
|
+
canvasopts.add(renderTarget.viewport.size, 'y', 0, 1).name("Viewport Hieght")
|
|
109
|
+
/**@type {GUI} */
|
|
110
|
+
let scissorsFolder
|
|
111
|
+
canvasopts.add(settings, "enableScissors").onChange((value) => {
|
|
112
|
+
if (value) {
|
|
113
|
+
renderTarget.scissor = new ViewRectangle()
|
|
114
|
+
scissorsFolder = canvasopts.addFolder('Scissors')
|
|
115
|
+
scissorsFolder.add(renderTarget.scissor.offset, 'x', 0, 1).name("Scissor X")
|
|
116
|
+
scissorsFolder.add(renderTarget.scissor.offset, 'y', 0, 1).name("Scissor Y")
|
|
117
|
+
scissorsFolder.add(renderTarget.scissor.size, 'x', 0, 1).name("Scissor Width")
|
|
118
|
+
scissorsFolder.add(renderTarget.scissor.size, 'y', 0, 1).name("Scissor Hieght")
|
|
119
|
+
} else {
|
|
120
|
+
canvasopts.removeFolder(scissorsFolder)
|
|
121
|
+
renderTarget.scissor = undefined
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
canvasopts.open()
|
|
125
|
+
|
|
126
|
+
addRenderGraphGuiAddon({
|
|
127
|
+
gui: controls,
|
|
128
|
+
renderer,
|
|
129
|
+
position: { x: 24, y: 24 }
|
|
130
|
+
})
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { GUI } from "dat.gui"
|
|
2
|
+
import { addRenderGraphGuiAddon } from "@examples/rendergraph_gui"
|
|
3
|
+
import Stats from "stats.js";
|
|
4
|
+
import {
|
|
5
|
+
MeshMaterial3D,
|
|
6
|
+
BasicMaterial,
|
|
7
|
+
Quaternion,
|
|
8
|
+
WebGLRenderer,
|
|
9
|
+
PerspectiveProjection,
|
|
10
|
+
Camera,
|
|
11
|
+
WebGLRenderDevice,
|
|
12
|
+
TextureType,
|
|
13
|
+
Texture,
|
|
14
|
+
TextureFormat,
|
|
15
|
+
ImageRenderTarget,
|
|
16
|
+
CuboidMeshBuilder,
|
|
17
|
+
MeshMaterialPlugin,
|
|
18
|
+
PlaneMeshBuilder,
|
|
19
|
+
DepthMaterial,
|
|
20
|
+
CanvasTarget,
|
|
21
|
+
CameraPlugin
|
|
22
|
+
} from "chorama"
|
|
23
|
+
|
|
24
|
+
// performance monitor
|
|
25
|
+
const stats = new Stats()
|
|
26
|
+
stats.showPanel(1)
|
|
27
|
+
document.body.append(stats.dom)
|
|
28
|
+
stats.dom.removeAttribute('style')
|
|
29
|
+
stats.dom.classList.add('performance-monitor')
|
|
30
|
+
|
|
31
|
+
const canvas = document.createElement('canvas')
|
|
32
|
+
const canvasTarget = new CanvasTarget(canvas)
|
|
33
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
34
|
+
depth:true
|
|
35
|
+
})
|
|
36
|
+
const renderer = new WebGLRenderer({
|
|
37
|
+
plugins: [
|
|
38
|
+
new CameraPlugin(),
|
|
39
|
+
new MeshMaterialPlugin(),
|
|
40
|
+
]
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const depthTexture = new Texture({
|
|
44
|
+
type: TextureType.Texture2D,
|
|
45
|
+
format: TextureFormat.Depth24PlusStencil8
|
|
46
|
+
})
|
|
47
|
+
const renderTarget = new ImageRenderTarget({
|
|
48
|
+
width: 1024,
|
|
49
|
+
height: 1024,
|
|
50
|
+
depthTexture: depthTexture
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const camera1 = new Camera(renderTarget)
|
|
54
|
+
const camera2 = new Camera(canvasTarget)
|
|
55
|
+
const mesh = new CuboidMeshBuilder().build()
|
|
56
|
+
const quad = new PlaneMeshBuilder()
|
|
57
|
+
const depthMaterial = new DepthMaterial({
|
|
58
|
+
depth: depthTexture
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const object1 = new MeshMaterial3D(mesh, new BasicMaterial())
|
|
62
|
+
const object2 = new MeshMaterial3D(quad.build(), depthMaterial)
|
|
63
|
+
|
|
64
|
+
//set up the cameras
|
|
65
|
+
camera1.far = 500
|
|
66
|
+
camera1.transform.position.z = 5
|
|
67
|
+
camera2.transform.position.z = 1
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
camera1.projection instanceof PerspectiveProjection &&
|
|
71
|
+
camera2.projection instanceof PerspectiveProjection
|
|
72
|
+
) {
|
|
73
|
+
camera1.projection.fov = Math.PI / 180 * 60
|
|
74
|
+
camera2.projection.fov = Math.PI / 180 * 60
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
document.body.append(canvas)
|
|
78
|
+
updateView()
|
|
79
|
+
addEventListener('resize', updateView)
|
|
80
|
+
requestAnimationFrame(update)
|
|
81
|
+
|
|
82
|
+
function update() {
|
|
83
|
+
stats.begin()
|
|
84
|
+
renderer.render([object1, camera1], renderDevice)
|
|
85
|
+
renderer.render([object2, camera2], renderDevice)
|
|
86
|
+
|
|
87
|
+
object1.transform.orientation.multiply(
|
|
88
|
+
Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
89
|
+
)
|
|
90
|
+
stats.end()
|
|
91
|
+
|
|
92
|
+
requestAnimationFrame(update)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function updateView() {
|
|
96
|
+
const fullWidth = innerWidth * devicePixelRatio
|
|
97
|
+
const fullHeight = innerWidth * devicePixelRatio
|
|
98
|
+
|
|
99
|
+
canvas.style.width = innerWidth + "px"
|
|
100
|
+
canvas.style.height = innerHeight + "px"
|
|
101
|
+
canvas.width = fullWidth
|
|
102
|
+
canvas.height = fullHeight
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
camera1.projection instanceof PerspectiveProjection &&
|
|
106
|
+
camera2.projection instanceof PerspectiveProjection
|
|
107
|
+
) {
|
|
108
|
+
camera1.projection.aspect = fullWidth / fullHeight
|
|
109
|
+
camera2.projection.aspect = fullWidth / fullHeight
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const controls = new GUI()
|
|
114
|
+
const buildOptionsFolder = controls.addFolder("Settings")
|
|
115
|
+
buildOptionsFolder
|
|
116
|
+
.add(camera1.transform.position, 'z', 1, 10)
|
|
117
|
+
.name("Position Z")
|
|
118
|
+
buildOptionsFolder
|
|
119
|
+
.add(camera1, 'near', 0.1, 10)
|
|
120
|
+
.name("Camera Near")
|
|
121
|
+
.onChange((value)=>depthMaterial.near = value)
|
|
122
|
+
buildOptionsFolder
|
|
123
|
+
.add(camera1, 'far', 10, 500)
|
|
124
|
+
.name("Camera Far")
|
|
125
|
+
.onChange((value)=>depthMaterial.far = value)
|
|
126
|
+
buildOptionsFolder.open()
|
|
127
|
+
addRenderGraphGuiAddon({
|
|
128
|
+
gui: controls,
|
|
129
|
+
renderer
|
|
130
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import Stats from "stats.js";
|
|
2
|
+
import {
|
|
3
|
+
MeshMaterial3D,
|
|
4
|
+
BasicMaterial,
|
|
5
|
+
Quaternion,
|
|
6
|
+
WebGLRenderer,
|
|
7
|
+
TextureLoader,
|
|
8
|
+
PerspectiveProjection,
|
|
9
|
+
Camera,
|
|
10
|
+
WebGLRenderDevice,
|
|
11
|
+
TextureType,
|
|
12
|
+
SkyBox,
|
|
13
|
+
Texture,
|
|
14
|
+
TextureFormat,
|
|
15
|
+
ImageRenderTarget,
|
|
16
|
+
Color,
|
|
17
|
+
CuboidMeshBuilder,
|
|
18
|
+
MeshMaterialPlugin,
|
|
19
|
+
CanvasTarget,
|
|
20
|
+
SkyboxPlugin,
|
|
21
|
+
CameraPlugin
|
|
22
|
+
} from "chorama"
|
|
23
|
+
|
|
24
|
+
// performance monitor
|
|
25
|
+
const stats = new Stats()
|
|
26
|
+
stats.showPanel(1)
|
|
27
|
+
document.body.append(stats.dom)
|
|
28
|
+
stats.dom.removeAttribute('style')
|
|
29
|
+
stats.dom.classList.add('performance-monitor')
|
|
30
|
+
|
|
31
|
+
const canvas = document.createElement('canvas')
|
|
32
|
+
const canvasTarget = new CanvasTarget(canvas)
|
|
33
|
+
const renderDevice = new WebGLRenderDevice(canvas,{
|
|
34
|
+
depth:true
|
|
35
|
+
})
|
|
36
|
+
const renderer = new WebGLRenderer({
|
|
37
|
+
plugins:[
|
|
38
|
+
new CameraPlugin(),
|
|
39
|
+
new SkyboxPlugin(),
|
|
40
|
+
new MeshMaterialPlugin(),
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const renderTarget = new ImageRenderTarget({
|
|
45
|
+
width:1024,
|
|
46
|
+
height:1024,
|
|
47
|
+
color:[
|
|
48
|
+
new Texture({
|
|
49
|
+
type:TextureType.Texture2D,
|
|
50
|
+
format:TextureFormat.RGBA8Unorm
|
|
51
|
+
})
|
|
52
|
+
],
|
|
53
|
+
internalDepthStencil:TextureFormat.Depth24PlusStencil8
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const camera1 = new Camera(renderTarget)
|
|
57
|
+
const camera2 = new Camera(canvasTarget)
|
|
58
|
+
|
|
59
|
+
const textureLoader = new TextureLoader()
|
|
60
|
+
const texture = textureLoader.load({
|
|
61
|
+
paths: ["/images/uv.jpg"],
|
|
62
|
+
textureSettings: {
|
|
63
|
+
flipY: true
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
const day = textureLoader.load({
|
|
67
|
+
paths: [
|
|
68
|
+
"/images/skybox/miramar_right.png",
|
|
69
|
+
"/images/skybox/miramar_left.png",
|
|
70
|
+
"/images/skybox/miramar_top.png",
|
|
71
|
+
"/images/skybox/miramar_bottom.png",
|
|
72
|
+
"/images/skybox/miramar_back.png",
|
|
73
|
+
"/images/skybox/miramar_front.png"
|
|
74
|
+
],
|
|
75
|
+
type: TextureType.TextureCubeMap
|
|
76
|
+
})
|
|
77
|
+
const mesh = new CuboidMeshBuilder().build()
|
|
78
|
+
const object1 = new MeshMaterial3D(mesh, new BasicMaterial({
|
|
79
|
+
mainTexture: texture
|
|
80
|
+
}))
|
|
81
|
+
const object2 = new MeshMaterial3D(mesh, new BasicMaterial({
|
|
82
|
+
mainTexture: renderTarget.color[0]
|
|
83
|
+
}))
|
|
84
|
+
const skyBox = new SkyBox({
|
|
85
|
+
day,
|
|
86
|
+
night:day
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
//set up the cameras
|
|
90
|
+
renderTarget.clearColor = Color.CYAN.clone()
|
|
91
|
+
camera1.target = renderTarget
|
|
92
|
+
camera1.transform.position.z = 5
|
|
93
|
+
camera2.transform.position.z = 5
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
camera1.projection instanceof PerspectiveProjection &&
|
|
97
|
+
camera2.projection instanceof PerspectiveProjection
|
|
98
|
+
) {
|
|
99
|
+
camera1.projection.fov = Math.PI / 180 * 60
|
|
100
|
+
camera2.projection.fov = Math.PI / 180 * 60
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
document.body.append(canvas)
|
|
104
|
+
updateView()
|
|
105
|
+
addEventListener('resize', updateView)
|
|
106
|
+
requestAnimationFrame(update)
|
|
107
|
+
|
|
108
|
+
function update() {
|
|
109
|
+
stats.begin()
|
|
110
|
+
renderer.render([object1, camera1], renderDevice)
|
|
111
|
+
renderer.render([skyBox, object2, camera2], renderDevice)
|
|
112
|
+
|
|
113
|
+
object1.transform.orientation.multiply(
|
|
114
|
+
Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
115
|
+
)
|
|
116
|
+
object2.transform.orientation.multiply(
|
|
117
|
+
Quaternion.fromEuler(Math.PI / 1000, Math.PI / 1000, 0)
|
|
118
|
+
)
|
|
119
|
+
stats.end()
|
|
120
|
+
|
|
121
|
+
requestAnimationFrame(update)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function updateView() {
|
|
125
|
+
const fullWidth = innerWidth * devicePixelRatio
|
|
126
|
+
const fullHeight = innerWidth * devicePixelRatio
|
|
127
|
+
|
|
128
|
+
canvas.style.width = innerWidth + "px"
|
|
129
|
+
canvas.style.height = innerHeight + "px"
|
|
130
|
+
canvas.width = fullWidth
|
|
131
|
+
canvas.height = fullHeight
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
camera1.projection instanceof PerspectiveProjection &&
|
|
135
|
+
camera2.projection instanceof PerspectiveProjection
|
|
136
|
+
) {
|
|
137
|
+
camera1.projection.aspect = fullWidth / fullHeight
|
|
138
|
+
camera2.projection.aspect = fullWidth / fullHeight
|
|
139
|
+
}
|
|
140
|
+
}
|