\r
public class RenderPrimitive : SceneObject\r
{\r
+ #region Public fields\r
public Primitive Prim;\r
public List<Face> Faces;\r
/// <summary>Is this object attached to an avatar</summary>\r
public bool Meshed;\r
/// <summary>Process of creating a mesh is underway</summary>\r
public bool Meshing;\r
+ #endregion Public fields\r
+\r
+ #region Private fields\r
+ int prevTEHash;\r
+ int prevSculptHash;\r
+ int prevShapeHash;\r
+ #endregion Private fields\r
\r
public RenderPrimitive()\r
{\r
public override Primitive BasePrim\r
{\r
get { return Prim; }\r
- set \r
+ set\r
{\r
- if(Meshed)\r
+ Prim = value;\r
+\r
+ int TEHash = Prim.Textures == null ? 0 : Prim.Textures.GetHashCode();\r
+ int sculptHash, shapeHash;\r
+\r
+ if (Meshed)\r
{\r
- if(Prim.Type == PrimType.Sculpt || Prim.Type == PrimType.Mesh)\r
+ if (Prim.Type == PrimType.Sculpt || Prim.Type == PrimType.Mesh)\r
{\r
- if(!Prim.Sculpt.Equals(value.Sculpt) || !Prim.Textures.Equals(value.Textures))\r
+ sculptHash = Prim.Sculpt.GetHashCode();\r
+ if (Prim.Sculpt.GetHashCode() != prevSculptHash || TEHash != prevTEHash)\r
{\r
Meshed = false;\r
- Faces.Clear();\r
}\r
+ prevSculptHash = sculptHash;\r
}\r
else\r
{\r
- if(!Prim.PrimData.Equals(value.PrimData))\r
+ shapeHash = Prim.PrimData.GetHashCode();\r
+ if (shapeHash != prevShapeHash)\r
{\r
Meshed = false;\r
- Faces.Clear();\r
}\r
- else if(!Prim.Textures.Equals(value.Textures))\r
+ else if (TEHash != prevTEHash)\r
{\r
Meshed = false;\r
- Faces.Clear();\r
}\r
+ prevShapeHash = shapeHash;\r
}\r
}\r
- Prim = value;\r
+ prevTEHash = TEHash;\r
}\r
}\r
\r
}\r
}\r
\r
- public static class Render\r
- {\r
- public static IRendering Plugin;\r
- }\r
-\r
public static class RHelp\r
{\r
public static readonly Vector3 InvalidPosition = new Vector3(99999f, 99999f, 99999f);\r
public skeleton()\r
{\r
\r
- \r
+\r
\r
mBones = new Dictionary<string, Bone>();\r
\r
\r
// Add animations to the global decoded list\r
// TODO garbage collect unused animations somehow\r
- public static void addanimation(OpenMetaverse.Assets.Asset asset,UUID tid, BinBVHAnimationReader b)\r
+ public static void addanimation(OpenMetaverse.Assets.Asset asset, UUID tid, BinBVHAnimationReader b)\r
{\r
RenderAvatar av;\r
mAnimationTransactions.TryGetValue(tid, out av);\r
mAnimationCache[asset.AssetID] = b;\r
Logger.Log("Adding new decoded animaton known animations " + asset.AssetID.ToString(), Helpers.LogLevel.Info);\r
}\r
- \r
- int pos=0;\r
+\r
+ int pos = 0;\r
foreach (binBVHJoint joint in b.joints)\r
{\r
binBVHJointState state;\r
\r
if (b.Loop == true)\r
{\r
- int frame=0;\r
- foreach( binBVHJointKey key in joint.rotationkeys)\r
+ int frame = 0;\r
+ foreach (binBVHJointKey key in joint.rotationkeys)\r
{\r
if (key.time == b.InPoint)\r
{\r
{\r
mPriority.Clear();\r
\r
- lock(mAnimations)\r
- foreach (BinBVHAnimationReader b in mAnimations) \r
+ lock (mAnimations)\r
+ foreach (BinBVHAnimationReader b in mAnimations)\r
{\r
if (b == null)\r
continue;\r
\r
- int jpos = 0;\r
- foreach (binBVHJoint joint in b.joints)\r
+ int jpos = 0;\r
+ foreach (binBVHJoint joint in b.joints)\r
+ {\r
+ int prio = 0;\r
+\r
+ //Quick hack to stack animations in the correct order\r
+ //TODO we need to do this per joint as they all have their own priorities as well ;-(\r
+ if (mPriority.TryGetValue(joint.Name, out prio))\r
{\r
- int prio=0;\r
- \r
- //Quick hack to stack animations in the correct order\r
- //TODO we need to do this per joint as they all have their own priorities as well ;-(\r
- if (mPriority.TryGetValue(joint.Name, out prio))\r
- {\r
- if (prio > b.Priority)\r
- continue;\r
- }\r
+ if (prio > b.Priority)\r
+ continue;\r
+ }\r
\r
- mPriority[joint.Name] = b.Priority;\r
- \r
- binBVHJointState state = (binBVHJointState) b.joints[jpos].Tag;\r
+ mPriority[joint.Name] = b.Priority;\r
\r
- state.currenttime_rot += lastframetime;\r
- state.currenttime_pos += lastframetime;\r
+ binBVHJointState state = (binBVHJointState)b.joints[jpos].Tag;\r
\r
- //fudge\r
- if (b.joints[jpos].rotationkeys.Length == 1)\r
- {\r
- state.nextkeyframe_rot = 0;\r
- }\r
+ state.currenttime_rot += lastframetime;\r
+ state.currenttime_pos += lastframetime;\r
\r
- Vector3 poslerp = Vector3.Zero;\r
+ //fudge\r
+ if (b.joints[jpos].rotationkeys.Length == 1)\r
+ {\r
+ state.nextkeyframe_rot = 0;\r
+ }\r
\r
- if (b.joints[jpos].positionkeys.Length > 2)\r
- {\r
- binBVHJointKey pos2 = b.joints[jpos].positionkeys[state.nextkeyframe_pos];\r
+ Vector3 poslerp = Vector3.Zero;\r
\r
+ if (b.joints[jpos].positionkeys.Length > 2)\r
+ {\r
+ binBVHJointKey pos2 = b.joints[jpos].positionkeys[state.nextkeyframe_pos];\r
\r
- if (state.currenttime_pos > pos2.time)\r
- {\r
- state.lastkeyframe_pos++;\r
- state.nextkeyframe_pos++;\r
\r
- if (state.nextkeyframe_pos >= b.joints[jpos].positionkeys.Length || (state.nextkeyframe_pos >=state.loopoutframe && b.Loop==true))\r
+ if (state.currenttime_pos > pos2.time)\r
+ {\r
+ state.lastkeyframe_pos++;\r
+ state.nextkeyframe_pos++;\r
+\r
+ if (state.nextkeyframe_pos >= b.joints[jpos].positionkeys.Length || (state.nextkeyframe_pos >= state.loopoutframe && b.Loop == true))\r
+ {\r
+ if (b.Loop == true)\r
{\r
- if (b.Loop == true)\r
- {\r
- state.nextkeyframe_pos = state.loopinframe;\r
- state.currenttime_pos = b.InPoint;\r
+ state.nextkeyframe_pos = state.loopinframe;\r
+ state.currenttime_pos = b.InPoint;\r
\r
- if (state.lastkeyframe_pos >= b.joints[jpos].positionkeys.Length)\r
- {\r
- state.lastkeyframe_pos = state.loopinframe;\r
- }\r
- }\r
- else\r
+ if (state.lastkeyframe_pos >= b.joints[jpos].positionkeys.Length)\r
{\r
- state.nextkeyframe_pos = joint.positionkeys.Length - 1;\r
+ state.lastkeyframe_pos = state.loopinframe;\r
}\r
}\r
+ else\r
+ {\r
+ state.nextkeyframe_pos = joint.positionkeys.Length - 1;\r
+ }\r
+ }\r
\r
- \r
\r
- if (state.lastkeyframe_pos >= b.joints[jpos].positionkeys.Length)\r
+\r
+ if (state.lastkeyframe_pos >= b.joints[jpos].positionkeys.Length)\r
+ {\r
+ if (b.Loop == true)\r
{\r
- if (b.Loop == true)\r
- {\r
- state.lastkeyframe_pos = 0;\r
- state.currenttime_pos = 0;\r
+ state.lastkeyframe_pos = 0;\r
+ state.currenttime_pos = 0;\r
\r
- }\r
- else\r
- {\r
- state.lastkeyframe_pos = joint.positionkeys.Length - 1;\r
- if (state.lastkeyframe_pos < 0)//eeww\r
- state.lastkeyframe_pos = 0; \r
- }\r
+ }\r
+ else\r
+ {\r
+ state.lastkeyframe_pos = joint.positionkeys.Length - 1;\r
+ if (state.lastkeyframe_pos < 0)//eeww\r
+ state.lastkeyframe_pos = 0;\r
}\r
}\r
+ }\r
\r
- binBVHJointKey pos = b.joints[jpos].positionkeys[state.lastkeyframe_pos];\r
+ binBVHJointKey pos = b.joints[jpos].positionkeys[state.lastkeyframe_pos];\r
\r
\r
- float delta = (pos2.time - pos.time) / ((state.currenttime_pos) - (pos.time - b.joints[jpos].positionkeys[0].time));\r
+ float delta = (pos2.time - pos.time) / ((state.currenttime_pos) - (pos.time - b.joints[jpos].positionkeys[0].time));\r
\r
- if (delta < 0)\r
- delta = 0;\r
+ if (delta < 0)\r
+ delta = 0;\r
\r
- if (delta > 1)\r
- delta = 1;\r
+ if (delta > 1)\r
+ delta = 1;\r
\r
- poslerp = Vector3.Lerp(pos.key_element, pos2.key_element, delta) *-1;\r
+ poslerp = Vector3.Lerp(pos.key_element, pos2.key_element, delta) * -1;\r
\r
- }\r
+ }\r
\r
\r
- Vector3 rotlerp = Vector3.Zero;\r
- if (b.joints[jpos].rotationkeys.Length > 0)\r
+ Vector3 rotlerp = Vector3.Zero;\r
+ if (b.joints[jpos].rotationkeys.Length > 0)\r
+ {\r
+ binBVHJointKey rot2 = b.joints[jpos].rotationkeys[state.nextkeyframe_rot];\r
+\r
+ if (state.currenttime_rot > rot2.time)\r
{\r
- binBVHJointKey rot2 = b.joints[jpos].rotationkeys[state.nextkeyframe_rot];\r
+ state.lastkeyframe_rot++;\r
+ state.nextkeyframe_rot++;\r
\r
- if (state.currenttime_rot > rot2.time)\r
+ if (state.nextkeyframe_rot >= b.joints[jpos].rotationkeys.Length || (state.nextkeyframe_rot >= state.loopoutframe && b.Loop == true))\r
{\r
- state.lastkeyframe_rot++;\r
- state.nextkeyframe_rot++;\r
-\r
- if (state.nextkeyframe_rot >= b.joints[jpos].rotationkeys.Length || (state.nextkeyframe_rot >= state.loopoutframe && b.Loop == true))\r
+ if (b.Loop == true)\r
{\r
- if (b.Loop == true)\r
+ state.nextkeyframe_rot = state.loopinframe;\r
+ state.currenttime_rot = b.InPoint;\r
+\r
+ if (state.lastkeyframe_rot >= b.joints[jpos].rotationkeys.Length)\r
{\r
- state.nextkeyframe_rot = state.loopinframe;\r
- state.currenttime_rot = b.InPoint;\r
+ state.lastkeyframe_rot = state.loopinframe;\r
\r
- if (state.lastkeyframe_rot >= b.joints[jpos].rotationkeys.Length)\r
- {\r
- state.lastkeyframe_rot = state.loopinframe;\r
- \r
- \r
- }\r
\r
}\r
- else\r
- {\r
- state.nextkeyframe_rot = joint.rotationkeys.Length - 1;\r
- }\r
+\r
+ }\r
+ else\r
+ {\r
+ state.nextkeyframe_rot = joint.rotationkeys.Length - 1;\r
}\r
+ }\r
\r
- if (state.lastkeyframe_rot >= b.joints[jpos].rotationkeys.Length)\r
+ if (state.lastkeyframe_rot >= b.joints[jpos].rotationkeys.Length)\r
+ {\r
+ if (b.Loop == true)\r
{\r
- if (b.Loop == true)\r
- {\r
- state.lastkeyframe_rot = 0;\r
- state.currenttime_rot = 0;\r
+ state.lastkeyframe_rot = 0;\r
+ state.currenttime_rot = 0;\r
\r
- }\r
- else\r
- {\r
- state.lastkeyframe_rot = joint.rotationkeys.Length - 1;\r
- }\r
+ }\r
+ else\r
+ {\r
+ state.lastkeyframe_rot = joint.rotationkeys.Length - 1;\r
}\r
}\r
- \r
- binBVHJointKey rot = b.joints[jpos].rotationkeys[state.lastkeyframe_rot];\r
- rot2 = b.joints[jpos].rotationkeys[state.nextkeyframe_rot];\r
+ }\r
\r
- float deltarot = (rot2.time - rot.time) / ((state.currenttime_rot) - (rot.time - b.joints[jpos].rotationkeys[0].time));\r
+ binBVHJointKey rot = b.joints[jpos].rotationkeys[state.lastkeyframe_rot];\r
+ rot2 = b.joints[jpos].rotationkeys[state.nextkeyframe_rot];\r
\r
- \r
- if (deltarot < 0)\r
- deltarot = 0;\r
+ float deltarot = (rot2.time - rot.time) / ((state.currenttime_rot) - (rot.time - b.joints[jpos].rotationkeys[0].time));\r
\r
- if (deltarot > 1)\r
- deltarot = 1;\r
\r
- rotlerp = Vector3.Lerp(rot.key_element, rot2.key_element, deltarot);\r
+ if (deltarot < 0)\r
+ deltarot = 0;\r
\r
- }\r
+ if (deltarot > 1)\r
+ deltarot = 1;\r
\r
- b.joints[jpos].Tag = (object)state;\r
- \r
- deformbone(joint.Name, poslerp, new Vector3(0, 0, 0), new Quaternion(rotlerp.X, rotlerp.Y, rotlerp.Z));\r
+ rotlerp = Vector3.Lerp(rot.key_element, rot2.key_element, deltarot);\r
\r
- jpos++;\r
}\r
\r
- mNeedsMeshRebuild = true;\r
+ b.joints[jpos].Tag = (object)state;\r
+\r
+ deformbone(joint.Name, poslerp, new Vector3(0, 0, 0), new Quaternion(rotlerp.X, rotlerp.Y, rotlerp.Z));\r
+\r
+ jpos++;\r
}\r
\r
+ mNeedsMeshRebuild = true;\r
+ }\r
+\r
mNeedsUpdate = false;\r
}\r
}\r
Vector3 mepre = pos * scale;\r
mepre = mepre * totalrot;\r
mTotalPos = parento + mepre;\r
- \r
+\r
Vector3 orig = getOrigOffset();\r
mDeltaPos = mTotalPos - orig;\r
\r
mDeltaPos = mTotalPos - orig;\r
posdirty = false;\r
return mTotalPos;\r
- \r
+\r
}\r
}\r
\r
\r
public int readblock(byte[] blockdata, int offset)\r
{\r
- \r
- BitPack input = new BitPack(blockdata, offset);\r
- mLocation = input.UnpackInt();\r
- mLength = input.UnpackInt();\r
- mAccessTime = input.UnpackInt();\r
- mFileID = input.UnpackUUID();\r
- int filetype = input.UnpackShort();\r
- mAssetType = (AssetType)filetype;\r
- mSize = input.UnpackInt();\r
- offset += 34;\r
\r
- Logger.Log(String.Format("Found header for {0} type {1} length {2} at {3}", mFileID, mAssetType, mSize, mLocation),Helpers.LogLevel.Info);\r
- \r
- return offset;\r
+ BitPack input = new BitPack(blockdata, offset);\r
+ mLocation = input.UnpackInt();\r
+ mLength = input.UnpackInt();\r
+ mAccessTime = input.UnpackInt();\r
+ mFileID = input.UnpackUUID();\r
+ int filetype = input.UnpackShort();\r
+ mAssetType = (AssetType)filetype;\r
+ mSize = input.UnpackInt();\r
+ offset += 34;\r
+\r
+ Logger.Log(String.Format("Found header for {0} type {1} length {2} at {3}", mFileID, mAssetType, mSize, mLocation), Helpers.LogLevel.Info);\r
+\r
+ return offset;\r
}\r
\r
}\r
datastream = File.Open(datafile, FileMode.Open);\r
indexstream = File.Open(indexfile, FileMode.Open);\r
\r
- int offset=0;\r
+ int offset = 0;\r
\r
byte[] blockdata = new byte[indexstream.Length];\r
indexstream.Read(blockdata, 0, (int)indexstream.Length);\r
VFSblock block = new VFSblock();\r
offset = block.readblock(blockdata, offset);\r
\r
- FileStream writer = File.Open(OpenMetaverse.Settings.RESOURCE_DIR+System.IO.Path.DirectorySeparatorChar+block.mFileID.ToString(),FileMode.Create);\r
+ FileStream writer = File.Open(OpenMetaverse.Settings.RESOURCE_DIR + System.IO.Path.DirectorySeparatorChar + block.mFileID.ToString(), FileMode.Create);\r
byte[] data = new byte[block.mSize];\r
datastream.Seek(block.mLocation, SeekOrigin.Begin);\r
datastream.Read(data, 0, block.mSize);\r
writer.Write(data, 0, block.mSize);\r
writer.Close();\r
}\r
- \r
+\r
}\r
}\r
}
\ No newline at end of file