public BasicRefinedVertexInfo[] GetVertexInfos(ChannelOutputs outputs, Vector3[] controlPositions) { Vector3 center = bone.GetChainedTransform(outputs).Transform(bone.CenterPoint.GetValue(outputs)); double totalDist = 0; foreach (int vertexIdx in attachedVertices) { totalDist += Vector3.Distance(controlPositions[vertexIdx], center); } double radius = totalDist / attachedVertices.Count; Quaternion rotation = bone.Parent.GetChainedTransform(outputs).RotationStage.Rotation; var transform = Matrix.AffineTransformation((float)radius, rotation, center); var transformedSurrogateMesh = OcclusionSurrogateCommon.Mesh.Transform(transform); return(Enumerable.Range(0, transformedSurrogateMesh.VertexCount) .Select(idx => new BasicRefinedVertexInfo { position = transformedSurrogateMesh.VertexPositions[idx], normal = Vector3.Normalize(transformedSurrogateMesh.VertexNormals[idx]) }) .ToArray()); }
private void CheckConsistency(ChannelOutputs channelOutputs) { var inputs = rigidBoneSystem.ReadInputs(channelOutputs); var boneTransformsA = boneSystem.GetBoneTransforms(channelOutputs); var boneTransformsB = rigidBoneSystem.GetBoneTransforms(inputs); for (int i = 0; i < boneSystem.Bones.Count; ++i) { var boneTransformA = boneTransformsA[i]; var boneTransformB = boneTransformsB[i]; var unposedCenterA = boneSystem.Bones[i].CenterPoint.GetValue(channelOutputs); var unposedCenterB = rigidBoneSystem.Bones[i].CenterPoint; foreach (var testVector in new Vector3[] { Vector3.Zero, Vector3.Right, Vector3.Up, Vector3.BackwardRH }) { var transformedVectorA = boneTransformA.Transform(unposedCenterA + testVector); var transformedVectorB = boneTransformB.Transform( unposedCenterB + boneTransformA.ScalingStage.Transform(testVector)); float distance = Vector3.Distance(transformedVectorA, transformedVectorB); if (distance > 1e-3) { throw new Exception("rigid and non-rigid bone transforms are inconsistent"); } } } }
public List <WeightedHdMorph> LoadActiveHdMorphs(ChannelOutputs channelOutputs) { List <WeightedHdMorph> hdMorphs = new List <WeightedHdMorph>(); foreach (var morph in morphs) { float weight = (float)morph.Channel.GetValue(channelOutputs); if (weight == 0) { continue; } var hdFile = morph.HdFile; if (hdFile == null) { continue; } var hdMorph = HdMorphSerialization.LoadHdMorph(hdFile); hdMorphs.Add(new WeightedHdMorph(hdMorph, weight)); } return(hdMorphs); }
public ScalingTransform GetObjectCenteredScalingTransform(ChannelOutputs outputs) { ScalingTransform localSpaceTransform = GetJointCenteredScalingTransform(outputs); Vector3 centerPoint = CenterPoint.GetValue(outputs); return(ScalingTransform.FromTranslation(-centerPoint).Chain(localSpaceTransform).Chain(ScalingTransform.FromTranslation(+centerPoint))); }
public OrientationSpace GetOrientationSpace(ChannelOutputs outputs) { Vector3 orientationAngles = Orientation.GetValue(outputs); Quaternion orientation = RotationOrder.DazStandard.FromEulerAngles(MathExtensions.DegreesToRadians(orientationAngles)); return(new OrientationSpace(orientation)); }
public Info GetInfo(ChannelOutputs outputs) { return(new Info( bone.CenterPoint.GetValue(outputs), offsetInOcclusionInfos, bone.GetRotation(outputs))); }
public AnimationDumper(Figure figure, DirectoryInfo figureDestDir) { this.figure = figure; this.animationsDirectory = figureDestDir.Subdirectory("animations"); this.orientationOutputs = figure.ChannelSystem.DefaultOutputs; //orientation doesn't seem to change between actors so we can use default outputs }
public void Apply(ChannelOutputs channelOutputs, Vector3[] vertices) { for (int morphIdx = 0; morphIdx < morphs.Count; ++morphIdx) { morphs[morphIdx].Apply(channelOutputs, vertices); } }
/// <summary> /// Writes FPP Universe file in 2.x json format /// </summary> /// <param name="fileName"></param> /// <returns></returns> public async Task Write2xUniverseFile(string fileName) { var fppStartChannel = 1; FppOutputConfiguration config = new FppOutputConfiguration(); ChannelOutputs channelOutputs = new ChannelOutputs(); config.ChannelOutputs.Add(channelOutputs); foreach (var controller in ControllerExportInfo.Where(x => x.IsActive).OrderBy(x => x.Index)) { if (controller.HasNetworkSupport) { var universes = controller.ControllerNetworkConfiguration.Universes; foreach (var uc in universes) { Universe u = new Universe(); channelOutputs.Universes.Add(u); string ip = string.Empty; if (!uc.IsMultiCast) { //Validate ip address ip = uc.IpAddress?.Address.ToString(); if (ip == null) { ip = string.Empty; } u.Address = ip; } u.Description = controller.Name; u.UniverseType = uc.IsMultiCast?UniverseTypes.E131_Multicast:UniverseTypes.E131_Unicast; u.Active = uc.Active; u.ChannelCount = uc.Size; u.StartChannel = fppStartChannel; u.UniverseId = uc.Universe; fppStartChannel = fppStartChannel + uc.Size; } } else { fppStartChannel = fppStartChannel + controller.Channels; } } using (var writer = new StreamWriter(fileName)) { DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; var s = JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings { ContractResolver = contractResolver }); await writer.WriteAsync(s); await writer.FlushAsync(); } }
public RigidTransform GetOriginToBindPoseTransform(ChannelOutputs outputs) { Vector3 orientationAngles = Orientation.GetValue(outputs); Vector3 centerPoint = CenterPoint.GetValue(outputs); Quaternion orientation = RotationOrder.DazStandard.FromEulerAngles(MathExtensions.DegreesToRadians(orientationAngles)); return(RigidTransform.FromRotationTranslation(orientation, centerPoint)); }
public Vector3 GetValue(ChannelOutputs outputs) { return(new Vector3( (float)X.GetValue(outputs), (float)Y.GetValue(outputs), (float)Z.GetValue(outputs) )); }
public ChannelOutputs Evaluate(ChannelOutputs parentOutputs, ChannelInputs inputs) { double[] valuesOut = new double[channelCount]; eval(parentOutputs?.Values, inputs.RawValues, valuesOut, splines); return(new ChannelOutputs(parentOutputs, valuesOut)); }
private DualQuaternion GetObjectCenteredRotationTransform(ChannelOutputs outputs, ScalingTransform parentScale) { DualQuaternion localSpaceTransform = GetJointCenteredRotationTransform(outputs, parentScale.Scale); Vector3 centerPoint = CenterPoint.GetValue(outputs); centerPoint = parentScale.Transform(centerPoint); return(DualQuaternion.FromTranslation(-centerPoint).Chain(localSpaceTransform).Chain(DualQuaternion.FromTranslation(+centerPoint))); }
private DualQuaternion GetJointCenteredRotationTransform(ChannelOutputs outputs, Matrix3x3 parentScale) { Quaternion worldSpaceRotation = GetRotation(outputs); Vector3 translation = Vector3.Transform(Translation.GetValue(outputs), parentScale); return(DualQuaternion.FromRotationTranslation(worldSpaceRotation, translation)); }
public ChannelSystem(ChannelSystem parent, List <Channel> channels) { this.parent = parent; this.channels = channels; this.channelsByName = channels.ToDictionary(channel => channel.Name, channel => channel); this.channelEvaluator = new ChannelEvaluator(channels); this.defaultOutputs = Evaluate(parent?.defaultOutputs, MakeDefaultChannelInputs()); }
/* * Shaping System */ public Vector3[] CalculateControlPositions(ChannelOutputs channelOutputs, Vector3[] baseDeltas) { Vector3[] controlVertices = Geometry.VertexPositions.Select(p => p).ToArray(); Morpher.Apply(channelOutputs, controlVertices); automorpher?.Apply(baseDeltas, controlVertices); StagedSkinningTransform[] boneTransforms = GetBoneTransforms(channelOutputs); SkinBinding.Apply(boneTransforms, controlVertices); return(controlVertices); }
public AnimationDumper(Figure figure) { this.figure = figure; var figureDirectory = CommonPaths.WorkDir.Subdirectory("figures").Subdirectory(figure.Name); this.animationsDirectory = figureDirectory.Subdirectory("animations"); this.orientationOutputs = figure.ChannelSystem.DefaultOutputs; //orientation doesn't seem to change between actors so we can use default outputs }
public void SetValues(DeviceContext context, ChannelOutputs channelOutputs) { if (parametersResources == null) { return; } float[] weights = channelIndices.Select(idx => (float)channelOutputs.Values[idx]).ToArray(); parametersResources.channelWeightsBufferManager.Update(context, weights); }
public StagedSkinningTransform GetChainedTransform(ChannelOutputs outputs, StagedSkinningTransform parentTransform) { ScalingTransform scalingTransform = GetObjectCenteredScalingTransform(outputs); ScalingTransform chainedScalingTransform = scalingTransform.Chain(parentTransform.ScalingStage); DualQuaternion rotationTransform = GetObjectCenteredRotationTransform(outputs, parentTransform.ScalingStage); DualQuaternion chainedRotationTransform = rotationTransform.Chain(parentTransform.RotationStage); return(new StagedSkinningTransform(chainedScalingTransform, chainedRotationTransform)); }
public StagedSkinningTransform[] GetBoneTransforms(ChannelOutputs outputs) { var boneTransforms = boneSystem.GetBoneTransforms(outputs); if (childToParentBindPoseTransforms != null) { BoneSystem.PrependChildToParentBindPoseTransforms(childToParentBindPoseTransforms, boneTransforms); } return(boneTransforms); }
private Matrix3x3 GetCombinedScale(ChannelOutputs outputs) { Vector3 scale = Scale.GetValue(outputs); float generalScale = (float)GeneralScale.GetValue(outputs); var objectSpaceScaling = Matrix3x3.Scaling(scale * generalScale); OrientationSpace orientationSpace = GetOrientationSpace(outputs); var orientedSpaceScaling = orientationSpace.TransformToOrientedSpace(objectSpaceScaling); return(orientedSpaceScaling); }
public void WriteInputs(ChannelInputs channelInputs, ChannelOutputs channelOutputs, RigidBoneSystemInputs inputs) { source.RootBone.Translation.SetEffectiveValue(channelInputs, channelOutputs, inputs.RootTranslation, SetMask.ApplyClampAndVisibleOnly); for (int boneIdx = 0; boneIdx < bones.Length; ++boneIdx) { var bone = bones[boneIdx]; var rotation = inputs.Rotations[boneIdx]; var rotationAngles = MathExtensions.RadiansToDegrees(bone.RotationOrder.ToTwistSwingAngles(rotation)); bone.Source.Rotation.SetEffectiveValue(channelInputs, channelOutputs, rotationAngles, SetMask.ApplyClampAndVisibleOnly); } }
private ScalingTransform GetJointCenteredScalingTransform(ChannelOutputs outputs) { Matrix3x3 scale = GetCombinedScale(outputs); if (!InheritsScale && Parent != null) { scale = Matrix3x3.Invert(Parent.GetCombinedScale(outputs)) * scale; } return(ScalingTransform.FromScale(scale)); }
private void UpdateEye(ChannelOutputs outputs, StagedSkinningTransform eyeParentTotalTransform, ChannelInputs inputs, Bone eyeBone, Vector3 targetPosition) { Vector3 targetPositionInRotationFreeEyeSpace = eyeParentTotalTransform.InverseTransform(targetPosition * 100) - eyeBone.CenterPoint.GetValue(outputs); var targetRotation = QuaternionExtensions.RotateBetween(Vector3.BackwardRH, targetPositionInRotationFreeEyeSpace); targetRotation = Quaternion.RotationAxis( targetRotation.Axis, TukeysBiweight(targetRotation.Angle, RotationAngleRejectionThreshold)); eyeBone.SetEffectiveRotation(inputs, outputs, targetRotation); }
public void Synchronize(ChannelOutputs outputs) { while (outputs.Parent != null) { outputs = outputs.Parent; } for (int boneIdx = 0; boneIdx < bones.Length; ++boneIdx) { RigidBone bone = bones[boneIdx]; bone.Synchronize(outputs); } }
public Quaternion GetRotation(ChannelOutputs outputs) { OrientationSpace orientationSpace = GetOrientationSpace(outputs); Vector3 rotationAngles = Rotation.GetValue(outputs); TwistSwing rotationTwistSwing = RotationOrder.FromTwistSwingAngles(MathExtensions.DegreesToRadians(rotationAngles)); rotationTwistSwing = RotationConstraint.Clamp(rotationTwistSwing); Quaternion orientedSpaceRotation = rotationTwistSwing.AsQuaternion(RotationOrder.TwistAxis); Quaternion worldSpaceRotation = orientationSpace.TransformFromOrientedSpace(orientedSpaceRotation); return(worldSpaceRotation); }
public void Synchronize(ChannelOutputs outputs) { ScalingTransform parentScalingTransform = Parent != null ? Parent.chainedScalingTransform : ScalingTransform.Identity; Vector3 parentTranslation = Parent != null ? Parent.chainedTranslation : Vector3.Zero; var sourceTranslation = Parent != null?Source.Translation.GetValue(outputs) : Vector3.Zero; //don't bake in translation for root bone chainedScalingTransform = Source.GetObjectCenteredScalingTransform(outputs).Chain(parentScalingTransform); chainedTranslation = Vector3.Transform(sourceTranslation, parentScalingTransform.Scale) + parentTranslation; Vector3 sourceCenter = Source.CenterPoint.GetValue(outputs); centerPoint = parentScalingTransform.Transform(sourceCenter) + chainedTranslation; orientationSpace = Source.GetOrientationSpace(outputs); }
public Vector3 ConvertRotationToAngles(ChannelOutputs orientationOutputs, Quaternion objectSpaceRotation, bool applyClamp) { OrientationSpace orientationSpace = GetOrientationSpace(orientationOutputs); Quaternion orientatedSpaceRotationQ = orientationSpace.TransformToOrientedSpace(objectSpaceRotation); TwistSwing orientatedSpaceRotation = TwistSwing.Decompose(RotationOrder.TwistAxis, orientatedSpaceRotationQ); if (applyClamp) { orientatedSpaceRotation = RotationConstraint.Clamp(orientatedSpaceRotation); } Vector3 rotationAnglesRadians = RotationOrder.ToTwistSwingAngles(orientatedSpaceRotation); Vector3 rotationAnglesDegrees = MathExtensions.RadiansToDegrees(rotationAnglesRadians); return(rotationAnglesDegrees); }
public void Apply(ChannelOutputs channelOutputs, Vector3[] vertices) { float weight = (float)channel.GetValue(channelOutputs); //Console.WriteLine("Applying " + channel.Name + " at " + weight + "..."); if (weight == 0) { return; } foreach (var delta in deltas) { vertices[delta.VertexIdx] += weight * delta.PositionOffset; } }
public void SetEffectiveValue(ChannelInputs inputs, ChannelOutputs outputsForDelta, double value, SetMask mask = SetMask.Any) { if (Locked) { return; } if (mask.HasFlag(SetMask.ApplyClamp) && Clamped) { value = EvaluatorHelperMethods.Clamp(value, Min, Max); } double delta = value - outputsForDelta.Values[this.Index]; inputs.RawValues[this.Index] += delta; }