public OccluderLoader(Device device, ShaderCache shaderCache, FigureDefinition figureDefinition)
 {
     this.device                 = device;
     this.shaderCache            = shaderCache;
     channelSystem               = figureDefinition.ChannelSystem;
     unmorphedOcclusionDirectory = figureDefinition.Directory.Subdirectory("occlusion");
 }
    public SpeechAnimator(ChannelSystem channelSystem, BoneSystem boneSystem)
    {
        this.channelSystem = channelSystem;
        this.boneSystem    = boneSystem;

        this.synth   = new SpeechSynthesizer();
        synth.Volume = 100;

        synth.SelectVoice(Voice);
        synth.VisemeReached += Synth_VisemeReached;

        visemeChannels = VisemeChannelMap
                         .Select(name => name == null ? null : channelSystem.ChannelsByName[name + "?value"])
                         .ToArray();

        headBone = boneSystem.BonesByName["head"];

        var audioDevice = new XAudio2(XAudio2Flags.DebugEngine, ProcessorSpecifier.AnyProcessor);

        masteringVoice = new MasteringVoice(audioDevice);

        WaveFormat monoWaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2);

        sourceVoice = new SourceVoice(audioDevice, monoWaveFormat, VoiceFlags.None);
        sourceVoice.SetVolume(1);
        sourceVoice.Start();

        phononStream = new PhononSourceVoiceStream(sourceVoice);
        synth.SetOutputToAudioStream(phononStream, new SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
    }
    public InverseKinematicsPerformanceDemo()
    {
        var figureDir = UnpackedArchiveDirectory.Make(new System.IO.DirectoryInfo("work/figures/genesis-3-female"));

        var channelSystemRecipe = Persistance.Load <ChannelSystemRecipe>(figureDir.File("channel-system-recipe.dat"));

        channelSystem = channelSystemRecipe.Bake(null);

        var boneSystemRecipe = Persistance.Load <BoneSystemRecipe>(figureDir.File("bone-system-recipe.dat"));

        boneSystem = boneSystemRecipe.Bake(channelSystem.ChannelsByName);

        var inverterParameters = Persistance.Load <InverterParameters>(figureDir.File("inverter-parameters.dat"));

        rigidBoneSystem = new RigidBoneSystem(boneSystem);

        goalProvider = new DemoInverseKinematicsGoalProvider(rigidBoneSystem);
        solver       = new HarmonicInverseKinematicsSolver(rigidBoneSystem, inverterParameters.BoneAttributes);

        var pose          = Persistance.Load <List <Pose> >(figureDir.File("animations/idle.dat"))[0];
        var channelInputs = channelSystem.MakeDefaultChannelInputs();

        new Poser(channelSystem, boneSystem).Apply(channelInputs, pose, DualQuaternion.Identity);
        var channelOutputs = channelSystem.Evaluate(null, channelInputs);

        rigidBoneSystem.Synchronize(channelOutputs);
        initialInputs = rigidBoneSystem.ReadInputs(channelOutputs);
    }
示例#4
0
    private static RigidTransform[] MakeChildToParentBindPoseTransforms(
        ChannelSystem channelSystem,
        BoneSystem selfBoneSystem,
        BoneSystem parentBoneSystem)
    {
        var childToParentBindPoseTransforms = parentBoneSystem.Bones
                                              .Select(parentBone => {
            selfBoneSystem.BonesByName.TryGetValue(parentBone.Name, out var childBone);
            if (childBone == null)
            {
                return(RigidTransform.Identity);
            }

            var originToChildBindPoseTransform  = childBone.GetOriginToBindPoseTransform(channelSystem.DefaultOutputs);
            var originToParentBindPoseTransform = parentBone.GetOriginToBindPoseTransform(channelSystem.Parent.DefaultOutputs);

            var childBonePoseToParentBindPoseTransform =
                originToChildBindPoseTransform.Invert().Chain(originToParentBindPoseTransform);

            return(childBonePoseToParentBindPoseTransform);
        })
                                              .ToArray();

        return(childToParentBindPoseTransforms);
    }
示例#5
0
 public BoneAttributesCalculator(ChannelSystem channelSystem, BoneSystem boneSystem, Geometry geometry, SkinBinding skinBinding)
 {
     this.channelSystem = channelSystem;
     this.boneSystem    = boneSystem;
     this.geometry      = geometry;
     this.skinBinding   = skinBinding;
 }
    public ExpressionAnimator(ChannelSystem channelSystem)
    {
        expressionChannels = ExpressionChannelNames
                             .Select(name => channelSystem.ChannelsByName[name])
                             .ToArray();

        nextExpression = expressionChannels[rnd.Next(expressionChannels.Length)];
    }
示例#7
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());
    }
 public InverseKinematicsAnimator(ControllerManager controllerManager, FigureDefinition definition, InverterParameters inverterParameters)
 {
     channelSystem = definition.ChannelSystem;
     boneSystem    = new RigidBoneSystem(definition.BoneSystem);
     goalProvider  = new InverseKinematicsUserInterface(controllerManager, channelSystem, boneSystem, inverterParameters);
     //goalProvider = new DemoInverseKinematicsGoalProvider(boneSystem);
     solver     = new HarmonicInverseKinematicsSolver(boneSystem, inverterParameters.BoneAttributes);
     poseDeltas = boneSystem.MakeZeroInputs();
     Reset();
 }
示例#9
0
    public static Shape Load(ChannelSystem channelSystem, IArchiveDirectory shapeDirectory)
    {
        var channelInputsFile = shapeDirectory.File("channel-inputs.dat");
        var channelInputs     = LoadChannelInputs(channelSystem, channelInputsFile);

        var parentOverridesFile = shapeDirectory.File("parent-overrides.dat");
        var parentOverrides     = LoadParentOverrides(channelSystem, parentOverridesFile);

        return(new Shape(shapeDirectory.Name, shapeDirectory, channelInputs, parentOverrides));
    }
示例#10
0
    public InverseKinematicsUserInterface(ControllerManager controllerManager, ChannelSystem channelSystem, RigidBoneSystem boneSystem, InverterParameters inverterParameters)
    {
        this.channelSystem      = channelSystem;
        this.boneSystem         = boneSystem;
        this.inverterParameters = inverterParameters;

        deviceTrackers = controllerManager.StateTrackers
                         .Select(stateTracker => new DeviceTracker(this, stateTracker))
                         .ToArray();
    }
示例#11
0
    public OccluderChannelPicker(ChannelSystem channelSystem)
    {
        this.channelSystem = channelSystem;

        isFormulaInput = new bool[channelSystem.Channels.Count];

        foreach (Channel channel in channelSystem.Channels)
        {
            TagInputs(channel);
        }
    }
示例#12
0
    public BreastGravityAnimator(ChannelSystem channelSystem, BoneSystem boneSystem)
    {
        this.channelSystem = channelSystem;
        this.boneSystem    = boneSystem;

        chestBone     = boneSystem.BonesByName["chestUpper"];
        lPectoralBone = boneSystem.BonesByName["lPectoral"];
        rPectoralBone = boneSystem.BonesByName["rPectoral"];

        flattenChannel     = channelSystem.ChannelsByName["pCTRLBreastsFlatten?value"];
        hangForwardChannel = channelSystem.ChannelsByName["pCTRLBreastsHangForward?value"];
    }
示例#13
0
    /*
     * // Update is called once per frame
     * void Update () {
     *      if (Input.GetMouseButtonDown(0)) {
     *              RaycastHit hit;
     *              if (Physics.Raycast (cam.ScreenPointToRay(Input.mousePosition), out hit)) {
     *                      Debug.Log (hit.textureCoord2);
     *                      Camera c=ChannelSystem.GetInstance ().c [ChannelSystem.GetInstance ().channelIndex].GetChannelLevel ().GetCamera ();
     *                      Ray r = c.ViewportPointToRay (hit.textureCoord);
     *
     *                      rayTester.SetPosition(0,r.origin);
     *                      rayTester.SetPosition(1,r.origin+ r.direction*1000);
     *                      MouseButtonDown (0, hit.textureCoord);
     *              }
     *      }
     * }
     * void empty(int i, Vector2 xy){
     *
     * }
     */
    public static Ray GetScreenMouseRay()
    {
        RaycastHit hit;
        Ray        r = new Ray();

        if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit))
        {
            Camera c = ChannelSystem.GetInstance().c [ChannelSystem.GetInstance().channelIndex].GetChannelLevel().GetCamera();
            r = c.ViewportPointToRay(hit.textureCoord);
        }
        return(r);
    }
示例#14
0
    public ChannelSystem Bake(ChannelSystem parent)
    {
        var channels = new List <Channel>();

        Channels.ForEach(recipe => recipe.Bake(channels, parent?.ChannelsByName));

        var channelsByName = channels.ToDictionary(channel => channel.Name, channel => channel);

        Formulas.ForEach(recipe => recipe.Bake(channelsByName));

        return(new ChannelSystem(parent, channels));
    }
示例#15
0
    public static Shape LoadDefault(ChannelSystem channelSystem, IArchiveDirectory figureDirectory)
    {
        var channelInputsFile = figureDirectory.File("channel-inputs.dat");
        var channelInputs     = channelInputsFile != null?
                                LoadChannelInputs(channelSystem, channelInputsFile) :
                                    channelSystem.MakeDefaultChannelInputs();

        var parentOverridesFile = figureDirectory.File("parent-overrides.dat");
        var parentOverrides     = LoadParentOverrides(channelSystem, parentOverridesFile);

        return(new Shape(DefaultLabel, null, channelInputs, parentOverrides));
    }
 public FigureDefinition(string name, IArchiveDirectory directory,
                         ChannelSystem channelSystem, BoneSystem boneSystem,
                         RigidTransform[] childToParentBindPoseTransforms,
                         List <Shape> shapeOptions, List <MaterialSetOption> materialSetOptions)
 {
     Name          = name;
     Directory     = directory;
     ChannelSystem = channelSystem;
     BoneSystem    = boneSystem;
     ChildToParentBindPoseTransforms = childToParentBindPoseTransforms;
     ShapeOptions       = shapeOptions;
     MaterialSetOptions = materialSetOptions;
 }
示例#17
0
 // Use this for initialization
 void Awake()
 {
     if (instance == null)
     {
         instance       = this;
         activeChannels = new List <ChannelLevel> ();
     }
     else if (instance != this)
     {
         Debug.Log("Channel System already exists, committing seppuku");
         Destroy(this.gameObject);
     }
 }
示例#18
0
 public static ChannelSystem GetInstance()
 {
     if (ChannelSystem.instance == null)
     {
         Debug.Log("Creating CHannel System");
         GameObject temp = new GameObject("ChannelSystem");
         instance = temp.AddComponent <ChannelSystem> ();
         instance.Init();
         Debug.Log("Lazy instantiation assuming a level is being loaded");
         instance.waitForRegister = true;
     }
     return(ChannelSystem.instance);
 }
示例#19
0
    public DeformableOccluder(Device device, ShaderCache shaderCache, ChannelSystem channelSystem, OcclusionInfo[] unmorphedOcclusionInfos, OccluderParameters parameters)
    {
        this.unmorphedOcclusionInfos = unmorphedOcclusionInfos;

        shader = shaderCache.GetComputeShader <DeformableOccluder>("figure/occlusion/shader/Occluder");

        unmorphedWithoutChildrenOcclusionInfosView       = BufferUtilities.ToStructuredBufferView(device, OcclusionInfo.PackArray(unmorphedOcclusionInfos));
        unmorphedWithChildrenOcclusionInfosBufferManager = new StructuredBufferManager <uint>(device, unmorphedOcclusionInfos.Length);

        parametersResources = OccluderParametersResources.Make(device, parameters);
        channelIndices      = parameters.ChannelNames
                              .Select(channelName => channelSystem.ChannelsByName[channelName].Index)
                              .ToArray();
    }
示例#20
0
    public HeadLookAtAnimator(ChannelSystem channelSystem, BoneSystem boneSystem)
    {
        this.channelSystem = channelSystem;
        this.boneSystem    = boneSystem;

        headBone     = boneSystem.BonesByName["head"];
        leftEyeBone  = boneSystem.BonesByName["lEye"];
        rightEyeBone = boneSystem.BonesByName["rEye"];

        if (leftEyeBone.Parent != headBone || rightEyeBone.Parent != headBone)
        {
            throw new InvalidOperationException("expected parent of eyes to be head");
        }
    }
示例#21
0
    private static ChannelInputs LoadChannelInputs(ChannelSystem channelSystem, IArchiveFile channelInputsFile)
    {
        var shapeInputsByName = Persistance.Load <Dictionary <string, double> >(channelInputsFile);

        ChannelInputs channelInputs = channelSystem.MakeDefaultChannelInputs();

        foreach (var entry in shapeInputsByName)
        {
            Channel channel = channelSystem.ChannelsByName[entry.Key];
            channel.SetValue(channelInputs, entry.Value);
        }

        return(channelInputs);
    }
示例#22
0
    public EyeLookAtAnimator(ChannelSystem channelSystem, BoneSystem boneSystem, BehaviorModel behaviorModel)
    {
        this.channelSystem = channelSystem;
        this.boneSystem    = boneSystem;
        this.behaviorModel = behaviorModel;

        leftEyeBone  = boneSystem.BonesByName["lEye"];
        rightEyeBone = boneSystem.BonesByName["rEye"];

        eyeParentBone = leftEyeBone.Parent;
        if (eyeParentBone != rightEyeBone.Parent)
        {
            throw new Exception("expected eyes to have same parent");
        }
    }
 public Figure(string name, Figure parent, FigureRecipe recipe, Geometry geometry, ChannelSystem channelSystem, BoneSystem boneSystem, RigidTransform[] childToParentBindPoseTransforms, Morpher morpher, Automorpher automorpher, SkinBinding skinBinding, Dictionary <string, UvSet> uvSets, UvSet defaultUvSet, OcclusionBinding occlusionBinding)
 {
     this.name          = name;
     this.parent        = parent;
     this.recipe        = recipe;
     this.geometry      = geometry;
     this.channelSystem = channelSystem;
     this.boneSystem    = boneSystem;
     this.childToParentBindPoseTransforms = childToParentBindPoseTransforms;
     this.morpher          = morpher;
     this.automorpher      = automorpher;
     this.skinBinding      = skinBinding;
     this.uvSets           = uvSets;
     this.defaultUvSet     = defaultUvSet;
     this.occlusionBinding = occlusionBinding;
 }
示例#24
0
    public BoneSystemPerformanceDemo()
    {
        var figureDir = UnpackedArchiveDirectory.Make(new System.IO.DirectoryInfo("work/figures/genesis-3-female"));

        var channelSystemRecipe = Persistance.Load <ChannelSystemRecipe>(figureDir.File("channel-system-recipe.dat"));

        channelSystem = channelSystemRecipe.Bake(null);

        var boneSystemRecipe = Persistance.Load <BoneSystemRecipe>(figureDir.File("bone-system-recipe.dat"));

        boneSystem = boneSystemRecipe.Bake(channelSystem.ChannelsByName);

        var pose = Persistance.Load <List <Pose> >(figureDir.File("animations/idle.dat"))[0];

        inputs = channelSystem.MakeDefaultChannelInputs();
        new Poser(channelSystem, boneSystem).Apply(inputs, pose, DualQuaternion.Identity);
    }
示例#25
0
    private static ParentOverride[] LoadParentOverrides(ChannelSystem channelSystem, IArchiveFile parentOverridesFile)
    {
        if (parentOverridesFile == null)
        {
            return(null);
        }

        var parentChannelSystem   = channelSystem.Parent;
        var parentOverridesByName = Persistance.Load <Dictionary <string, double> >(parentOverridesFile);
        var parentOverrides       = parentOverridesByName
                                    .Select(entry => new ParentOverride {
            channel = parentChannelSystem.ChannelsByName[entry.Key],
            value   = entry.Value
        })
                                    .ToArray();

        return(parentOverrides);
    }
示例#26
0
    public static List <Shape> LoadAllForFigure(IArchiveDirectory figureDir, ChannelSystem channelSystem)
    {
        List <Shape> shapes = new List <Shape>();

        IArchiveDirectory shapesDirectory = figureDir.Subdirectory("shapes");

        if (shapesDirectory != null)
        {
            foreach (var shapeDirectory in shapesDirectory.Subdirectories)
            {
                var shape = Shape.Load(channelSystem, shapeDirectory);
                shapes.Add(shape);
            }
        }
        else
        {
            var defaultShape = Shape.LoadDefault(channelSystem, figureDir);
            shapes.Add(defaultShape);
        }

        return(shapes);
    }
示例#27
0
 public ChannelShaker(ChannelSystem channelSystem)
 {
     isDirectlyUsed = new bool[channelSystem.Channels.Count];
 }
 public BlinkAnimator(ChannelSystem channelSystem)
 {
     eyesClosedChannel = channelSystem.ChannelsByName["eCTRLEyesClosed?value"];
 }
示例#29
0
 // Use this for initialization
 void Start()
 {
     ChannelSystem.GetInstance().RegisterChannel(this);
     Init();
 }
示例#30
0
    private IEnumerable <Channel> GetChannelsForOcclusionSystem()
    {
        ChannelSystem channelSystem = figureGroup.Parent.ChannelSystem;

        return(new OccluderChannelPicker(channelSystem).GetChannels());
    }