Support for new ExtraParams
This commit is contained in:
29
lib/classes/public/ExtendedMeshData.ts
Normal file
29
lib/classes/public/ExtendedMeshData.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
4
lib/classes/public/ExtendedMeshFlags.ts
Normal file
4
lib/classes/public/ExtendedMeshFlags.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export enum ExtendedMeshFlags
|
||||
{
|
||||
ANIMATED_MESH_ENABLED_FLAG = 0x1 << 0
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
39
lib/classes/public/ReflectionProbeData.ts
Normal file
39
lib/classes/public/ReflectionProbeData.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
5
lib/classes/public/ReflectionProbeFlags.ts
Normal file
5
lib/classes/public/ReflectionProbeFlags.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum ReflectionProbeFlags
|
||||
{
|
||||
FLAG_BOX_VOLUME = 0x01,
|
||||
FLAG_DYNAMIC = 0x02,
|
||||
}
|
||||
51
lib/classes/public/RenderMaterialData.ts
Normal file
51
lib/classes/public/RenderMaterialData.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
7
lib/classes/public/RenderMaterialParam.ts
Normal file
7
lib/classes/public/RenderMaterialParam.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { UUID } from '../UUID';
|
||||
|
||||
export class RenderMaterialParam
|
||||
{
|
||||
public textureIndex: number;
|
||||
public textureUUID: UUID;
|
||||
}
|
||||
@@ -4,5 +4,8 @@ export enum ExtraParamType
|
||||
Light = 0x20,
|
||||
Sculpt = 0x30,
|
||||
LightImage = 0x40,
|
||||
Mesh = 0x60
|
||||
Mesh = 0x60,
|
||||
ExtendedMesh = 0x70,
|
||||
RenderMaterial = 0x80,
|
||||
ReflectionProbe = 0x90
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user