sunag 11 месяцев назад
Родитель
Сommit
4de68d2a02
3 измененных файлов с 77 добавлено и 0 удалено
  1. 1 0
      examples/webgpu_compute_particles.html
  2. 28 0
      src/nodes/core/StructNode.js
  3. 48 0
      src/nodes/core/StructTypeNode.js

+ 1 - 0
examples/webgpu_compute_particles.html

@@ -227,6 +227,7 @@
 				// events
 				// events
 
 
 				renderer.domElement.addEventListener( 'pointermove', onMove );
 				renderer.domElement.addEventListener( 'pointermove', onMove );
+
 				//
 				//
 
 
 				controls = new OrbitControls( camera, renderer.domElement );
 				controls = new OrbitControls( camera, renderer.domElement );

+ 28 - 0
src/nodes/core/StructNode.js

@@ -4,6 +4,26 @@ import { nodeObject } from '../tsl/TSLCore.js';
 
 
 /** @module StructNode **/
 /** @module StructNode **/
 
 
+/**
+ * StructNode allows to create custom structures with multiple members.
+ * This can also be used to define structures in attribute and uniform data.
+ *
+ * ```js
+ * // Define a custom struct
+ * const BoundingBox = struct( { min: 'vec3', max: 'vec3' } );
+ *
+ * // Create a new instance of the struct
+ * const bb = BoundingBox( vec3( 0 ), vec3( 1 ) ); // style 1
+ * const bb = BoundingBox( { min: vec3( 0 ), max: vec3( 1 ) } ); // style 2
+ *
+ * // Access the struct members
+ * const min = bb.get( 'min' );
+ *
+ * // Assign a new value to a member
+ * min.assign( vec3() );
+ * ```
+ * @augments Node
+ */
 class StructNode extends Node {
 class StructNode extends Node {
 
 
 	static get type() {
 	static get type() {
@@ -51,6 +71,14 @@ class StructNode extends Node {
 
 
 export default StructNode;
 export default StructNode;
 
 
+/**
+ * TSL function for creating a struct node.
+ *
+ * @function
+ * @param {Object} membersLayout - The layout of the struct members.
+ * @param {string} [name=null] - The name of the struct.
+ * @returns {Function} The struct function.
+ */
 export const struct = ( membersLayout, name = null ) => {
 export const struct = ( membersLayout, name = null ) => {
 
 
 	const structLayout = new StructTypeNode( membersLayout, name );
 	const structLayout = new StructTypeNode( membersLayout, name );

+ 48 - 0
src/nodes/core/StructTypeNode.js

@@ -1,8 +1,17 @@
+
 import Node from './Node.js';
 import Node from './Node.js';
 import { getLengthFromType } from './NodeUtils.js';
 import { getLengthFromType } from './NodeUtils.js';
 
 
 /** @module StructTypeNode **/
 /** @module StructTypeNode **/
 
 
+/**
+ * Generates a layout for struct members.
+ * This function takes an object representing struct members and returns an array of member layouts.
+ * Each member layout includes the member's name, type, and whether it is atomic.
+ *
+ * @param {Object.<string, string|Object>} members - An object where keys are member names and values are either types (as strings) or objects with type and atomic properties.
+ * @returns {Array.<{name: string, type: string, atomic: boolean}>} An array of member layouts.
+ */
 function getMembersLayout( members ) {
 function getMembersLayout( members ) {
 
 
 	return Object.entries( members ).map( ( [ name, value ] ) => {
 	return Object.entries( members ).map( ( [ name, value ] ) => {
@@ -19,6 +28,14 @@ function getMembersLayout( members ) {
 
 
 }
 }
 
 
+/**
+ * Represents a struct type node in the node-based system.
+ * This class is used to define and manage the layout and types of struct members.
+ * It extends the base Node class and provides methods to get the length of the struct,
+ * retrieve member types, and generate the struct type for a builder.
+ *
+ * @augments Node
+ */
 class StructTypeNode extends Node {
 class StructTypeNode extends Node {
 
 
 	static get type() {
 	static get type() {
@@ -27,17 +44,48 @@ class StructTypeNode extends Node {
 
 
 	}
 	}
 
 
+	/**
+	 * Creates an instance of StructTypeNode.
+	 *
+	 * @param {Object} membersLayout - The layout of the members for the struct.
+	 * @param {string} [name=null] - The optional name of the struct.
+	 */
 	constructor( membersLayout, name = null ) {
 	constructor( membersLayout, name = null ) {
 
 
 		super( 'struct' );
 		super( 'struct' );
 
 
+		/**
+		 * The layout of the members for the struct
+		 *
+		 * @type {Array.<{name: string, type: string, atomic: boolean}>}
+		 */
 		this.membersLayout = getMembersLayout( membersLayout );
 		this.membersLayout = getMembersLayout( membersLayout );
+
+		/**
+		 * The name of the struct.
+		 *
+		 * @type {String}
+		 * @default null
+		 */
 		this.name = name;
 		this.name = name;
 
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isStructLayoutNode = true;
 		this.isStructLayoutNode = true;
 
 
 	}
 	}
 
 
+	/**
+	 * Returns the length of the struct.
+	 * The length is calculated by summing the lengths of the struct's members.
+	 *
+	 * @returns {Number} The length of the struct.
+	 */
 	getLength() {
 	getLength() {
 
 
 		let length = 0;
 		let length = 0;

粤ICP备19079148号