2020-01-06 12:10:40 +00:00
|
|
|
import { UUID } from '../UUID';
|
|
|
|
|
import { Color4 } from '../Color4';
|
2020-11-19 16:51:14 +00:00
|
|
|
import * as LLSD from '@caspertech/llsd';
|
|
|
|
|
import { Utils } from '../Utils';
|
- Add "GET" method to Caps
- New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent
- Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export
- Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore
- Object store will automatically request missing "parent" prims
- "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning
- Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps
- Fixed object scale being incorrectly calculated
- Add terrain decoding (this was a ballache)
- Add parcel map decoding
- Add support for region windlight settings (region.environment)
- Add support for materials (normal / specular maps)
- Add getBuffer, getLong and bitwiseOr to UUID
- Added a circular-reference-safe JSONStringify to Utils
- Add XferFile capability to Circuit
PUBLIC API:
AssetCommands:
- Rework "downloadAsset" to detect failures
- NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items
- NEW: getMaterials() - resolves material UUIDs
RegionCommands:
- NEW: getTerrainTextures()
- NEW: exportSettings() - OpenSim XML export of region settings
- NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32
- resolveObjects() - now fetches task inventory contents too.
- resolveObjects() - fix calculation of land impact
- NEW: getObjectByLocalID(localID: number, timeout: number)
- NEW: getObjectByUUID(uuid: UUID, timeout: number)
- NEW: getParcels();
- NEW: pruneObjects - removes missing GameObjects from a list
- NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
|
|
|
|
|
|
|
|
export class Material
|
|
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
public alphaMaskCutoff: number;
|
|
|
|
|
public diffuseAlphaMode: number;
|
|
|
|
|
public envIntensity: number;
|
|
|
|
|
public normMap: UUID;
|
|
|
|
|
public normOffsetX: number;
|
|
|
|
|
public normOffsetY: number;
|
|
|
|
|
public normRepeatX: number;
|
|
|
|
|
public normRepeatY: number;
|
|
|
|
|
public normRotation: number;
|
|
|
|
|
public specColor: Color4;
|
|
|
|
|
public specExp: number;
|
|
|
|
|
public specMap: UUID;
|
|
|
|
|
public specOffsetX: number;
|
|
|
|
|
public specOffsetY: number;
|
|
|
|
|
public specRepeatX: number;
|
|
|
|
|
public specRepeatY: number;
|
|
|
|
|
public specRotation: number;
|
2020-11-19 16:51:14 +00:00
|
|
|
|
2025-01-17 23:37:54 +00:00
|
|
|
public static fromLLSD(llsd: string): Material
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
|
|
|
|
const parsed = LLSD.LLSD.parseXML(llsd);
|
|
|
|
|
return this.fromLLSDObject(parsed);
|
|
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
|
|
|
|
|
public static fromLLSDObject(parsed: any): Material
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
|
|
|
|
const material = new Material();
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.AlphaMaskCutoff !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.alphaMaskCutoff = parsed.AlphaMaskCutoff;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.DiffuseAlphaMode !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.diffuseAlphaMode = parsed.DiffuseAlphaMode;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.EnvIntensity !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.envIntensity = parsed.EnvIntensity;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormMap !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normMap = new UUID(parsed.NormMap.toString())
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormOffsetX !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normOffsetX = parsed.NormOffsetX;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormOffsetY !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normOffsetY = parsed.NormOffsetY;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormRepeatX !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normRepeatX = parsed.NormRepeatX;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormRepeatY !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normRepeatY = parsed.NormRepeatY;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.NormRotation !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.normRotation = parsed.NormRotation;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecColor !== undefined && Array.isArray(parsed.SpecColor) && parsed.SpecColor.length > 3)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
|
|
|
|
material.specColor = new Color4([
|
2025-01-17 23:37:54 +00:00
|
|
|
parsed.SpecColor[0],
|
|
|
|
|
parsed.SpecColor[1],
|
|
|
|
|
parsed.SpecColor[2],
|
|
|
|
|
parsed.SpecColor[3]
|
2020-11-19 16:51:14 +00:00
|
|
|
]);
|
|
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecExp !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specExp = parsed.SpecExp;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecMap !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specMap = new UUID(parsed.SpecMap.toString())
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecOffsetX !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specOffsetX = parsed.SpecOffsetX;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecOffsetY !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specOffsetY = parsed.SpecOffsetY;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecRepeatX !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specRepeatX = parsed.SpecRepeatX;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecRepeatY !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specRepeatY = parsed.SpecRepeatY;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
2025-01-17 23:37:54 +00:00
|
|
|
if (parsed.SpecRotation !== undefined)
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
material.specRotation = parsed.SpecRotation;
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
|
|
|
|
return material;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 23:37:54 +00:00
|
|
|
public toLLSDObject(): any
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
'AlphaMaskCutoff': this.alphaMaskCutoff,
|
|
|
|
|
'DiffuseAlphaMode': this.diffuseAlphaMode,
|
|
|
|
|
'EnvIntensity': this.envIntensity,
|
|
|
|
|
'NormMap': new LLSD.UUID(this.normMap.toString()),
|
|
|
|
|
'NormOffsetX': this.normOffsetX,
|
|
|
|
|
'NormOffsetY': this.normOffsetY,
|
|
|
|
|
'NormRepeatX': this.normRepeatX,
|
|
|
|
|
'NormRepeatY': this.normRepeatY,
|
|
|
|
|
'NormRotation': this.normRotation,
|
|
|
|
|
'SpecColor': [
|
|
|
|
|
this.specColor.getRed(),
|
|
|
|
|
this.specColor.getGreen(),
|
|
|
|
|
this.specColor.getBlue(),
|
|
|
|
|
this.specColor.getAlpha()
|
|
|
|
|
],
|
|
|
|
|
'SpecExp': this.specExp,
|
|
|
|
|
'SpecMap': new LLSD.UUID(this.specMap.toString()),
|
|
|
|
|
'SpecOffsetX': this.specOffsetX,
|
|
|
|
|
'SpecOffsetY': this.specOffsetY,
|
|
|
|
|
'SpecRepeatX': this.specRepeatX,
|
|
|
|
|
'SpecRepeatY': this.specRepeatY,
|
|
|
|
|
'SpecRotation': this.specRotation,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 23:37:54 +00:00
|
|
|
public toLLSD(): string
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
2025-01-17 23:37:54 +00:00
|
|
|
return String(LLSD.LLSD.formatXML(this.toLLSDObject()));
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-17 23:37:54 +00:00
|
|
|
public async toAsset(uuid: UUID): Promise<Buffer>
|
2020-11-19 16:51:14 +00:00
|
|
|
{
|
|
|
|
|
const asset = {
|
|
|
|
|
'ID': new LLSD.UUID(uuid.toString()),
|
|
|
|
|
'Material': this.toLLSD()
|
|
|
|
|
};
|
|
|
|
|
const binary = LLSD.LLSD.formatBinary(asset);
|
2025-01-17 23:37:54 +00:00
|
|
|
return Utils.deflate(Buffer.from(binary.toArray()));
|
2020-11-19 16:51:14 +00:00
|
|
|
}
|
- Add "GET" method to Caps
- New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent
- Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export
- Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore
- Object store will automatically request missing "parent" prims
- "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning
- Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps
- Fixed object scale being incorrectly calculated
- Add terrain decoding (this was a ballache)
- Add parcel map decoding
- Add support for region windlight settings (region.environment)
- Add support for materials (normal / specular maps)
- Add getBuffer, getLong and bitwiseOr to UUID
- Added a circular-reference-safe JSONStringify to Utils
- Add XferFile capability to Circuit
PUBLIC API:
AssetCommands:
- Rework "downloadAsset" to detect failures
- NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items
- NEW: getMaterials() - resolves material UUIDs
RegionCommands:
- NEW: getTerrainTextures()
- NEW: exportSettings() - OpenSim XML export of region settings
- NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32
- resolveObjects() - now fetches task inventory contents too.
- resolveObjects() - fix calculation of land impact
- NEW: getObjectByLocalID(localID: number, timeout: number)
- NEW: getObjectByUUID(uuid: UUID, timeout: number)
- NEW: getParcels();
- NEW: pruneObjects - removes missing GameObjects from a list
- NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
|
|
|
}
|