轻量封装WebGPU渲染系统示例<50>- Json数据描述材质等3D渲染场景信息

本示例中的3d渲染场景由Json数据来描述。

包含3个主要部分:

  1. Json描述渲染器的基本信息。

  2. Json描述渲染场景的环境信息,包括全局的灯光、阴影、雾等。

  3. Json描述构成场景的各个可选人实体,包括几何信息、transform、材质、渲染状态等。

当前示例源码github地址:

https://github.com/vilyLei/voxwebgpu/blob/feature/material/src/voxgpu/sample/DataDrivenScene2.ts

当前示例运行效果:

此示例基于此渲染系统实现,当前示例TypeScript源码如下:

json场景数据:

javascript 复制代码
{
	"renderer": {
		"mtplEnabled": true,
		"camera": {
			"eye": [
				1100,
				1100,
				500
			],
			"up": [
				0,
				1,
				0
			]
		}
	},
	"scene": {
		"light": {
			"pointLights": [
				{
					"position": [
						0,
						190,
						0
					],
					"color": [
						5,
						0,
						0
					],
					"factor1": 0.00001,
					"factor2": 0.00002
				}
			],
			"directionLights": [
				{
					"direction": [-1, -1, 0],
					"color": [0.5, 0.5, 0.5]
				}
			],
			"spotLights": []
		},
		"shadow": {
			"intensity": 0.4,
			"radius": 4
		},
		"fog": {
			"color": [
				0.3,
				0.7,
				0.2
			]
		}
	},
	"entities": [
		{
			"plane": {
				"entity": {
					"axisType": 1,
					"extent": [
						-600,
						-600,
						1200,
						1200
					],
					"transform": {
						"position": [
							0,
							0,
							0
						]
					},
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"shadow": false,
							"shadowReceived": true,
							"fogging": true,
							"arms": [
								1,
								0.3,
								0.2
							],
							"albedo": [
								0.6,
								0.6,
								0.5
							]
						}
					]
				}
			}
		},
		{
			"sphere": {
				"entity": {
					"radius": 80,
					"transform": {
						"position": [
							0,
							100,
							200
						]
					},
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"shadow": true,
							"shadowReceived": true,
							"fogging": true,
							"arms": [
								1,
								0.3,
								0.2
							],
							"albedo": [
								0.7,
								0.6,
								0.5
							]
						}
					]
				}
			}
		},
		{
			"cube": {
				"entity": {
					"size": 80,
					"transform": {
						"position": [
							220,
							130,
							-10
						],
						"scale": [
							2,
							1.5,
							3
						],
						"rotation": [
							-190,
							0,
							200
						]
					},
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"shadow": true,
							"shadowReceived": true,
							"fogging": true,
							"arms": [
								1,
								0.4,
								0.2
							],
							"albedo": [
								0.3,
								0.7,
								0.8
							]
						}
					]
				}
			}
		},
		{
			"torus": {
				"entity": {
					"radius": 150,
					"axisType": 1,
					"rings": 50,
					"segments": 30,
					"transform": {
						"position": [
							0,
							230,
							0
						]
					},
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"shadow": true,
							"shadowReceived": true,
							"fogging": true,
							"arms": [
								1,
								0.2,
								0.2
							],
							"albedo": [
								0.2,
								0.5,
								0.8
							]
						}
					]
				}
			}
		},
		{
			"model": {
				"entity": {
					"url": "static/assets/draco/monkey.drc",
					"transform": {
						"position": [
							0,
							380,
							0
						],
						"scale": [
							100,
							100,
							100
						],
						"rotation": [
							0,
							90,
							0
						]
					},
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"shadow": true,
							"shadowReceived": true,
							"fogging": true,
							"arms": [
								1,
								0.5,
								0.2
							],
							"albedo": [
								0.6,
								0.3,
								0.8
							]
						}
					]
				}
			}
		},
		{
			"cube": {
				"entity": {
					"size": 2050,
					"normalScale": -1,
					"materials": [
						{
							"type": "default",
							"lighting": true,
							"fogging": true,
							"arms": [
								1,
								0.3,
								0.2
							],
							"albedo": [
								0.3,
								0.3,
								0.7
							],
							"faceCullMode": "front"
						}
					]
				}
			}
		},
		{
			"gltf": {
				"entity": {}
			}
		},
		{
			"usd": {
				"entity": {}
			}
		}
	]
}

代码:

javascript 复制代码
export class DataDrivenScene2 {

	private mScene = new DataDrivenRScene();
	initialize(): void {

		let url = "static/assets/scene/sceneData02.json";

		new HttpFileLoader().loadJson(
			url,
			(json: object, url: string): void => {
				console.log("json: ", json);
				this.initScene(json);
			}
		);
	}
	private initScene(json: object): void {
		this.mScene.initialize(json);
		this.initEvent();
	}
	private initEvent(): void {
		const rc = this.mScene;
		new MouseInteraction().initialize(rc.rscene, 0, false).setAutoRunning(true);
	}
	run(): void {
		this.mScene.run();
	}
}
相关推荐
mirrornan3 小时前
3D和AR技术在电商行业的应用有哪些?
3d·ar·3d建模·3d模型·三维建模
工业3D_大熊5 小时前
3D开发工具HOOPS助力造船业加速设计与数字化转型
3d
zaf赵5 小时前
3D 高斯溅射 (Gaussian Splatting)技术,一种实现超写实、高效渲染的突破性技术
3d
前端Hardy9 小时前
HTML&CSS:酷炫的3D开关控件
前端·javascript·css·3d·html
Debroon1 天前
M3D: 基于多模态大模型的新型3D医学影像分析框架,将3D医学图像分析从“看图片“提升到“理解空间“的层次,支持检索、报告生成、问答、定位和分割等8类任务
3d
广东数字化转型1 天前
Three.js相机Camera控件知识梳理
3d·three.js
CASAIM2 天前
模具制造之三维扫描和逆向建模
目标检测·3d·汽车·制造
工业3D_大熊2 天前
HOOPS Communicator功能剖析:3D Web模型树交互的实用指南!
linux·windows·macos·3d·docker·c#·.net
番茄电脑全能王2 天前
电脑玩《刺客信条》时中,遇到找不到d3dx9_42.dll的问题是什么原因?缺失d3dx9_42.dll应该怎么解决呢?下面一起来看看吧!
3d
程序员_三木2 天前
Three.js资源-贴图材质网站推荐
javascript·webgl·three.js·材质·贴图