Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTF Serializer rework. #15869

Merged
Merged
Show file tree
Hide file tree
Changes from 134 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
6b903c9
WIP
bghgary Oct 2, 2024
11ccb22
Merge with Garys PR
SergioRZMasson Oct 7, 2024
ebac165
Added triangle re-ordering logic
SergioRZMasson Oct 7, 2024
7bc831e
Updated index logic to flip based on coordinate system
SergioRZMasson Oct 7, 2024
c87e0ff
Added camera support
SergioRZMasson Oct 8, 2024
4acc5b6
Added camera export
SergioRZMasson Oct 8, 2024
c43aedb
Started adding support for skeleton
SergioRZMasson Oct 8, 2024
1bdb0ba
Remove cameras that are not assigned to nodes
SergioRZMasson Oct 9, 2024
04de555
Added logic to not include empty or unused skins
SergioRZMasson Oct 9, 2024
b0091a3
Got skeleton working
SergioRZMasson Oct 15, 2024
ec11a57
Merge branch 'master' of https://github.com/SergioRZMasson/Babylon.js…
SergioRZMasson Oct 15, 2024
b201c4d
Reverted changes to glTFLoader
SergioRZMasson Oct 15, 2024
ba01797
Added support for animations
SergioRZMasson Oct 16, 2024
0d7a705
Added animation support
Oct 16, 2024
1cc8964
Changed triangle flipping to XOR operator
SergioRZMasson Oct 16, 2024
6d45c54
Added initial convertion to right hand mode for animation
SergioRZMasson Oct 16, 2024
d92181c
Added right hand transformation for rotation animation
SergioRZMasson Oct 18, 2024
b6658d9
Got morph targets to work
SergioRZMasson Oct 23, 2024
3f5f480
Got morph to export with no errors
SergioRZMasson Oct 23, 2024
c8b913c
Solved handyness problem
SergioRZMasson Oct 24, 2024
5969278
Init WIP
alexchuber Oct 25, 2024
39263db
Add back glTF.extensions initialization
alexchuber Oct 25, 2024
81edf35
Add directional light test
alexchuber Oct 28, 2024
5f8cd2c
Changed position calculation to match old implementation
SergioRZMasson Oct 28, 2024
350be47
Removed unecessary comments
SergioRZMasson Oct 28, 2024
d825911
replace comment
alexchuber Oct 28, 2024
dede9b6
Merge branch 'master' of https://github.com/SergioRZMasson/Babylon.js…
SergioRZMasson Oct 30, 2024
3cd41f4
Fixed mesh flipping and removed scale flipping on animations
SergioRZMasson Oct 30, 2024
f70fce1
Update test
alexchuber Oct 30, 2024
9290362
Refactor lights - WIP
alexchuber Oct 30, 2024
313d3e9
Fixed skeleton animations and fixed indices flipping
SergioRZMasson Oct 31, 2024
650ae0f
Ensure nodes are skippable via postExportNodeAsync, and that parent n…
alexchuber Oct 31, 2024
54cacbd
Added logic to handle triangle flipping
SergioRZMasson Oct 31, 2024
943870a
Code cleanup, added missing code to push nodes to node table in the c…
SergioRZMasson Nov 1, 2024
34783e4
Fix skipping node at index 0; convert handiness of light WIP
alexchuber Nov 4, 2024
07dd1e2
Fix light rotation for both LH and RH
alexchuber Nov 4, 2024
7be933e
Fix possible empty children array (invalid glTF) if nodeIndex is null
alexchuber Nov 4, 2024
0d9aae3
Update vis tests for lights
alexchuber Nov 4, 2024
62eea7d
Merge remote-tracking branch 'sergio/sergio/new-gltf-exporter-2' into…
alexchuber Nov 4, 2024
930663f
Add specificity to light parent check
alexchuber Nov 4, 2024
b72975e
comments
alexchuber Nov 5, 2024
d8dab33
Ok, more comments
alexchuber Nov 5, 2024
bd4f274
Merge pull request #1 from alexchuber/ext-lights
SergioRZMasson Nov 12, 2024
b67e087
Added fix for camera roundtrip
SergioRZMasson Nov 12, 2024
2dc9a40
Fixed camera transformation based on parent
SergioRZMasson Nov 13, 2024
1c2ff00
Added camera roundtrip tests
SergioRZMasson Nov 13, 2024
7b8bfaf
Added validation tests for camera transform
SergioRZMasson Nov 13, 2024
710dd60
Make materialExporter public for extensions to use
alexchuber Nov 13, 2024
8d0029b
Make exportTextureAsync public (for now) for transmission
alexchuber Nov 13, 2024
61831d1
Restore all material/texture extensions to previous working state
alexchuber Nov 13, 2024
c44f379
Merge pull request #3 from alexchuber/uncomment-material-texture-exte…
SergioRZMasson Nov 14, 2024
f3afff1
Added possible fix to round trip
SergioRZMasson Nov 14, 2024
665a298
Merge branch 'sergio/new-gltf-exporter-2' into sergio/new-gltf-export…
SergioRZMasson Nov 14, 2024
6786e37
Fixed camera round trip
SergioRZMasson Nov 18, 2024
79b23a4
Fixed camera round trip
SergioRZMasson Nov 18, 2024
8149420
Finished camera work
SergioRZMasson Nov 18, 2024
7066164
Finished working on camera rotation
SergioRZMasson Nov 18, 2024
df96f49
Removed unecessary transform
SergioRZMasson Nov 18, 2024
4aed529
Fixed transforms, added proper test for left handed scene
SergioRZMasson Nov 18, 2024
308c580
Small cleanup
SergioRZMasson Nov 18, 2024
0593ced
Fixed tipos and removed comments
SergioRZMasson Nov 18, 2024
d512d55
Merge pull request #5 from SergioRZMasson/sergio/new-gltf-exporter-2-…
SergioRZMasson Nov 18, 2024
8120e53
wip
alexchuber Nov 18, 2024
50f3599
wip
alexchuber Nov 18, 2024
2e31915
Clean up
alexchuber Nov 19, 2024
d06ffb3
Added handle for linesMesh
SergioRZMasson Nov 19, 2024
1a6d77a
Added small change for fillMode when mesh is LinesMesh
SergioRZMasson Nov 19, 2024
16a9918
Factor out common variables; extra comments
alexchuber Nov 19, 2024
895f625
Count stdMaterials, not just non-stdMaterials, since not sure what ot…
alexchuber Nov 19, 2024
6cf9810
Remove casting to Color3/4, use separate Color3/4 variables
alexchuber Nov 19, 2024
23625d6
Remove int8 check, just need uint8
alexchuber Nov 19, 2024
fe053d1
remove unneeded comment
alexchuber Nov 19, 2024
5384a0d
Added support for GPU instancing
SergioRZMasson Nov 19, 2024
826aeeb
Got hand rotation working
SergioRZMasson Nov 19, 2024
efe1d2f
Merge branch 'sergio/new-gltf-exporter-2' into standard-material-vert…
alexchuber Nov 19, 2024
7cba726
Pass "should serialize empty Babylon window.scene to glTF with only a…
alexchuber Nov 20, 2024
ade6fcb
nit: remove skipNode, instead early return null
alexchuber Nov 20, 2024
a52a871
Pass all animation-related tests
alexchuber Nov 20, 2024
ed1deac
Pass all light-related tests
alexchuber Nov 20, 2024
4c35273
Update class and method names to pass metal-rough-related tests
alexchuber Nov 20, 2024
2ed44f0
Merge pull request #7 from alexchuber/restore-integration-tests
SergioRZMasson Nov 21, 2024
8398e5d
Merge pull request #6 from alexchuber/standard-material-vertex-colors
SergioRZMasson Nov 21, 2024
9a4655d
Add optional `normalized` to accessor factory
alexchuber Nov 21, 2024
c32f748
Use `normalized` when creating most accessors
alexchuber Nov 21, 2024
e04d827
Add test to export instances pointing to same mesh
alexchuber Nov 21, 2024
6c2cd44
Merge pull request #9 from alexchuber/instance-test
SergioRZMasson Nov 21, 2024
8ab7981
Merge pull request #8 from alexchuber/normalized-accessors
SergioRZMasson Nov 21, 2024
fe0e516
Removed old TODO
SergioRZMasson Nov 21, 2024
786ed2f
Merge branch 'sergio/new-gltf-exporter-2' of https://github.com/Sergi…
SergioRZMasson Nov 21, 2024
5298bbd
Fixed bad importing
SergioRZMasson Nov 21, 2024
90a2a4d
Fixed bad importing
SergioRZMasson Nov 21, 2024
7b16084
Changed interators to be complient with UMD
SergioRZMasson Nov 22, 2024
d2dc61d
Remove IMaterialExtension and its references
alexchuber Nov 22, 2024
435652e
Merge pull request #10 from alexchuber/remove-stale-IMaterialExtensio…
SergioRZMasson Nov 22, 2024
12094f8
Revert name change to copyFloatData
alexchuber Nov 22, 2024
8eeaef8
Merge pull request #11 from alexchuber/revert-name-change
SergioRZMasson Nov 22, 2024
e2fa453
Revert move of CopyFloatData import
alexchuber Nov 22, 2024
f20b84b
Modify iwt and iwr in-place
alexchuber Nov 22, 2024
ba0167b
Remove Nullable glTF object types from extension methods
alexchuber Nov 23, 2024
6753129
Use PascalCase for exported module-level functions
alexchuber Nov 23, 2024
41cef91
Remove unneeded normalize()
alexchuber Nov 23, 2024
166c88a
Remove properties in-place in OmitDefaultValues
alexchuber Nov 23, 2024
84ac1cf
Narrow types for DEFAULTS
alexchuber Nov 23, 2024
7ae5b78
Remove commented-out functions
alexchuber Nov 25, 2024
3c646b9
Merge pull request #12 from alexchuber/first-pass-small-files-fixes
SergioRZMasson Nov 25, 2024
88c86ea
Update packages/dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts
SergioRZMasson Nov 25, 2024
ab14b32
Update packages/dev/serializers/src/glTF/2.0/glTFAnimation.ts
SergioRZMasson Nov 25, 2024
d37023e
Update packages/dev/serializers/src/glTF/2.0/glTFMorphTargetsUtilitie…
SergioRZMasson Nov 25, 2024
cd4da13
Update packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
SergioRZMasson Nov 25, 2024
a63f7d9
Changed GlTFMorphTarget to interface
SergioRZMasson Nov 25, 2024
90bae64
Merge branch 'sergio/new-gltf-exporter-2' of https://github.com/Sergi…
SergioRZMasson Nov 25, 2024
fda7cf7
Fixed tipo
SergioRZMasson Nov 25, 2024
5be8cf2
Fixed comments on camera coordinates
SergioRZMasson Nov 25, 2024
f637d92
Changed exporter to automatically detect need for 16bit integers
SergioRZMasson Nov 25, 2024
a81af10
Fixed error when using const
SergioRZMasson Nov 25, 2024
a9ae8b2
Removed legacy comment
SergioRZMasson Nov 25, 2024
77e1369
Added test for morph target vertex buffers on WebGL1
SergioRZMasson Nov 25, 2024
a2edb8b
Use PascalCase for non-exported module-level functions
alexchuber Nov 25, 2024
20e52dc
Mark SolveMetallic as internal
alexchuber Nov 25, 2024
e8a571a
Update packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
alexchuber Nov 25, 2024
d85014b
Capitalize L in IGlTFMorphTarget
alexchuber Nov 25, 2024
d6b73fa
Typo in solveApproxOne
alexchuber Nov 25, 2024
698a56a
Update packages/dev/core/src/Buffers/buffer.ts
alexchuber Nov 25, 2024
d95787f
Update packages/dev/core/src/Buffers/buffer.ts
alexchuber Nov 25, 2024
cea0b7a
Remove linter disables
alexchuber Nov 25, 2024
f73f79c
Remove double comment
alexchuber Nov 25, 2024
3244640
nits
alexchuber Nov 25, 2024
9a3e312
Rename IGLTFMorphTargets to IMorphTargetData
alexchuber Nov 25, 2024
b31b744
Simplified vertex attribute check
SergioRZMasson Nov 26, 2024
3fb7fd9
Merge branch 'sergio/new-gltf-exporter-2' of https://github.com/Sergi…
SergioRZMasson Nov 26, 2024
185c939
Update packages/dev/serializers/src/glTF/2.0/glTFUtilities.ts
alexchuber Dec 3, 2024
d4f016e
Update packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
SergioRZMasson Dec 3, 2024
a42ad44
Update packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
SergioRZMasson Dec 3, 2024
9620f37
Update packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
SergioRZMasson Dec 3, 2024
493e193
Update packages/dev/serializers/src/glTF/2.0/glTFMorphTargetsUtilitie…
SergioRZMasson Dec 4, 2024
45ad7b6
Update packages/dev/serializers/src/glTF/2.0/glTFMorphTargetsUtilitie…
SergioRZMasson Dec 4, 2024
14238d3
Update packages/dev/serializers/src/glTF/2.0/dataWriter.ts
SergioRZMasson Dec 4, 2024
e13dce7
Update packages/dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts
SergioRZMasson Dec 4, 2024
fd0a047
Update packages/dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts
SergioRZMasson Dec 4, 2024
cc390ca
Moved explicit property to constructor
SergioRZMasson Dec 4, 2024
317ec18
Fixed wrong capitalization
SergioRZMasson Dec 4, 2024
473e5eb
Simplified morph targets min max ranges
SergioRZMasson Dec 4, 2024
818b9ad
Added proper error handling when extracting morph target data
SergioRZMasson Dec 4, 2024
bb073db
Changed light normalization to not modify original babylon object
SergioRZMasson Dec 4, 2024
763558f
Reverted change made to _byteOffset
SergioRZMasson Dec 4, 2024
9d18d31
Fixed type mismatch in GPU instancing accessor creation
SergioRZMasson Dec 4, 2024
7d82ce4
Removed duplicated functions
SergioRZMasson Dec 4, 2024
ef46680
Removed double assignment
SergioRZMasson Dec 4, 2024
758e20c
Changed default value compare to be done using equalsWithEpsilon
SergioRZMasson Dec 4, 2024
f333f54
Updating naming convention for public function
SergioRZMasson Dec 4, 2024
f765226
Fixed index buffer flipping logic
SergioRZMasson Dec 4, 2024
a1f989e
Added code to avoid allocations during processing
SergioRZMasson Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 20 additions & 124 deletions packages/dev/core/src/Buffers/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataBuffer } from "./dataBuffer";
import type { Mesh } from "../Meshes/mesh";
import { Logger } from "../Misc/logger";
import { Constants } from "../Engines/constants";
import { EnumerateFloatValues, GetFloatData, GetTypeByteLength } from "./bufferUtils";

/**
* Class used to store data that will be store in GPU memory
Expand Down Expand Up @@ -566,7 +567,7 @@ export class VertexBuffer {
this.type = type;
}

const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);
const typeByteLength = GetTypeByteLength(this.type);

if (useBytes) {
this._size = size || (stride ? stride / typeByteLength : VertexBuffer.DeduceStride(kind));
Expand Down Expand Up @@ -641,7 +642,7 @@ export class VertexBuffer {
return null;
}

return VertexBuffer.GetFloatData(data, this._size, this.type, this.byteOffset, this.byteStride, this.normalized, totalVertices, forceCopy);
return GetFloatData(data, this._size, this.type, this.byteOffset, this.byteStride, this.normalized, totalVertices, forceCopy);
}

/**
Expand All @@ -667,7 +668,7 @@ export class VertexBuffer {
* @deprecated Please use byteStride instead.
*/
public getStrideSize(): number {
return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);
return this.byteStride / GetTypeByteLength(this.type);
}

/**
Expand All @@ -676,7 +677,7 @@ export class VertexBuffer {
* @deprecated Please use byteOffset instead.
*/
public getOffset(): number {
return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);
return this.byteOffset / GetTypeByteLength(this.type);
}

/**
Expand All @@ -685,7 +686,7 @@ export class VertexBuffer {
* @returns the number of components
*/
public getSize(sizeInBytes = false): number {
return sizeInBytes ? this._size * VertexBuffer.GetTypeByteLength(this.type) : this._size;
return sizeInBytes ? this._size * GetTypeByteLength(this.type) : this._size;
}

/**
Expand Down Expand Up @@ -754,7 +755,11 @@ export class VertexBuffer {
* @param callback the callback function called for each value
*/
public forEach(count: number, callback: (value: number, index: number) => void): void {
VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);
EnumerateFloatValues(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, (values, index) => {
for (let i = 0; i < this._size; i++) {
callback(values[i], index + i);
}
});
}

/** @internal */
Expand Down Expand Up @@ -879,22 +884,10 @@ export class VertexBuffer {
* Gets the byte length of the given type.
* @param type the type
* @returns the number of bytes
* @deprecated Use `getTypeByteLength` from `bufferUtils` instead
*/
public static GetTypeByteLength(type: number): number {
switch (type) {
case VertexBuffer.BYTE:
case VertexBuffer.UNSIGNED_BYTE:
return 1;
case VertexBuffer.SHORT:
case VertexBuffer.UNSIGNED_SHORT:
return 2;
case VertexBuffer.INT:
case VertexBuffer.UNSIGNED_INT:
case VertexBuffer.FLOAT:
return 4;
default:
throw new Error(`Invalid type '${type}'`);
}
return GetTypeByteLength(type);
}

/**
Expand All @@ -907,6 +900,7 @@ export class VertexBuffer {
* @param count the number of values to enumerate
* @param normalized whether the data is normalized
* @param callback the callback function called for each value
* @deprecated Use `EnumerateFloatValues` from `bufferUtils` instead
*/
public static ForEach(
data: DataArray,
Expand All @@ -918,73 +912,11 @@ export class VertexBuffer {
normalized: boolean,
callback: (value: number, index: number) => void
): void {
if (data instanceof Array) {
let offset = byteOffset / 4;
const stride = byteStride / 4;
for (let index = 0; index < count; index += componentCount) {
for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
callback(data[offset + componentIndex], index + componentIndex);
}
offset += stride;
}
} else {
const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);
const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);
for (let index = 0; index < count; index += componentCount) {
let componentByteOffset = byteOffset;
for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);
callback(value, index + componentIndex);
componentByteOffset += componentByteLength;
}
byteOffset += byteStride;
}
}
}

private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {
switch (type) {
case VertexBuffer.BYTE: {
let value = dataView.getInt8(byteOffset);
if (normalized) {
value = Math.max(value / 127, -1);
}
return value;
}
case VertexBuffer.UNSIGNED_BYTE: {
let value = dataView.getUint8(byteOffset);
if (normalized) {
value = value / 255;
}
return value;
}
case VertexBuffer.SHORT: {
let value = dataView.getInt16(byteOffset, true);
if (normalized) {
value = Math.max(value / 32767, -1);
}
return value;
}
case VertexBuffer.UNSIGNED_SHORT: {
let value = dataView.getUint16(byteOffset, true);
if (normalized) {
value = value / 65535;
}
return value;
}
case VertexBuffer.INT: {
return dataView.getInt32(byteOffset, true);
}
case VertexBuffer.UNSIGNED_INT: {
return dataView.getUint32(byteOffset, true);
}
case VertexBuffer.FLOAT: {
return dataView.getFloat32(byteOffset, true);
}
default: {
throw new Error(`Invalid component type ${type}`);
EnumerateFloatValues(data, byteOffset, byteStride, componentCount, componentType, count, normalized, (values, index) => {
for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
callback(values[componentIndex], index + componentIndex);
}
}
});
}

/**
Expand All @@ -998,6 +930,7 @@ export class VertexBuffer {
* @param totalVertices number of vertices in the buffer to take into account
* @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it
* @returns a float array containing vertex data
* @deprecated Use `GetFloatData` from `bufferUtils` instead
*/
public static GetFloatData(
data: DataArray,
Expand All @@ -1009,43 +942,6 @@ export class VertexBuffer {
totalVertices: number,
forceCopy?: boolean
): FloatArray {
const tightlyPackedByteStride = size * VertexBuffer.GetTypeByteLength(type);
const count = totalVertices * size;

if (type !== VertexBuffer.FLOAT || byteStride !== tightlyPackedByteStride) {
const copy = new Float32Array(count);
VertexBuffer.ForEach(data, byteOffset, byteStride, size, type, count, normalized, (value, index) => (copy[index] = value));
return copy;
}

if (!(data instanceof Array || data instanceof Float32Array) || byteOffset !== 0 || data.length !== count) {
if (data instanceof Array) {
const offset = byteOffset / 4;
return data.slice(offset, offset + count);
} else if (data instanceof ArrayBuffer) {
return new Float32Array(data, byteOffset, count);
} else {
const offset = data.byteOffset + byteOffset;
if ((offset & 3) !== 0) {
Logger.Warn("Float array must be aligned to 4-bytes border");
forceCopy = true;
}

if (forceCopy) {
const result = new Uint8Array(count * Float32Array.BYTES_PER_ELEMENT);
const source = new Uint8Array(data.buffer, offset, result.length);
result.set(source);
return new Float32Array(result.buffer);
} else {
return new Float32Array(data.buffer, offset, count);
}
}
}

if (forceCopy) {
return data.slice();
}

return data;
return GetFloatData(data, size, type, byteOffset, byteStride, normalized, totalVertices, forceCopy);
}
}
Loading