轻量封装WebGPU渲染系统示例<10>- 容器(源码)

news2024/9/25 3:27:19

当前示例源码github地址:

https://github.com/vilyLei/voxwebgpu/blob/main/src/voxgpu/sample/REntity3DContainerTest.ts

此示例渲染系统实现的特性:

1. 用户态与系统态隔离。

2. 高频调用与低频调用隔离。

3. 面向用户的易用性封装。

4. 渲染数据和渲染机制分离。

5. 用户操作和渲染系统调度并行机制。

关于3D引擎中容器的更多作用请见: 3D系统中可渲染实体容器(Renderable Entity Container)-CSDN博客

当前示例运行效果:

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

export class REntity3DContainerTest {

	private mRscene = new RendererScene();
	geomData = new GeomDataBuilder();
	initialize(): void {
		console.log("REntity3DContainerTest::initialize() ...");

		this.mRscene.initialize();
		this.initEvent();
		this.initScene();
	}
	private initEvent(): void {
		const rc = this.mRscene;
		rc.addEventListener(MouseEvent.MOUSE_DOWN, this, this.mouseDown);
		new MouseInteraction().initialize(rc, 0, false).setAutoRunning(true);
	}

	private mouseDown(evt: MouseEvent): void {
		console.log("mousedown evt call ...");
	}
	private createMaterial(shdSrc: WGRShderSrcType, texDatas?: WGImage2DTextureData[], color?: Color4, blendModes: string[] = ["solid"], faceCullMode = "back"): WGMaterial {

		color = color ? color : new Color4();

		let pipelineDefParam = {
			depthWriteEnabled: true,
			faceCullMode,
			blendModes: [] as string[]
		};


		pipelineDefParam.blendModes = blendModes;

		const texTotal = texDatas ? texDatas.length : 0;

		const material = new WGMaterial({
			shadinguuid: "base-material-tex" + texTotal,
			shaderCodeSrc: shdSrc,
			pipelineDefParam
		});

		let ufv = new WGRStorageValue(new Float32Array([color.r, color.g, color.b, 1]));
		material.uniformValues = [ufv];
		material.addTextureWithDatas(texDatas);

		return material;
	}

	private createGeom(rgd: GeomRDataType, normalEnabled = false): WGGeometry {
		const geometry = new WGGeometry()
			.addAttribute({ shdVarName: "position", data: rgd.vs, strides: [3] })
			.addAttribute({ shdVarName: "uv", data: rgd.uvs, strides: [2] })
			.setIndexBuffer({ name: "geomIndex", data: rgd.ivs });
		if (normalEnabled) {
			geometry.addAttribute({ shdVarName: "normal", data: rgd.nvs, strides: [3] });
		}
		return geometry;
	}
	private mContainers: Entity3DContainer[] = [];
	private createCircle(radius: number, total: number, scale: number, materials: WGMaterial[], geometry: WGGeometry, pv?: Vector3): Entity3DContainer {

		const rc = this.mRscene;

		pv = pv ? pv : new Vector3();

		let mContainer = new Entity3DContainer();
		mContainer.setPosition(pv);
		for (let i = 0; i < total; ++i) {
			const factor = i / total;
			const rad = Math.PI * 2.0 * factor;
			const px = radius * Math.cos(rad);
			const py = radius * Math.sin(rad);

			let entity = new Entity3D();
			entity.materials = materials;
			entity.geometry = geometry;
			entity.transform.setXYZ(px, py, 0);
			entity.transform.setRotationZ(factor * 360.0);
			entity.transform.setScaleAll(scale);

			mContainer.addChild(entity);
		}
		return mContainer;
	}
	private initScene(): void {

		const rc = this.mRscene;

		const geometry = this.createGeom(this.geomData.createCube(80));

		const shdSrc = {
			vertShaderSrc: { code: vertWGSL, uuid: "vertShdCode" },
			fragShaderSrc: { code: fragWGSL, uuid: "fragShdCode" }
		};
		let materials0 = [this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/box.jpg")], new Color4(1.0, 0.0, 0.0))];
		let materials1 = [this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/box.jpg")], new Color4(0.0, 1.0, 0.0))];
		let materials2 = [this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/box.jpg")], new Color4(1.0, 0.0, 1.0))];

		const container0 = this.createCircle(100, 10, 0.5, materials0, geometry);
		const container1 = this.createCircle(180, 15, 0.5, materials1, geometry);
		const container2 = this.createCircle(260, 25, 0.5, materials2, geometry);

		let container = new Entity3DContainer();
		container.addChild(container0);
		container.addChild(container1);
		container.addChild(container2);
		rc.addEntity(container);

		this.mContainers.push(container0, container1, container2, container);
	}

	private mRotValue = 0.0;
	run(): void {

		this.mRotValue += 0.5;

		const ls = this.mContainers;
		ls[0].setRotationZ(this.mRotValue * 1.2);
		ls[1].setRotationZ(this.mRotValue * 0.4 + 15.0);
		ls[2].setRotationZ(this.mRotValue * 0.2 + 30.0);
		ls[3].setRotationY(this.mRotValue * 0.2);
		ls[3].update();

		this.mRscene.run();
	}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1151986.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Doris数据库FE——全局事务状态机

begin; create database db1; ERROR 1105 (HY000): TException, msg: org.apache.thrift.TException: This is in a transaction, only insert, commit, rollback is acceptable从上述报错可以看出begin、commit、rollback等操作只有和insert操作结合使用。从上述可以猜测Doris…

【腾学汇的第1个实验代码】应用Matplotlib绘制图标分析

import matplotlib.pyplot as plt import numpy as np #Jupter Notebook 里面显示图片 %matplotlib inline#1.1.1 线形图 np.random.seed(42) #产生随机种子 y np.random.randn(30) #产生随机数 plt.plot(y, "r--o")#绘图&#xff1a;红色--虚线--圆形# 1.1.2 线条颜…

【【哈希应用】位图/布隆过滤器】

位图/布隆过滤器 位图位图概念位图的使用位图模拟实现 布隆过滤器布隆过滤器概念布隆过滤器的使用布隆过滤器模拟实现 位图/布隆过滤器应用&#xff1a;海量数据处理哈希切分 位图 位图概念 计算机中通常以位bit为数据最小存储单位&#xff0c;只有0、1两种二进制状态&#x…

2D网页游戏开发引擎

2D网页开发引擎是用于创建富有交互性和动画效果的2D网页应用程序的工具。以下是一些常用的2D网页开发引擎以及它们的主要特点&#xff0c;希望对大家有所帮助。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#xff0c;欢迎交流合作。 1.Phaser&#xff1a; P…

【ES专题】ElasticSearch快速入门

目录 前言从一个【搜索】说起 阅读对象前置知识笔记正文一、全文检索1.1 什么是【全文检索】1.2 【全文检索】原理1.3 什么是倒排索引 二、ElasticSearch简介2.1 ElasticSearch介绍2.2 ElasticSearch应用场景2.3 数据库横向对比 三、ElasticSearch环境搭建3.1 Windows下安装3.2…

Qlik Sense Enterprise 忘记PostgreSQL密码

在 Windows 上安装 Qlik Sense Enterprise 期间会提供密码。如果您忘记了该密码&#xff0c;则无法找回&#xff1b;但是&#xff0c;可以按照以下步骤重置密码。 如何在 Qlik 中重置忘记的 PostgreSQL 密码... - Qlik Community - 1712725 如果该过程完成后记录了密码错误的…

Java架构师面向对象技术建模

目录 1 导学2 面向对象开发2.1 面向对象需求建模2.2 面向对象的设计原则3 统一建模语言UML4 设计模式想学习架构师构建流程请跳转:Java架构师系统架构设计 1 导学 2 面向对象开发 对象:由数据及其操作所构成的封装体,是系统中用来描述客观事务的个实体,是构成系统的一个基…

yolov5 pt转成nccn_yolov5

一&#xff1a;转换环境准备 python版本为Python 3.8.0&#xff0c;需要安装对应的版本包&#xff0c;torch1.10.0 torchvision0.11.0 torchaudio0.10.0 pip3 install torch1.10.0 torchvision0.11.0 torchaudio0.10.0 -f https://download.pytorch.org/whl/torch_stable.html…

小红书平台用户数据分析与可视化

管理器、网页下载器、网页解析器、输出管理器这四个模块去搭建一个爬虫框架&#xff0c;将爬虫流程统一化&#xff0c;将通用的功能进行抽象&#xff0c;减少重复工作。要求实现的爬虫框架可以进行分布式爬取&#xff0c;解决爬虫的统一调度和统一去重&#xff0c;以及存储问题…

Ceph入门到精通-bluestore IO流程及导入导出

bluestore 直接管理裸设备&#xff0c;实现在用户态下使用linux aio直接对裸设备进行I/O操作 写IO流程&#xff1a; 一个I/O在bluestore里经历了多个线程和队列才最终完成&#xff0c;对于非WAL的写&#xff0c;比如对齐写、写到新的blob里等&#xff0c;I/O先写到块设备上&am…

Mybatis 多对一和一对多查询

文章目录 Mybatis 多对一 and 一对多查询详解数据库需求Mybatis代码注意 Mybatis 多对一 and 一对多查询详解 数据库 员工表 t_emp 部门表 t_dept CREATE TABLE t_emp (emp_id int NOT NULL AUTO_INCREMENT,emp_name varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci…

2023年华为云双11有什么优惠活动?详细攻略来了!

随着双十一的临近&#xff0c;华为云也开启了双11大促&#xff0c;推出了“华为云11.11”活动&#xff0c;那么&#xff0c;2023年华为云双11的优惠活动究竟有哪些呢&#xff1f;本文将为大家详细介绍。 一、华为云双11活动入口 活动地址&#xff1a;点此直达 二、华为云双11…

DSP 开发例程(5): tcp_server

目录 DSP 开发例程(5): tcp_server创建工程源码编辑tcp_echo.chelloWorld.c 调试说明 DSP 开发例程(5): tcp_server 此例程实现在 EVM6678L 开发板上创建 TCP Server进程, 完成计算机与开发板之间的 TCP/IP 通信. 例程源码可从我的 gitee 仓库上克隆或下载. 点击 DSP 开发教程…

JAVA基础(JAVA SE)学习笔记(十)多线程

前言 1. 学习视频&#xff1a; 尚硅谷Java零基础全套视频教程(宋红康2023版&#xff0c;java入门自学必备)_哔哩哔哩_bilibili 2023最新Java学习路线 - 哔哩哔哩 第三阶段&#xff1a;Java高级应用 9.异常处理 10.多线程 11.常用类和基础API 12.集合框架 13.泛型 14…

浅谈js代码的封装方法(2023.10.30)

常见的js代码封装方法 2023.10.30 需求1、js代码封装的优缺点2、js代码封装方式2.1 方式一&#xff1a;function function declarations2.1.1 示例 2.2 方式二&#xff1a;class2.2.1 class declarations2.2.2 Class expressions 2.3 变量函数2.4 变量闭包匿名函数2.5 闭包函数…

TiDB 企业版全新升级,平凯数据库核心特性全解读

作为 TiDB 企业版的全新升级&#xff0c;平凯数据库一经推出便广受媒体及用户关注。 近日&#xff0c;平凯星辰首席科学家丁岩在“平凯数据库全解读”活动中&#xff0c;首次详细介绍了平凯数据库的核心能力。 本文为丁岩演讲实录全文&#xff0c;为方便阅读&#xff0c;已做部…

[激光原理与应用-72]:PLC架构与工作原理

目录 一、PLC简介 1.1 概述 1.2 基本组成 1.3 常见的PLC品牌比较 二、PLC程序执行原理 2.1 PLC有操作系统吗&#xff1f; 2.2 PLC程序执行 2.3 PLC编程语言 2.4 PLC编程过程 三、PLC编程工具 3.1 编程工具 四、PLC与工控机协同 4.1 PLC需要配置工控机吗&#xff1…

构建Web UI自动化测试平台

您好&#xff0c; 如果喜欢我的文章或者想上岸大厂&#xff0c;可以关注公众号「量子前端」&#xff0c;将不定期关注推送前端好文、分享就业资料秘籍&#xff0c;也希望有机会一对一帮助你实现梦想 前言 什么是前端UI自动化测试平台&#xff1f;由于部门的业务域非常广&…

HCIP——MGRE实验

一、实验要求 1.R5为ISP&#xff0c;只能进行IP地址配置&#xff1b;其所有地址均为公有IP地址 2.R1和R5间使用PPP的PAP认证&#xff0c;R5为主认证方&#xff1b; R2与R5之间使用PPP的chap认证&#xff0c;R5为主认证方&#xff1b; R3与R5之间使用HDLC封装。 3.R1/R2/R3…

纪念基于JavaScript 实现的后台桌面 UI 设计

目录 前言 C/S 到 B/S ASP Builder 的诞生 关于 Craneoffice.net 开发环境配置 后台界面的 UI 区域要素 桌面系统的想法和设计 搜索引擎 导航面板 快捷访问 二级导航 小组件及其它 设置桌面壁纸 小时钟 附件小程序 计算器界面设计 日历与任务 系统设置 天气小…