From fddb95dc3149a739bdef30817d828691942aa2eb Mon Sep 17 00:00:00 2001 From: Tarek Sherif Date: Thu, 4 Apr 2019 17:07:27 -0400 Subject: [PATCH] Model handles geometry with constant attributes --- modules/core/src/core/model-utils.js | 18 ++++++++++++------ modules/core/src/core/model.js | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/core/src/core/model-utils.js b/modules/core/src/core/model-utils.js index b0e6bfc9b6..e7a0581c85 100644 --- a/modules/core/src/core/model-utils.js +++ b/modules/core/src/core/model-utils.js @@ -16,14 +16,20 @@ export function getBuffersFromGeometry(gl, geometry, options) { const buffers = {}; for (const name in geometry.attributes) { - const typedArray = geometry.attributes[name].value; - // Create accessor by copying the attribute and removing `value`` - const attribute = {...geometry.attributes[name]}; - delete attribute.value; + const attribute = geometry.attributes[name]; const remappedName = mapAttributeName(name, options); - buffers[remappedName] = [new Buffer(gl, typedArray), attribute]; - inferAttributeAccessor(name, attribute); + if (attribute.constant) { + buffers[remappedName] = attribute.value; + } else { + const typedArray = attribute.value; + // Create accessor by copying the attribute and removing `value`` + const accessor = {...attribute}; + delete accessor.value; + buffers[remappedName] = [new Buffer(gl, typedArray), accessor]; + + inferAttributeAccessor(name, accessor); + } } if (geometry.indices) { diff --git a/modules/core/src/core/model.js b/modules/core/src/core/model.js index 1c6dc6cd82..2ac27262d5 100644 --- a/modules/core/src/core/model.js +++ b/modules/core/src/core/model.js @@ -1,5 +1,5 @@ import GL from '@luma.gl/constants'; -import {Query, TransformFeedback} from '@luma.gl/webgl'; +import {Query, TransformFeedback, Buffer} from '@luma.gl/webgl'; import {getBuffersFromGeometry} from './model-utils'; import BaseModel from './base-model'; import {log, isObjectEmpty, uid, assert} from '../utils'; @@ -183,7 +183,9 @@ export default class Model extends BaseModel { for (const name in this.geometryBuffers) { // Buffer is raw value (for indices) or first element of [buffer, accessor] pair const buffer = this.geometryBuffers[name][0] || this.geometryBuffers[name]; - buffer.delete(); + if (buffer instanceof Buffer) { + buffer.delete(); + } } }