Skip to content

Commit 39d1669

Browse files
Fix up LLAnimation to do the right thing - 0.8.7
1 parent 05f9e9e commit 39d1669

5 files changed

Lines changed: 35 additions & 27 deletions

File tree

lib/classes/LLAnimation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class LLAnimation
6161
for (let x = 0; x < this.jointCount; x++)
6262
{
6363
const joint = new LLAnimationJoint();
64-
joint.readFromBuffer(buf, this.inPoint, this.outPoint);
64+
joint.readFromBuffer(buf, this.length);
6565
this.joints.push(joint);
6666
}
6767

@@ -101,11 +101,11 @@ export class LLAnimation
101101
writer.writeFloatLE(this.easeInTime);
102102
writer.writeFloatLE(this.easeOutTime);
103103
writer.writeUInt32LE(this.handPose);
104-
writer.writeUInt32LE(this.jointCount);
104+
writer.writeUInt32LE(this.joints.length);
105105

106106
for (const joint of this.joints)
107107
{
108-
joint.writeToBuffer(writer, this.inPoint, this.outPoint);
108+
joint.writeToBuffer(writer, this.length);
109109
}
110110

111111
writer.writeInt32LE(this.constraints.length);

lib/classes/LLAnimationJoint.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { LLAnimationJointKeyFrame } from "./LLAnimationJointKeyFrame";
1+
import { LLAnimationJointKeyFrame } from './LLAnimationJointKeyFrame';
22
import type { BinaryReader } from './BinaryReader';
3-
import { Utils } from "./Utils";
3+
import { Utils } from './Utils';
44
import { Vector3 } from './Vector3';
5+
import { Quaternion } from './Quaternion';
56
import type { BinaryWriter } from './BinaryWriter';
67

8+
const LL_MAX_PELVIS_OFFSET = 5.0;
9+
710
export class LLAnimationJoint
811
{
912
public name: string;
@@ -16,7 +19,7 @@ export class LLAnimationJoint
1619
public positionKeyframes: LLAnimationJointKeyFrame[] = [];
1720

1821

19-
public readFromBuffer(buf: BinaryReader, inPoint: number, outPoint: number): void
22+
public readFromBuffer(buf: BinaryReader, duration: number): void
2023
{
2124
this.name = buf.readCString();
2225
this.priority = buf.readInt32LE();
@@ -25,11 +28,13 @@ export class LLAnimationJoint
2528
for (let frameNum = 0; frameNum < this.rotationKeyframeCount; frameNum++)
2629
{
2730
const jointKF = new LLAnimationJointKeyFrame();
28-
jointKF.time = Utils.UInt16ToFloat(buf.readUInt16LE(), inPoint, outPoint);
29-
const x = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
30-
const y = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
31-
const z = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
32-
jointKF.transform = new Vector3([x, y, z]);
31+
jointKF.time = Utils.UInt16ToFloat(buf.readUInt16LE(), 0.0, duration, false);
32+
const x = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0, false);
33+
const y = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0, false);
34+
const z = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0, false);
35+
const remainder = 1.0 - (x * x) - (y * y) - (z * z);
36+
const w = remainder > 0.0 ? Math.sqrt(remainder) : 0.0;
37+
jointKF.transform = new Quaternion([x, y, z, w]);
3338
this.rotationKeyframes.push(jointKF);
3439
}
3540

@@ -38,35 +43,35 @@ export class LLAnimationJoint
3843
for (let frameNum = 0; frameNum < this.positionKeyframeCount; frameNum++)
3944
{
4045
const jointKF = new LLAnimationJointKeyFrame();
41-
jointKF.time = Utils.UInt16ToFloat(buf.readUInt16LE(), inPoint, outPoint);
42-
const x = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
43-
const y = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
44-
const z = Utils.UInt16ToFloat(buf.readUInt16LE(), -1.0, 1.0);
46+
jointKF.time = Utils.UInt16ToFloat(buf.readUInt16LE(), 0.0, duration, false);
47+
const x = Utils.UInt16ToFloat(buf.readUInt16LE(), -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET, false);
48+
const y = Utils.UInt16ToFloat(buf.readUInt16LE(), -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET, false);
49+
const z = Utils.UInt16ToFloat(buf.readUInt16LE(), -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET, false);
4550
jointKF.transform = new Vector3([x, y, z]);
4651
this.positionKeyframes.push(jointKF);
4752
}
4853
}
4954

50-
public writeToBuffer(writer: BinaryWriter, inPoint: number, outPoint: number): void
55+
public writeToBuffer(writer: BinaryWriter, duration: number): void
5156
{
5257
writer.writeCString(this.name);
5358
writer.writeInt32LE(this.priority);
54-
writer.writeInt32LE(this.rotationKeyframeCount);
59+
writer.writeInt32LE(this.rotationKeyframes.length);
5560
for (const keyframe of this.rotationKeyframes)
5661
{
57-
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.time, inPoint, outPoint));
62+
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.time, 0.0, duration));
5863
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.x, -1.0, 1.0));
5964
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.y, -1.0, 1.0));
6065
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.z, -1.0, 1.0));
6166
}
6267

63-
writer.writeInt32LE(this.positionKeyframeCount);
68+
writer.writeInt32LE(this.positionKeyframes.length);
6469
for (const keyframe of this.positionKeyframes)
6570
{
66-
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.time, inPoint, outPoint));
67-
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.x, -1.0, 1.0));
68-
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.y, -1.0, 1.0));
69-
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.z, -1.0, 1.0));
71+
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.time, 0.0, duration));
72+
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.x, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET));
73+
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.y, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET));
74+
writer.writeUInt16LE(Utils.FloatToUInt16(keyframe.transform.z, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET));
7075
}
7176
}
7277
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Vector3 } from './Vector3';
2+
import type { Quaternion } from './Quaternion';
23

34
export class LLAnimationJointKeyFrame
45
{
56
public time: number;
6-
public transform: Vector3;
7+
public transform: Vector3 | Quaternion;
78
}
8-

lib/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ import { LLWearable } from './classes/LLWearable';
8989
import { ParticleSystem } from './classes/ParticleSystem';
9090
import { ExtraParams } from './classes/public/ExtraParams';
9191
import { LLMesh } from './classes/public/LLMesh';
92+
import { LLAnimation } from './classes/LLAnimation';
93+
import { LLAnimationJoint } from './classes/LLAnimationJoint';
94+
import { LLAnimationJointKeyFrame } from './classes/LLAnimationJointKeyFrame';
9295
import { FolderType } from './enums/FolderType';
9396
import { InventoryItem } from './classes/InventoryItem';
9497
import { InventoryType } from './enums/InventoryType';
@@ -109,4 +112,4 @@ import type { LLSettingsHazeConfig, LLSettingsTermConfig } from './classes/LLSet
109112
import { LLSettings } from './classes/LLSettings';
110113

111114
export type { LLSettingsTermConfig, LLSettingsHazeConfig, GlobalPosition, MapLocation };
112-
export { Bot, LoginParameters, ClientEvents, BVH, ChatSourceType, UUID, Vector3, Vector2, Utils, TextureEntry, LLWearable, LLLindenText, LLGLTFMaterial, LLGesture, LLGestureAnimationStep, LLGestureSoundStep, LLGestureChatStep, LLGestureWaitStep, LLSettings, ParticleSystem, ExtraParams, AgentFlags, BotOptionFlags, CompressedFlags, ControlFlags, DecodeFlags, InstantMessageEventFlags, InventoryItemFlags, LoginFlags, MessageFlags, ParcelInfoFlags, PacketFlags, RegionProtocolFlags, SoundFlags, TeleportFlags, RegionFlags, RightsFlags, ParticleDataFlags, TextureFlags, PrimFlags, ParcelFlags, SimAccessFlags, TextureAnimFlags, InventoryType, AssetType, FolderType, TransferStatus, SourcePattern, BlendFunc, PCode, Bumpiness, HoleType, LayerType, MappingType, PhysicsShapeType, ProfileShape, SculptType, Shininess, LLGestureStepType, ChatEvent, DisconnectEvent, FriendRequestEvent, FriendResponseEvent, GroupChatEvent, GroupChatSessionAgentListEvent, GroupChatSessionJoinEvent, GroupNoticeEvent, GroupInviteEvent, InstantMessageEvent, InventoryOfferedEvent, LureEvent, MapInfoRangeReplyEvent, MapInfoReplyEvent, ParcelInfoReplyEvent, RegionInfoReplyEvent, TeleportEvent, ScriptDialogEvent, EventQueueStateChangeEvent, FriendOnlineEvent, FriendRightsEvent, FriendRemovedEvent, ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectKilledEvent, ObjectUpdatedEvent, GroupProfileReplyEvent, AvatarPropertiesReplyEvent, Avatar, Friend, FlexibleData, LightData, LightImageData, GameObject, Material, Parcel, SculptData, MeshData, LLMesh, InventoryItem, TarReader, TarWriter, ExtendedMeshData, ReflectionProbeData, RenderMaterialData };
115+
export { Bot, LoginParameters, ClientEvents, BVH, ChatSourceType, UUID, Vector3, Vector2, Utils, TextureEntry, LLWearable, LLLindenText, LLGLTFMaterial, LLGesture, LLGestureAnimationStep, LLGestureSoundStep, LLGestureChatStep, LLGestureWaitStep, LLSettings, ParticleSystem, ExtraParams, AgentFlags, BotOptionFlags, CompressedFlags, ControlFlags, DecodeFlags, InstantMessageEventFlags, InventoryItemFlags, LoginFlags, MessageFlags, ParcelInfoFlags, PacketFlags, RegionProtocolFlags, SoundFlags, TeleportFlags, RegionFlags, RightsFlags, ParticleDataFlags, TextureFlags, PrimFlags, ParcelFlags, SimAccessFlags, TextureAnimFlags, InventoryType, AssetType, FolderType, TransferStatus, SourcePattern, BlendFunc, PCode, Bumpiness, HoleType, LayerType, MappingType, PhysicsShapeType, ProfileShape, SculptType, Shininess, LLGestureStepType, ChatEvent, DisconnectEvent, FriendRequestEvent, FriendResponseEvent, GroupChatEvent, GroupChatSessionAgentListEvent, GroupChatSessionJoinEvent, GroupNoticeEvent, GroupInviteEvent, InstantMessageEvent, InventoryOfferedEvent, LureEvent, MapInfoRangeReplyEvent, MapInfoReplyEvent, ParcelInfoReplyEvent, RegionInfoReplyEvent, TeleportEvent, ScriptDialogEvent, EventQueueStateChangeEvent, FriendOnlineEvent, FriendRightsEvent, FriendRemovedEvent, ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectKilledEvent, ObjectUpdatedEvent, GroupProfileReplyEvent, AvatarPropertiesReplyEvent, Avatar, Friend, FlexibleData, LightData, LightImageData, GameObject, Material, Parcel, SculptData, MeshData, LLMesh, LLAnimation, LLAnimationJoint, LLAnimationJointKeyFrame, InventoryItem, TarReader, TarWriter, ExtendedMeshData, ReflectionProbeData, RenderMaterialData };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@caspertech/node-metaverse",
3-
"version": "0.8.6",
3+
"version": "0.8.7",
44
"description": "A node.js interface for Second Life.",
55
"main": "dist/lib/index.js",
66
"types": "dist/lib/index.d.ts",

0 commit comments

Comments
 (0)