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());
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 4
0
    public ScalingTransform GetObjectCenteredScalingTransform(ChannelOutputs outputs)
    {
        ScalingTransform localSpaceTransform = GetJointCenteredScalingTransform(outputs);
        Vector3          centerPoint         = CenterPoint.GetValue(outputs);

        return(ScalingTransform.FromTranslation(-centerPoint).Chain(localSpaceTransform).Chain(ScalingTransform.FromTranslation(+centerPoint)));
    }
Ejemplo n.º 5
0
    public OrientationSpace GetOrientationSpace(ChannelOutputs outputs)
    {
        Vector3    orientationAngles = Orientation.GetValue(outputs);
        Quaternion orientation       = RotationOrder.DazStandard.FromEulerAngles(MathExtensions.DegreesToRadians(orientationAngles));

        return(new OrientationSpace(orientation));
    }
Ejemplo n.º 6
0
 public Info GetInfo(ChannelOutputs outputs)
 {
     return(new Info(
                bone.CenterPoint.GetValue(outputs),
                offsetInOcclusionInfos,
                bone.GetRotation(outputs)));
 }
Ejemplo n.º 7
0
    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);
     }
 }
Ejemplo n.º 9
0
        /// <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();
            }
        }
Ejemplo n.º 10
0
    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));
    }
Ejemplo n.º 11
0
 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));
    }
Ejemplo n.º 13
0
    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)));
    }
Ejemplo n.º 14
0
    private DualQuaternion GetJointCenteredRotationTransform(ChannelOutputs outputs, Matrix3x3 parentScale)
    {
        Quaternion worldSpaceRotation = GetRotation(outputs);

        Vector3 translation = Vector3.Transform(Translation.GetValue(outputs), parentScale);

        return(DualQuaternion.FromRotationTranslation(worldSpaceRotation, translation));
    }
Ejemplo n.º 15
0
    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());
    }
Ejemplo n.º 16
0
    /*
     * 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);
    }
Ejemplo n.º 17
0
    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
    }
Ejemplo n.º 18
0
    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);
    }
Ejemplo n.º 19
0
    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));
    }
Ejemplo n.º 20
0
    public StagedSkinningTransform[] GetBoneTransforms(ChannelOutputs outputs)
    {
        var boneTransforms = boneSystem.GetBoneTransforms(outputs);

        if (childToParentBindPoseTransforms != null)
        {
            BoneSystem.PrependChildToParentBindPoseTransforms(childToParentBindPoseTransforms, boneTransforms);
        }
        return(boneTransforms);
    }
Ejemplo n.º 21
0
    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);
    }
Ejemplo n.º 22
0
 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);
     }
 }
Ejemplo n.º 23
0
    private ScalingTransform GetJointCenteredScalingTransform(ChannelOutputs outputs)
    {
        Matrix3x3 scale = GetCombinedScale(outputs);

        if (!InheritsScale && Parent != null)
        {
            scale = Matrix3x3.Invert(Parent.GetCombinedScale(outputs)) * scale;
        }

        return(ScalingTransform.FromScale(scale));
    }
Ejemplo n.º 24
0
    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);
    }
Ejemplo n.º 25
0
    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);
        }
    }
Ejemplo n.º 26
0
    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);
    }
Ejemplo n.º 28
0
    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);
    }
Ejemplo n.º 29
0
    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;
    }