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

当前示例源码github地址:

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

当前示例运行效果:

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

json场景数据:

{
	"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": {}
			}
		}
	]
}

代码:

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();
	}
}

最近更新

  1. TCP协议是安全的吗?

    2023-12-17 04:00:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-17 04:00:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-17 04:00:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-17 04:00:04       18 阅读

热门阅读

  1. 西电微机原理实验三

    2023-12-17 04:00:04       35 阅读
  2. 算法基础十三

    2023-12-17 04:00:04       32 阅读
  3. Linux的双网口(内网+外网)的IP报文转发

    2023-12-17 04:00:04       33 阅读
  4. 23. 如何设计一个前端项目

    2023-12-17 04:00:04       38 阅读
  5. vue3 引入Element Plus 组件库

    2023-12-17 04:00:04       38 阅读
  6. 序列化与反序列化

    2023-12-17 04:00:04       28 阅读
  7. k8s service 内部dns 地址介绍,互相依赖Pod启动介绍

    2023-12-17 04:00:04       36 阅读
  8. 企业与员工

    2023-12-17 04:00:04       38 阅读
  9. (第29天)Oracle 数据泵传输表空间

    2023-12-17 04:00:04       37 阅读
  10. ArcGIS Pro SDK 将几何输出为要素

    2023-12-17 04:00:04       42 阅读