UNPKG

@loaders.gl/obj

Version:

Framework-independent loader for the OBJ format

36 lines 1.34 kB
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { getDataTypeFromArray } from '@loaders.gl/schema-utils'; /** Get Mesh Schema */ export function getOBJSchema(attributes, metadata = {}) { const stringMetadata = {}; for (const key in metadata) { if (key !== 'value') { stringMetadata[key] = JSON.stringify(metadata[key]); } } const fields = []; for (const attributeName in attributes) { const attribute = attributes[attributeName]; const field = getFieldFromAttribute(attributeName, attribute); fields.push(field); } return { fields, metadata: stringMetadata }; } /** Get a Field describing the column from an OBJ attribute */ function getFieldFromAttribute(name, attribute) { const metadata = {}; for (const key in attribute) { if (key !== 'value') { metadata[key] = JSON.stringify(attribute[key]); } } let { type } = getDataTypeFromArray(attribute.value); const isSingleValue = attribute.size === 1 || attribute.size === undefined; if (!isSingleValue) { type = { type: 'fixed-size-list', listSize: attribute.size, children: [{ name: 'values', type }] }; } return { name, type, nullable: false, metadata }; } //# sourceMappingURL=get-obj-schema.js.map