Пример #1
0
    private void createSlaveAnimationFromPreview(NPVoxAnimation animation, NPVoxIModelFactory inputModelFactory)
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>(AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(inputModelFactory as Object)).name + "_" + animation.name);

        if (path.Length != 0)
        {
            NPVoxAnimation slaveAnimation = NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path);
            foreach (NPVoxFrame sourceFrame in animation.Frames)
            {
                NPVoxFrame targetFrame = slaveAnimation.AppendFrame();

                NPVoxSocketAttachment attachment = sourceFrame.GetPreviewAttachmentForFactory(inputModelFactory);
                if (attachment == null)
                {
                    Debug.LogWarning("no attachment found for the given model factory");
                    continue;
                }

                targetFrame.Source = inputModelFactory;
                NPVoxModelSocketCombiner combiner = NPVoxModelSocketCombiner.CreateInstance <NPVoxModelSocketCombiner>();

                if (!sourceFrame.PreOutput)
                {
                    sourceFrame.FixStuff();
                }
                combiner.Target           = sourceFrame.PreOutput;
                combiner.InputSocketName  = attachment.sourceSocketName;
                combiner.TargetSocketName = attachment.targetSocketName;
                targetFrame.AppendTransformer(combiner);
            }

            Selection.objects = new Object[] { slaveAnimation };
        }
    }
    public void SetSourceSocketForTargetSocket(string targetSocketName, string sourceSocketName)
    {
        Undo.RecordObjects(new Object[] { this, animation }, "set preview source socket");
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, true);

        p.sourceSocketName = sourceSocketName;
        FireOnMeshChange();
    }
    public void SetPreviewFactoryForTargetSocket(string targetSocketName, NPVoxIMeshFactory meshFactory)
    {
        Undo.RecordObjects(new Object[] { this, animation }, "set preview socket factory enabled");
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, true);

        p.meshFactory = meshFactory as NPVoxMeshOutput;
        wipePreviewMeshFactories(targetSocketName);
    }
    public void SetPreviewSocketEnabled(string targetSocketName, bool val)
    {
        Undo.RecordObjects(new Object[] { this, animation }, "set preview socket enabled");
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, true);

        p.visible = val;
        FireOnMeshChange();
    }
    public string GetSourceSocketForTargetSocket(string targetSocketName)
    {
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, false);

        if (p != null)
        {
            return(p.sourceSocketName);
        }
        return(null);
    }
    public NPVoxIMeshFactory GetPreviewFactoryForTargetSocket(string targetSocketName)
    {
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, false);

        if (p != null)
        {
            return(p.meshFactory);
        }
        return(null);
    }
    public NPVoxIMeshFactory GetSocketPreviewMeshFactoryForCurrentFrame(string targetSocketName)
    {
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName);

        if (this.selectedFrameIndex < 0 || p == null)
        {
            return(null);
        }

        NPVoxIModelFactory modelFactory = GetPreviewModelFactoryForTargetSocket(targetSocketName);

        string inputSocketName = p.sourceSocketName;

        if (p.outputMeshFactory == null)
        {
            NPVoxIMeshFactory meshFactory = GetPreviewFactoryForTargetSocket(targetSocketName);

            if (meshFactory == null)
            {
                return(null);
            }

            NPVoxModelSocketCombiner combiner = NPVoxModelCombiner.CreateInstance <NPVoxModelSocketCombiner>();
            combiner.Input                 = modelFactory;
            combiner.InputSocketName       = inputSocketName;
            combiner.TargetSocketName      = targetSocketName;
            combiner.ResolveConflictMethod = NPVoxModelTransformationUtil.ResolveConflictMethodType.FILL_GAPS;
            combiner.Target                = (UnityEngine.Object)SelectedFrame.PreOutput.Input;
            combiner.StorageMode           = NPipeStorageMode.MEMORY;

            NPVoxMeshOutput previewFactory = (NPVoxMeshOutput)meshFactory.Clone();
            previewFactory.StorageMode = NPipeStorageMode.MEMORY;
            previewFactory.Input       = combiner;

            p.outputMeshFactory = previewFactory;
        }
        else
        {
            NPVoxModelSocketCombiner combiner = ((NPVoxModelSocketCombiner)((NPVoxMeshOutput)p.outputMeshFactory).Input);
            // check if something changed in the meanwhipe
            if (combiner.Target != TotalModelFactory as UnityEngine.Object || combiner.InputSocketName != inputSocketName)
            {
                p.outputMeshFactory.Invalidate();
                combiner.Target          = (UnityEngine.Object)TotalModelFactory;
                combiner.InputSocketName = inputSocketName;
                combiner.Invalidate();
            }
        }

        return(p.outputMeshFactory);
    }
Пример #8
0
    public NPVoxSocketAttachment GetPreviewAttachmentForTargetSocket(string targetSocketName, bool createIfNotExists = false)
    {
        if (previewAttachments == null)
        {
            previewAttachments = new NPVoxSocketAttachment[] {}
        }
        ;
        foreach (NPVoxSocketAttachment previewSocket in previewAttachments)
        {
            if (previewSocket.targetSocketName == targetSocketName)
            {
                return(previewSocket);
            }
        }

        if (createIfNotExists)
        {
            NPVoxSocketAttachment p = new NPVoxSocketAttachment();
            p.targetSocketName = targetSocketName;
            UnityEditor.ArrayUtility.Add(ref previewAttachments, p);
            return(p);
        }
        return(null);
    }
    public bool GetPreviewSocketEnabled(string targetSocketName)
    {
        NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName, false);

        return(p == null || p.visible);
    }