This commit is contained in:
kacper 2026-03-06 22:51:19 -05:00
parent 6acf267d48
commit b7614eb3f8
4794 changed files with 1280808 additions and 1546 deletions

View file

@ -0,0 +1,77 @@
import DataMap from './DataMap.js';
import { AttributeType } from './Constants.js';
import { DynamicDrawUsage } from 'three';
class Attributes extends DataMap {
constructor( backend ) {
super();
this.backend = backend;
}
delete( attribute ) {
const attributeData = super.delete( attribute );
if ( attributeData !== undefined ) {
this.backend.destroyAttribute( attribute );
}
return attributeData;
}
update( attribute, type ) {
const data = this.get( attribute );
if ( data.version === undefined ) {
if ( type === AttributeType.VERTEX ) {
this.backend.createAttribute( attribute );
} else if ( type === AttributeType.INDEX ) {
this.backend.createIndexAttribute( attribute );
} else if ( type === AttributeType.STORAGE ) {
this.backend.createStorageAttribute( attribute );
}
data.version = this._getBufferAttribute( attribute ).version;
} else {
const bufferAttribute = this._getBufferAttribute( attribute );
if ( data.version < bufferAttribute.version || bufferAttribute.usage === DynamicDrawUsage ) {
this.backend.updateAttribute( attribute );
data.version = bufferAttribute.version;
}
}
}
_getBufferAttribute( attribute ) {
if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
return attribute;
}
}
export default Attributes;