Support for new ExtraParams

This commit is contained in:
Casper Warden
2023-11-09 18:08:37 +00:00
parent 8187726962
commit 53506ff2cb
8 changed files with 184 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,4 @@
export enum ExtendedMeshFlags
{
ANIMATED_MESH_ENABLED_FLAG = 0x1 << 0
}

View File

@@ -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');
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
export enum ReflectionProbeFlags
{
FLAG_BOX_VOLUME = 0x01,
FLAG_DYNAMIC = 0x02,
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,7 @@
import { UUID } from '../UUID';
export class RenderMaterialParam
{
public textureIndex: number;
public textureUUID: UUID;
}

View File

@@ -4,5 +4,8 @@ export enum ExtraParamType
Light = 0x20,
Sculpt = 0x30,
LightImage = 0x40,
Mesh = 0x60
Mesh = 0x60,
ExtendedMesh = 0x70,
RenderMaterial = 0x80,
ReflectionProbe = 0x90
}