From 53506ff2cb2592941453b985f0f727b18d68bfd8 Mon Sep 17 00:00:00 2001 From: Casper Warden <216465704+casperwardensl@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:08:37 +0000 Subject: [PATCH] Support for new ExtraParams --- lib/classes/public/ExtendedMeshData.ts | 29 ++++++++++++ lib/classes/public/ExtendedMeshFlags.ts | 4 ++ lib/classes/public/ExtraParams.ts | 51 +++++++++++++++++++--- lib/classes/public/ReflectionProbeData.ts | 39 +++++++++++++++++ lib/classes/public/ReflectionProbeFlags.ts | 5 +++ lib/classes/public/RenderMaterialData.ts | 51 ++++++++++++++++++++++ lib/classes/public/RenderMaterialParam.ts | 7 +++ lib/enums/ExtraParamType.ts | 5 ++- 8 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 lib/classes/public/ExtendedMeshData.ts create mode 100644 lib/classes/public/ExtendedMeshFlags.ts create mode 100644 lib/classes/public/ReflectionProbeData.ts create mode 100644 lib/classes/public/ReflectionProbeFlags.ts create mode 100644 lib/classes/public/RenderMaterialData.ts create mode 100644 lib/classes/public/RenderMaterialParam.ts diff --git a/lib/classes/public/ExtendedMeshData.ts b/lib/classes/public/ExtendedMeshData.ts new file mode 100644 index 0000000..aad2aad --- /dev/null +++ b/lib/classes/public/ExtendedMeshData.ts @@ -0,0 +1,29 @@ +import { ExtendedMeshFlags } from './ExtendedMeshFlags'; + +export class ExtendedMeshData +{ + public flags: ExtendedMeshFlags = 0 as ExtendedMeshFlags; + + constructor(buf?: Buffer, pos?: number, length?: number) + { + if (buf !== undefined && pos !== undefined && length !== undefined) + { + if (buf.length - pos >= 4 && length >= 4) + { + this.flags = buf.readUInt32LE(pos); + } + } + } + + writeToBuffer(buf: Buffer, pos: number): void + { + buf.writeUInt32LE(this.flags, pos); + } + + getBuffer(): Buffer + { + const buf = Buffer.allocUnsafe(4); + this.writeToBuffer(buf, 0); + return buf; + } +} diff --git a/lib/classes/public/ExtendedMeshFlags.ts b/lib/classes/public/ExtendedMeshFlags.ts new file mode 100644 index 0000000..29036d4 --- /dev/null +++ b/lib/classes/public/ExtendedMeshFlags.ts @@ -0,0 +1,4 @@ +export enum ExtendedMeshFlags +{ + ANIMATED_MESH_ENABLED_FLAG = 0x1 << 0 +} diff --git a/lib/classes/public/ExtraParams.ts b/lib/classes/public/ExtraParams.ts index 0cc1eeb..dc14b53 100644 --- a/lib/classes/public/ExtraParams.ts +++ b/lib/classes/public/ExtraParams.ts @@ -7,6 +7,12 @@ import { SculptData } from './SculptData'; import { UUID } from '../UUID'; import { Vector3 } from '../Vector3'; import { Color4 } from '../Color4'; +import { ExtendedMeshData } from './ExtendedMeshData'; +import { RenderMaterialData } from './RenderMaterialData'; +import { ReflectionProbeData } from './ReflectionProbeData'; +import { ExtendedMeshFlags } from './ExtendedMeshFlags'; +import { ReflectionProbeFlags } from './ReflectionProbeFlags'; +import { RenderMaterialParam } from './RenderMaterialParam'; export class ExtraParams { @@ -15,6 +21,9 @@ export class ExtraParams lightImageData: LightImageData | null = null; meshData: MeshData | null = null; sculptData: SculptData | null = null; + extendedMeshData: ExtendedMeshData | null = null; + renderMaterialData: RenderMaterialData | null = null; + reflectionProbeData: ReflectionProbeData | null = null; static getLengthOfParams(buf: Buffer, pos: number): number { @@ -68,6 +77,15 @@ export class ExtraParams case ExtraParamType.Sculpt: ep.sculptData = new SculptData(buf, pos, paramLength); break; + case ExtraParamType.ExtendedMesh: + ep.extendedMeshData = new ExtendedMeshData(buf, pos, paramLength); + break; + case ExtraParamType.RenderMaterial: + ep.renderMaterialData = new RenderMaterialData(buf, pos, paramLength); + break; + case ExtraParamType.ReflectionProbe: + ep.reflectionProbeData = new ReflectionProbeData(buf, pos, paramLength); + break; } pos += paramLength; @@ -76,19 +94,40 @@ export class ExtraParams } return ep; } - setMeshData(type: number, uuid: UUID): void + public setMeshData(type: number, uuid: UUID): void { this.meshData = new MeshData(); this.meshData.type = type; this.meshData.meshData = uuid; } - setSculptData(type: number, uuid: UUID): void + + public setExtendedMeshData(flags: ExtendedMeshFlags): void + { + this.extendedMeshData = new ExtendedMeshData(); + this.extendedMeshData.flags = flags; + } + + public setReflectionProbeData(ambiance: number, clipDistance: number, flags: ReflectionProbeFlags): void + { + this.reflectionProbeData = new ReflectionProbeData(); + this.reflectionProbeData.ambiance = ambiance; + this.reflectionProbeData.clipDistance = clipDistance; + this.reflectionProbeData.flags = flags; + } + + public setRenderMaterialData(params: RenderMaterialParam[]): void + { + this.renderMaterialData = new RenderMaterialData(); + this.renderMaterialData.params = params; + } + + public setSculptData(type: number, uuid: UUID): void { this.sculptData = new SculptData(); this.sculptData.type = type; this.sculptData.texture = uuid; } - setFlexiData(softness: number, tension: number, drag: number, gravity: number, wind: number, force: Vector3): void + public setFlexiData(softness: number, tension: number, drag: number, gravity: number, wind: number, force: Vector3): void { this.flexibleData = new FlexibleData(); this.flexibleData.Softness = softness; @@ -98,7 +137,7 @@ export class ExtraParams this.flexibleData.Wind = wind; this.flexibleData.Force = force; } - setLightData(color: Color4, radius: number, cutoff: number, falloff: number, intensity: number): void + public setLightData(color: Color4, radius: number, cutoff: number, falloff: number, intensity: number): void { this.lightData = new LightData(); this.lightData.Color = color; @@ -107,7 +146,7 @@ export class ExtraParams this.lightData.Falloff = falloff; this.lightData.Intensity = intensity; } - toBuffer(): Buffer + public toBuffer(): Buffer { let totalLength = 1; let paramCount = 0; @@ -171,7 +210,7 @@ export class ExtraParams } return buf; } - toBase64(): string + public toBase64(): string { return this.toBuffer().toString('base64'); } diff --git a/lib/classes/public/ReflectionProbeData.ts b/lib/classes/public/ReflectionProbeData.ts new file mode 100644 index 0000000..e1df434 --- /dev/null +++ b/lib/classes/public/ReflectionProbeData.ts @@ -0,0 +1,39 @@ +import { ReflectionProbeFlags } from './ReflectionProbeFlags'; + +export class ReflectionProbeData +{ + public ambiance = 0.0; + public clipDistance = 0.0; + public flags: ReflectionProbeFlags = 0 as ReflectionProbeFlags; + + constructor(buf?: Buffer, pos?: number, length?: number) + { + if (buf !== undefined && pos !== undefined && length !== undefined) + { + if (buf.length - pos >= 9 && length >= 9) + { + this.ambiance = buf.readFloatLE(pos); + pos = pos + 4; + this.clipDistance = buf.readFloatLE(pos); + pos = pos + 4; + this.flags = buf.readUInt8(pos); + } + } + } + + writeToBuffer(buf: Buffer, pos: number): void + { + buf.writeFloatLE(this.ambiance, pos); + pos = pos + 4; + buf.writeFloatLE(this.clipDistance, pos); + pos = pos + 4; + buf.writeUInt8(this.flags, pos); + } + + getBuffer(): Buffer + { + const buf = Buffer.allocUnsafe(9); + this.writeToBuffer(buf, 0); + return buf; + } +} diff --git a/lib/classes/public/ReflectionProbeFlags.ts b/lib/classes/public/ReflectionProbeFlags.ts new file mode 100644 index 0000000..ad32a25 --- /dev/null +++ b/lib/classes/public/ReflectionProbeFlags.ts @@ -0,0 +1,5 @@ +export enum ReflectionProbeFlags +{ + FLAG_BOX_VOLUME = 0x01, + FLAG_DYNAMIC = 0x02, +} diff --git a/lib/classes/public/RenderMaterialData.ts b/lib/classes/public/RenderMaterialData.ts new file mode 100644 index 0000000..ed8cd43 --- /dev/null +++ b/lib/classes/public/RenderMaterialData.ts @@ -0,0 +1,51 @@ +import { RenderMaterialParam } from './RenderMaterialParam'; +import { UUID } from '../UUID'; + +export class RenderMaterialData +{ + public params: RenderMaterialParam[] = []; + + constructor(buf?: Buffer, pos?: number, length?: number) + { + let localPos = 0; + if (buf !== undefined && pos !== undefined && length !== undefined) + { + if (buf.length - pos >= 1 && length - localPos >= 1) + { + const count = buf.readUInt8(pos++); + localPos++; + for (let x = 0; x < count; x++) + { + if (buf.length - pos >= 17 && length - localPos >= 17) + { + const param = new RenderMaterialParam(); + param.textureIndex = buf.readUInt8(pos++); + localPos++; + param.textureUUID = new UUID(buf, pos); + pos = pos + 16; + localPos = localPos + 16; + this.params.push(param); + } + } + } + } + } + + writeToBuffer(buf: Buffer, pos: number): void + { + buf.writeUInt8(this.params.length, pos++); + for (const param of this.params) + { + buf.writeUInt8(param.textureIndex, pos++); + param.textureUUID.writeToBuffer(buf, pos); + pos = pos + 16; + } + } + + getBuffer(): Buffer + { + const buf = Buffer.allocUnsafe(8 + (this.params.length * 17)); + this.writeToBuffer(buf, 0); + return buf; + } +} diff --git a/lib/classes/public/RenderMaterialParam.ts b/lib/classes/public/RenderMaterialParam.ts new file mode 100644 index 0000000..c457cd7 --- /dev/null +++ b/lib/classes/public/RenderMaterialParam.ts @@ -0,0 +1,7 @@ +import { UUID } from '../UUID'; + +export class RenderMaterialParam +{ + public textureIndex: number; + public textureUUID: UUID; +} diff --git a/lib/enums/ExtraParamType.ts b/lib/enums/ExtraParamType.ts index cc4557e..d74c02e 100644 --- a/lib/enums/ExtraParamType.ts +++ b/lib/enums/ExtraParamType.ts @@ -4,5 +4,8 @@ export enum ExtraParamType Light = 0x20, Sculpt = 0x30, LightImage = 0x40, - Mesh = 0x60 + Mesh = 0x60, + ExtendedMesh = 0x70, + RenderMaterial = 0x80, + ReflectionProbe = 0x90 }