141 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			141 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { Color, Matrix3, Matrix4, Vector2, Vector3, Vector4 } from 'three';
 | |
| 
 | |
| class Uniform {
 | |
| 
 | |
| 	constructor( name, value = null ) {
 | |
| 
 | |
| 		this.name = name;
 | |
| 		this.value = value;
 | |
| 
 | |
| 		this.boundary = 0; // used to build the uniform buffer according to the STD140 layout
 | |
| 		this.itemSize = 0;
 | |
| 
 | |
| 		this.offset = 0; // this property is set by WebGPUUniformsGroup and marks the start position in the uniform buffer
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 	setValue( value ) {
 | |
| 
 | |
| 		this.value = value;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 	getValue() {
 | |
| 
 | |
| 		return this.value;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class FloatUniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = 0 ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isFloatUniform = true;
 | |
| 
 | |
| 		this.boundary = 4;
 | |
| 		this.itemSize = 1;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class Vector2Uniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Vector2() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isVector2Uniform = true;
 | |
| 
 | |
| 		this.boundary = 8;
 | |
| 		this.itemSize = 2;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class Vector3Uniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Vector3() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isVector3Uniform = true;
 | |
| 
 | |
| 		this.boundary = 16;
 | |
| 		this.itemSize = 3;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class Vector4Uniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Vector4() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isVector4Uniform = true;
 | |
| 
 | |
| 		this.boundary = 16;
 | |
| 		this.itemSize = 4;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class ColorUniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Color() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isColorUniform = true;
 | |
| 
 | |
| 		this.boundary = 16;
 | |
| 		this.itemSize = 3;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class Matrix3Uniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Matrix3() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isMatrix3Uniform = true;
 | |
| 
 | |
| 		this.boundary = 48;
 | |
| 		this.itemSize = 12;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| class Matrix4Uniform extends Uniform {
 | |
| 
 | |
| 	constructor( name, value = new Matrix4() ) {
 | |
| 
 | |
| 		super( name, value );
 | |
| 
 | |
| 		this.isMatrix4Uniform = true;
 | |
| 
 | |
| 		this.boundary = 64;
 | |
| 		this.itemSize = 16;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| export {
 | |
| 	FloatUniform,
 | |
| 	Vector2Uniform, Vector3Uniform, Vector4Uniform, ColorUniform,
 | |
| 	Matrix3Uniform, Matrix4Uniform
 | |
| };
 |