From 043f01b2da3580be2c6acaf895f1767f662af2d6 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Sun, 18 Mar 2012 17:37:05 +0000 Subject: [PATCH] Correctly apply multiple morphs with same id (on different meshes), correct bone scaling with multiple parameters scaling same bone, and always scale by parent not current bone or the positions go wonky git-svn-id: https://radegast.googlecode.com/svn/trunk@1213 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/GUI/Rendering/RenderAvatar.cs | 102 +++++++++++------ Radegast/GUI/Rendering/RenderSettings.cs | 188 +++++++++++++++---------------- Radegast/GUI/Rendering/Rendering.cs | 28 +++-- 3 files changed, 180 insertions(+), 138 deletions(-) diff --git a/Radegast/GUI/Rendering/RenderAvatar.cs b/Radegast/GUI/Rendering/RenderAvatar.cs index c4f4981..68ac5f2 100644 --- a/Radegast/GUI/Rendering/RenderAvatar.cs +++ b/Radegast/GUI/Rendering/RenderAvatar.cs @@ -678,15 +678,28 @@ namespace Radegast.Rendering } lindenMeshesLoaded = true; - } + } + + public void applyMorph(Avatar av, int param, float weight) - { + { VisualParamEx vpx; + if (VisualParamEx.allParams.TryGetValue(param, out vpx)) - { + { + applyMorph(vpx, av, param, weight); + + foreach (VisualParamEx cvpx in vpx.identicalIds) + { + applyMorph(vpx, av, param, weight); + } + } + } + + public void applyMorph(VisualParamEx vpx, Avatar av, int param, float weight) + { - if (weight < 0) weight = 0; @@ -711,7 +724,7 @@ namespace Radegast.Rendering if (mesh.Name == "skirtMesh" && _showSkirt == false) return; - mesh.morphmesh(morph, weight); + mesh.morphmesh(morph, value); continue; } @@ -756,12 +769,12 @@ namespace Radegast.Rendering { // scale="0 0 .3" /> // value_min="-1" - // value_max="1" - + // value_max="1" + foreach (KeyValuePair kvp in vpx.BoneDeforms) - { - skel.scalebone(kvp.Key, Vector3.One + (kvp.Value.scale *value)); - skel.offsetbone(kvp.Key, kvp.Value.offset * value); + { + skel.scalebone(kvp.Key, Vector3.One + (kvp.Value.scale * value)); + // skel.offsetbone(kvp.Key, kvp.Value.offset * value); } return; } @@ -771,11 +784,7 @@ namespace Radegast.Rendering } } - } - else - { - Logger.Log("Invalid paramater " + param.ToString(), Helpers.LogLevel.Warning); - } + } public void morph(Avatar av) @@ -808,7 +817,9 @@ namespace Radegast.Rendering foreach (GLMesh mesh in _meshes.Values) { mesh.resetallmorphs(); - } + } + + skel.resetbonescales(); foreach (byte vpvalue in av.VisualParameters) { @@ -902,8 +913,6 @@ namespace Radegast.Rendering public skeleton() { - - mBones = new Dictionary(); foreach (Bone src in Bone.mBones.Values) @@ -960,6 +969,14 @@ namespace Radegast.Rendering mLeftEye = mBones["mEyeLeft"]; mRightEye = mBones["mEyeRight"]; + } + + public void resetbonescales() + { + foreach (KeyValuePair src in mBones) + { + src.Value.scale = new Vector3(1, 1, 1); + } } public void deformbone(string name, Vector3 pos, Quaternion rotation) @@ -973,9 +990,11 @@ namespace Radegast.Rendering public void scalebone(string name, Vector3 scale) { + Bone bone; if (mBones.TryGetValue(name, out bone)) - { + { + Logger.Log(String.Format("scalebone() {0} {1}", name, scale.ToString()),Helpers.LogLevel.Info); bone.scalebone(scale); } } @@ -1421,8 +1440,8 @@ namespace Radegast.Rendering public void scalebone(Vector3 scale) { - //this.scale = Bone.mBones[name].orig_scale + scale; - this.scale = scale; + // this.scale = Bone.mBones[name].orig_scale * scale; + this.scale *= scale; markdirty(); } @@ -1461,7 +1480,7 @@ namespace Radegast.Rendering { Quaternion totalrot = getParentRot(); // we don't want this joints rotation included Vector3 parento = parent.getOffset(); - mTotalPos = parento + pos * scale * totalrot; + mTotalPos = parento + pos * parent.scale * totalrot; Vector3 orig = getOrigOffset(); mDeltaPos = mTotalPos - orig; @@ -1472,7 +1491,8 @@ namespace Radegast.Rendering else { Vector3 orig = getOrigOffset(); - mTotalPos = (pos * scale)+offset_pos; + //mTotalPos = (pos * scale)+offset_pos; + mTotalPos = (pos) + offset_pos; mDeltaPos = mTotalPos - orig; posdirty = false; return mTotalPos; @@ -1595,13 +1615,20 @@ namespace Radegast.Rendering static public Dictionary allParams = new Dictionary(); static public Dictionary deformParams = new Dictionary(); - static public Dictionary morphParams = new Dictionary(); + + //static public Dictionary morphParams = new Dictionary(); + + //dirty use of string as indexer, we need to have an enum for meshes + static public Dictionary> morphParams = new Dictionary>(); + static public Dictionary drivenParams = new Dictionary(); static public SortedList tweakable_params = new SortedList(); public Dictionary BoneDeforms = null; public Dictionary VolumeDeforms = null; - public List childparams = null; + public List childparams = null; + + public List identicalIds = new List(); public string morphmesh = null; @@ -1773,15 +1800,17 @@ namespace Radegast.Rendering //TODO other paramaters but these arew concerned with editing the GUI display so not too fussed at the moment - try - { - allParams.Add(ParamID, this); + if(allParams.ContainsKey(ParamID)) + { + //Logger.Log("Duplicate VisualParam in allParams id " + ParamID.ToString(), Helpers.LogLevel.Info); + allParams[ParamID].identicalIds.Add(this); } - catch + else { - Logger.Log("Duplicate VisualParam in allParams id " + ParamID.ToString(), Helpers.LogLevel.Info); + allParams.Add(ParamID, this); } + if (pt == ParamType.TYPE_BONEDEFORM) { // If we are in the skeleton section then we also have bone deforms to parse @@ -1801,14 +1830,23 @@ namespace Radegast.Rendering ParseVolumeDeforms(node.ChildNodes[0].ChildNodes); } + /* try - { - morphParams.Add(ParamID, this); + { + if (!morphParams.ContainsKey(meshname)) + { + morphParams.Add(meshname, new Dictionary()); + } + else + { + morphParams[meshname].Add(ParamID, this); + } } catch { Logger.Log("Duplicate VisualParam in morphParams id " + ParamID.ToString(), Helpers.LogLevel.Info); } + */ } diff --git a/Radegast/GUI/Rendering/RenderSettings.cs b/Radegast/GUI/Rendering/RenderSettings.cs index 30e4b59..f2451e4 100644 --- a/Radegast/GUI/Rendering/RenderSettings.cs +++ b/Radegast/GUI/Rendering/RenderSettings.cs @@ -1,94 +1,94 @@ -// -// Radegast Metaverse Client -// Copyright (c) 2009-2012, Radegast Development Team -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// * Neither the name of the application "Radegast", nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// $Id$ -// - -using System; -using OpenMetaverse; -using OpenMetaverse.Rendering; - -namespace Radegast.Rendering -{ - public static class RenderSettings - { - #region VBO support - public static bool UseVBO; - public static bool CoreVBOPresent; - public static bool ARBVBOPresent; - #endregion VBO support - - #region Occlusion queries - /// Should we try to optimize by not drawing objects occluded behind other objects - public static bool OcclusionCullingEnabled; - public static bool CoreQuerySupported; - public static bool ARBQuerySupported; - #endregion Occlusion queries - - public static bool HasMultiTexturing; - public static bool UseFBO; - public static bool HasMipmap; - public static bool HasShaders; - public static DetailLevel PrimRenderDetail = DetailLevel.High; - public static DetailLevel SculptRenderDetail = DetailLevel.High; - public static DetailLevel MeshRenderDetail = DetailLevel.Highest; - public static bool AllowQuickAndDirtyMeshing = true; - public static int MeshesPerFrame = 2; - public static int TexturesToDownloadPerFrame = 2; - /// Should we try to make sure that large prims that are > our draw distance are in view when we are standing on them - public static bool HeavierDistanceChecking = true; - /// Minimum time between rebuilding terrain mesh and texture - public static float MinimumTimeBetweenTerrainUpdated = 15f; - /// Are textures that don't have dimensions that are powers of two supported - public static bool TextureNonPowerOfTwoSupported; - - /// - /// Render avatars - /// - public static bool AvatarRenderingEnabled = true; - - /// - /// Render prims - /// - public static bool PrimitiveRenderingEnabled = true; - - /// - /// Show avatar skeloton - /// - public static bool RenderAvatarSkeleton = false; - - /// - /// Enable shader for shiny - /// - public static bool EnableShiny = false; - - #region Water - public static bool WaterReflections = false; - #endregion Water - } -} +// +// Radegast Metaverse Client +// Copyright (c) 2009-2012, Radegast Development Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the application "Radegast", nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// $Id$ +// + +using System; +using OpenMetaverse; +using OpenMetaverse.Rendering; + +namespace Radegast.Rendering +{ + public static class RenderSettings + { + #region VBO support + public static bool UseVBO; + public static bool CoreVBOPresent; + public static bool ARBVBOPresent; + #endregion VBO support + + #region Occlusion queries + /// Should we try to optimize by not drawing objects occluded behind other objects + public static bool OcclusionCullingEnabled; + public static bool CoreQuerySupported; + public static bool ARBQuerySupported; + #endregion Occlusion queries + + public static bool HasMultiTexturing; + public static bool UseFBO; + public static bool HasMipmap; + public static bool HasShaders; + public static DetailLevel PrimRenderDetail = DetailLevel.High; + public static DetailLevel SculptRenderDetail = DetailLevel.High; + public static DetailLevel MeshRenderDetail = DetailLevel.Highest; + public static bool AllowQuickAndDirtyMeshing = true; + public static int MeshesPerFrame = 2; + public static int TexturesToDownloadPerFrame = 2; + /// Should we try to make sure that large prims that are > our draw distance are in view when we are standing on them + public static bool HeavierDistanceChecking = true; + /// Minimum time between rebuilding terrain mesh and texture + public static float MinimumTimeBetweenTerrainUpdated = 15f; + /// Are textures that don't have dimensions that are powers of two supported + public static bool TextureNonPowerOfTwoSupported; + + /// + /// Render avatars + /// + public static bool AvatarRenderingEnabled = true; + + /// + /// Render prims + /// + public static bool PrimitiveRenderingEnabled = true; + + /// + /// Show avatar skeloton + /// + public static bool RenderAvatarSkeleton = true; + + /// + /// Enable shader for shiny + /// + public static bool EnableShiny = false; + + #region Water + public static bool WaterReflections = false; + #endregion Water + } +} diff --git a/Radegast/GUI/Rendering/Rendering.cs b/Radegast/GUI/Rendering/Rendering.cs index eb91d31..e817c90 100644 --- a/Radegast/GUI/Rendering/Rendering.cs +++ b/Radegast/GUI/Rendering/Rendering.cs @@ -1193,10 +1193,11 @@ namespace Radegast.Rendering return; } - foreach (VisualParamEx vpe in VisualParamEx.morphParams.Values) - { - comboBox_morph.Items.Add(vpe.Name); - } + //FIX ME + //foreach (VisualParamEx vpe in VisualParamEx.morphParams.Values) + //{ + // comboBox_morph.Items.Add(vpe.Name); + //} foreach (VisualParamEx vpe in VisualParamEx.drivenParams.Values) { @@ -1642,6 +1643,7 @@ namespace Radegast.Rendering Vector3 pos = av.avatar.Position; Vector3 avataroffset = av.glavatar.skel.getOffset("mPelvis"); + avataroffset.X += 1.0f; GL.MultMatrix(Math3D.CreateSRTMatrix(new Vector3(1, 1, 1), av.RenderRotation, av.RenderPosition - avataroffset * av.RenderRotation)); @@ -3521,15 +3523,17 @@ namespace Radegast.Rendering foreach (RenderAvatar av in Avatars.Values) { int id = -1; - foreach (VisualParamEx vpe in VisualParamEx.morphParams.Values) - { - if (vpe.Name == comboBox_morph.Text) - { - id = vpe.ParamID; - break; - } + + //foreach (VisualParamEx vpe in VisualParamEx.morphParams.Values) + //{ + // if (vpe.Name == comboBox_morph.Text) + // { + // id = vpe.ParamID; + // break; + // } + // + //} - } av.glavatar.applyMorph(av.avatar, id, float.Parse(textBox_morphamount.Text)); foreach (GLMesh mesh in av.glavatar._meshes.Values) -- 2.11.0