vim-format
Advanced tools
Comparing version 1.0.1 to 1.0.2-dev.0
@@ -8,6 +8,7 @@ /** | ||
end: number; | ||
get count(): number; | ||
get length(): number; | ||
constructor(start: number, end: number); | ||
offset(offset: number): Range; | ||
} | ||
export declare function typeSize(type: string): 1 | 2 | 4 | 8; | ||
/** | ||
@@ -72,6 +73,14 @@ * Bfast header, mainly for validation. | ||
getValue(name: string, index: number): Promise<number>; | ||
getRange(name: string): Promise<Range>; | ||
/** | ||
* Returns the buffer with given name as a byte array | ||
* Returns a single value from given buffer name | ||
* @param name buffer name | ||
* @param index row index | ||
*/ | ||
getValues(name: string, index: number, count: number): Promise<Int8Array | Int16Array | Int32Array | Float32Array | Float64Array>; | ||
/** | ||
* Returns the buffer with given name as a byte array | ||
* @param name buffer name | ||
*/ | ||
getBytes(name: string): Promise<Uint8Array>; | ||
@@ -78,0 +87,0 @@ /** |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BFast = exports.BFastHeader = exports.Range = void 0; | ||
exports.BFast = exports.BFastHeader = exports.typeSize = exports.Range = void 0; | ||
const remoteValue_1 = require("./remoteValue"); | ||
@@ -24,3 +24,3 @@ const remoteBuffer_1 = require("./remoteBuffer"); | ||
} | ||
get count() { | ||
get length() { | ||
return this.end - this.start; | ||
@@ -49,2 +49,3 @@ } | ||
} | ||
exports.typeSize = typeSize; | ||
function typeConstructor(type) { | ||
@@ -203,10 +204,33 @@ switch (type) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const array = yield this.getValues(name, index, 1); | ||
return array === null || array === void 0 ? void 0 : array[0]; | ||
}); | ||
} | ||
getRange(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const ranges = yield this.getRanges(); | ||
const range = ranges.get(name); | ||
return ranges.get(name); | ||
}); | ||
} | ||
/** | ||
* Returns a single value from given buffer name | ||
* @param name buffer name | ||
* @param index row index | ||
*/ | ||
getValues(name, index, count) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (index < 0 || count < 1) | ||
return; | ||
const range = yield this.getRange(name); | ||
if (!range) | ||
return; | ||
//Could be done in-place. | ||
const type = name.split(':')[0]; | ||
const size = typeSize(type); | ||
const start = range.start + index * size; | ||
const buffer = yield this.request(new Range(start, start + size), `${name}[${index.toString()}]`); | ||
const start = Math.min(range.start + index * size, range.end); | ||
const end = Math.min(start + size * count, range.end); | ||
const dataRange = new Range(start, end); | ||
if (dataRange.length <= 0) | ||
return; | ||
const buffer = yield this.request(dataRange, `${name}[${index.toString()}]`); | ||
if (!buffer) | ||
@@ -216,9 +240,10 @@ return; | ||
const array = new Ctor(buffer); | ||
return array[0]; | ||
return array; | ||
}); | ||
} | ||
/** | ||
* Returns the buffer with given name as a byte array | ||
* @param name buffer name | ||
*/ | ||
* Returns the buffer with given name as a byte array | ||
* @param name buffer name | ||
*/ | ||
getBytes(name) { | ||
@@ -345,3 +370,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
if (buffer.byteLength > range.count) { | ||
if (buffer.byteLength > range.length) { | ||
this.source = buffer; | ||
@@ -373,3 +398,3 @@ return this.local(range, label); | ||
const buffer = yield this.source.http(r, `${this.name}.${label}`); | ||
if (range && ((_a = buffer === null || buffer === void 0 ? void 0 : buffer.byteLength) !== null && _a !== void 0 ? _a : 0) < range.count) { | ||
if (range && ((_a = buffer === null || buffer === void 0 ? void 0 : buffer.byteLength) !== null && _a !== void 0 ? _a : 0) < range.length) { | ||
console.log('Range request request failed.'); | ||
@@ -376,0 +401,0 @@ return; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -5,3 +5,3 @@ /** | ||
import { BFast } from './bfast'; | ||
declare class G3dAttributeDescriptor { | ||
export declare class G3dAttributeDescriptor { | ||
description: string; | ||
@@ -18,4 +18,4 @@ association: string; | ||
export declare type MeshSection = 'opaque' | 'transparent' | 'all'; | ||
declare type TypedArray = Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Uint32Array | Float64Array; | ||
declare class G3dAttribute { | ||
export declare type TypedArray = Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Uint32Array | Float64Array; | ||
export declare class G3dAttribute { | ||
descriptor: G3dAttributeDescriptor; | ||
@@ -33,3 +33,3 @@ bytes: Uint8Array; | ||
*/ | ||
declare class AbstractG3d { | ||
export declare class AbstractG3d { | ||
meta: string; | ||
@@ -45,2 +45,17 @@ attributes: G3dAttribute[]; | ||
/** | ||
* See https://github.com/vimaec/vim#vim-geometry-attributes | ||
*/ | ||
export declare class VimAttributes { | ||
static positions: string; | ||
static indices: string; | ||
static instanceMeshes: string; | ||
static instanceTransforms: string; | ||
static instanceFlags: string; | ||
static meshSubmeshes: string; | ||
static submeshIndexOffsets: string; | ||
static submeshMaterials: string; | ||
static materialColors: string; | ||
static all: string[]; | ||
} | ||
/** | ||
* G3D is a simple, efficient, generic binary format for storing and transmitting geometry. | ||
@@ -74,2 +89,3 @@ * The G3D format is designed to be used either as a serialization format or as an in-memory data structure. | ||
constructor(g3d: AbstractG3d); | ||
static createFromBfast(bfast: BFast): Promise<G3d>; | ||
/** | ||
@@ -118,2 +134,3 @@ * Computes the index of the first vertex of each mesh | ||
private computeMeshOpaqueCount; | ||
slice(instance: number): G3d; | ||
getVertexCount: () => number; | ||
@@ -171,5 +188,3 @@ getMeshCount: () => number; | ||
getMaterialAlpha(material: number): number; | ||
static createFromBfast(bfast: BFast): Promise<G3d>; | ||
validate(): void; | ||
} | ||
export {}; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.G3d = void 0; | ||
exports.G3d = exports.VimAttributes = exports.AbstractG3d = exports.G3dAttribute = exports.G3dAttributeDescriptor = void 0; | ||
class G3dAttributeDescriptor { | ||
@@ -44,2 +44,3 @@ constructor(description, association, semantic, attributeTypeIndex, dataType, dataArity) { | ||
} | ||
exports.G3dAttributeDescriptor = G3dAttributeDescriptor; | ||
class G3dAttribute { | ||
@@ -81,2 +82,3 @@ constructor(descriptor, bytes) { | ||
} | ||
exports.G3dAttribute = G3dAttribute; | ||
/** | ||
@@ -112,2 +114,3 @@ * G3D is a simple, efficient, generic binary format for storing and transmitting geometry. | ||
} | ||
exports.AbstractG3d = AbstractG3d; | ||
/** | ||
@@ -118,2 +121,3 @@ * See https://github.com/vimaec/vim#vim-geometry-attributes | ||
} | ||
exports.VimAttributes = VimAttributes; | ||
VimAttributes.positions = 'g3d:vertex:position:0:float32:3'; | ||
@@ -201,2 +205,7 @@ VimAttributes.indices = 'g3d:corner:index:0:int32:1'; | ||
} | ||
static createFromBfast(bfast) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return AbstractG3d.createFromBfast(bfast).then((g3d) => new G3d(g3d)); | ||
}); | ||
} | ||
/** | ||
@@ -362,2 +371,64 @@ * Computes the index of the first vertex of each mesh | ||
} | ||
slice(instance) { | ||
const attributes = []; | ||
const matrix = this.instanceTransforms.slice(instance * 16, (instance + 1) * 16); | ||
const mesh = this.instanceMeshes[instance]; | ||
const flags = this.instanceFlags[instance]; | ||
const _instanceTransforms = new Float32Array([...matrix]); | ||
const _instanceMeshes = new Int32Array([mesh >= 0 ? 0 : -1]); | ||
const _instanceFlags = new Uint16Array([flags]); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.instanceTransforms, new Uint8Array(_instanceTransforms.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.instanceFlags, new Uint8Array(_instanceFlags.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.instanceMeshes, new Uint8Array(_instanceMeshes.buffer))); | ||
if (mesh >= 0) { | ||
const _meshSubmeshes = new Int32Array([0]); | ||
// Submeshes | ||
const submeshStart = this.getMeshSubmeshStart(mesh); | ||
const submeshEnd = this.getMeshSubmeshEnd(mesh); | ||
const originalOffsets = this.submeshIndexOffset.slice(submeshStart, submeshEnd); | ||
const firstOffset = originalOffsets[0]; | ||
const _submeshIndexOffsets = originalOffsets.map(i => i - firstOffset); | ||
// Vertices | ||
const _indices = this.indices.slice(this.getMeshIndexStart(mesh), this.getMeshIndexEnd(mesh)); | ||
const _vertices = this.positions.slice(this.getMeshVertexStart(mesh) * 3, this.getMeshVertexEnd(mesh) * 3); | ||
// Compile used materials and remap. | ||
const originalSubmeshMaterials = this.submeshMaterial.slice(submeshStart, submeshEnd); | ||
const map = new Map(); | ||
originalSubmeshMaterials.forEach((m, i) => { | ||
var _a; | ||
if (m >= 0) { | ||
const set = (_a = map.get(m)) !== null && _a !== void 0 ? _a : []; | ||
set.push(i); | ||
map.set(m, set); | ||
} | ||
}); | ||
const _submeshMaterials = new Int32Array(map.size); | ||
const materialColors = []; | ||
let i = 0; | ||
map.forEach((set, mat) => __awaiter(this, void 0, void 0, function* () { | ||
const color = this.materialColors.slice(mat * 4, mat * 4 + 4); | ||
color.forEach(v => materialColors.push(v)); | ||
set.forEach((s) => _submeshMaterials[i] = i); | ||
i++; | ||
})); | ||
const _materialColors = new Float32Array(materialColors); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.meshSubmeshes, new Uint8Array(_meshSubmeshes.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.submeshIndexOffsets, new Uint8Array(_submeshIndexOffsets.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.indices, new Uint8Array(_indices.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.positions, new Uint8Array(_vertices.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.submeshMaterials, new Uint8Array(_submeshMaterials.buffer))); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.materialColors, new Uint8Array(_materialColors.buffer))); | ||
} | ||
else { | ||
attributes.push(G3dAttribute.fromString(VimAttributes.meshSubmeshes, new Uint8Array())); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.submeshIndexOffsets, new Uint8Array())); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.submeshMaterials, new Uint8Array())); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.indices, new Uint8Array())); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.positions, new Uint8Array())); | ||
attributes.push(G3dAttribute.fromString(VimAttributes.materialColors, new Uint8Array())); | ||
} | ||
const abstract = new AbstractG3d('woot', attributes); | ||
const g3d = new G3d(abstract); | ||
return g3d; | ||
} | ||
getMeshIndexStart(mesh, section = 'all') { | ||
@@ -398,3 +469,3 @@ const sub = this.getMeshSubmeshStart(mesh, section); | ||
? this.meshSubmeshes[mesh + 1] | ||
: this.submeshIndexOffset.length; | ||
: this.getSubmeshCount(); | ||
} | ||
@@ -448,3 +519,3 @@ getMeshSubmeshCount(mesh, section = 'all') { | ||
getSubmeshCount() { | ||
return this.submeshMaterial.length; | ||
return this.submeshIndexOffset.length; | ||
} | ||
@@ -481,7 +552,2 @@ /** | ||
} | ||
static createFromBfast(bfast) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return AbstractG3d.createFromBfast(bfast).then((g3d) => new G3d(g3d)); | ||
}); | ||
} | ||
validate() { | ||
@@ -488,0 +554,0 @@ const isPresent = (attribute, label) => { |
@@ -0,0 +0,0 @@ export * from './bfast'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "vim-format", | ||
"version": "1.0.1", | ||
"version": "1.0.2-dev.0", | ||
"description": "The VIM format is a modern and efficient open 3D data interchange format designed for BIM and manufacturing data optimized for efficient loading and rendering on low-power devices.", | ||
@@ -5,0 +5,0 @@ "directories": { |
# vim-ts | ||
VIM TypeScript Implementation |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
506628
27
11256
2
1