Esempio n. 1
0
    virtual public UnityEngine.Object Clone()
    {
        NPVoxMeshOutput copy = (NPVoxMeshOutput)base.Clone();

        copy.NormalVarianceSeed = Random.Range(0, int.MaxValue);
        return(copy);
    }
    public NPVoxNormalProcessorPreviewContext GeneratePreviewContext(NPVoxMeshOutput _meshOutput)
    {
        ClearInvalidPreviewContexts();
        NPVoxNormalProcessorPreviewContext previewContext = ScriptableObject.CreateInstance <NPVoxNormalProcessorPreviewContext>();

        previewContext.Set(_meshOutput, this);
        m_validPreviewContexts.Add(previewContext);
        return(previewContext);
    }
Esempio n. 3
0
    public override UnityEngine.Object Clone()
    {
        NPVoxMeshOutput copy = (NPVoxMeshOutput)base.Clone();

        copy.NormalVarianceSeed = Random.Range(0, int.MaxValue);

        copy.NormalProcessors = NormalProcessors.Clone() as NPVoxNormalProcessorList;
        copy.NormalProcessors.RequiresMigration = false;

        return(copy);
    }
    override public void OnAssetCreated()
    {
        base.OnAssetCreated();
        NPVoxMeshOutput output = NPipelineUtils.GetByType <NPVoxMeshOutput>(NPVoxUtils.GetTemplatePipeline())[0];

        MeshFactory              = (NPVoxMeshOutput)output.Clone();
        MeshFactory.StorageMode  = NPipeStorageMode.RESOURCE_CACHE;
        MeshFactory.Input        = null;
        MeshFactory.InstanceName = "_TEMPLATE_";
        NPipelineUtils.CreateAttachedPipe(UnityEditor.AssetDatabase.GetAssetPath(this), MeshFactory);
        UnityEditor.AssetDatabase.SaveAssets();
    }
    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);
    }
    public void Set(NPVoxMeshOutput _meshOutput, NPVoxNormalProcessor _processor)
    {
        MeshOutput      = _meshOutput;
        ViewedProcessor = _processor;
        PreviewObject   = MeshOutput.Instatiate();

        VoxToUnity = new NPVoxToUnity(MeshOutput.GetVoxModel(), MeshOutput.VoxelSize);

        MeshFilter mf = PreviewObject.GetComponent <MeshFilter>();

        PreviewMesh   = Mesh.Instantiate <Mesh>(mf.sharedMesh);
        mf.sharedMesh = PreviewMesh;

        PreviewObject.hideFlags = HideFlags.HideAndDontSave;
        PreviewObject.SetActive(false);
        IsValid = true;
    }
Esempio n. 7
0
    public NPVoxFrame(NPVoxAnimation animation)
    {
        this.animation = animation;

        output           = (NPVoxMeshOutput)animation.MeshFactory.Clone();
        output.hideFlags = HideFlags.HideInHierarchy;

//        Debug.Log("invalidating");
#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(output, AssetDatabase.GetAssetPath(animation));
        preOutput = (NPVoxModelForwarder)NPVoxModelForwarder.CreateInstance <NPVoxModelForwarder>();
        NPipelineUtils.CreateAttachedPipe(AssetDatabase.GetAssetPath(animation), preOutput);
        preOutput.Input = null;
#endif
        output.Input = preOutput;
        output.Invalidate();
        preOutput.Invalidate();
    }
    void OnDrawGizmos()
    {
//        if (Selection.activeGameObject != this.gameObject)
//        {
//            return;
//        }

        NPVoxMeshOutput MeshOutput = MeshFactory as NPVoxMeshOutput;

        if (MeshOutput)
        {
            NPVoxToUnity npVoxToUnity = MeshOutput.GetNPVoxToUnity();
            NPVoxModel   model        = MeshOutput.GetVoxModel();
            if (model)
            {
                foreach (NPVoxSocket socket in model.Sockets)
                {
                    Vector3    anchorPos     = npVoxToUnity.ToUnityPosition(socket.Anchor);
                    Quaternion rotation      = Quaternion.Euler(socket.EulerAngles);
                    Vector3    anchorRight   = npVoxToUnity.ToUnityDirection(rotation * Vector3.right);
                    Vector3    anchorUp      = npVoxToUnity.ToUnityDirection(rotation * Vector3.up);
                    Vector3    anchorForward = npVoxToUnity.ToUnityDirection(rotation * Vector3.forward);

                    Gizmos.color = new Color(0.5f, 1.0f, 0.1f, 0.75f);
                    Gizmos.DrawCube(transform.position + anchorPos, Vector3.one * 0.4f);

                    Gizmos.color = Color.red;
                    Gizmos.DrawLine(transform.position + anchorPos, transform.position + anchorPos + anchorRight * 10.0f);
                    Gizmos.color = Color.green;
                    Gizmos.DrawLine(transform.position + anchorPos, transform.position + anchorPos + anchorUp * 10.0f);
                    Gizmos.color = Color.blue;
                    Gizmos.DrawLine(transform.position + anchorPos, transform.position + anchorPos + anchorForward * 10.0f);
                }
            }
        }
    }
Esempio n. 9
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        NPVoxMeshOutput          target        = property.serializedObject.targetObject as NPVoxMeshOutput;
        NPVoxNormalProcessorList processorList = target.NormalProcessors;

        EditorGUI.BeginProperty(position, label, property);
        // Customize gui style
        Color previousBGColor = GUI.backgroundColor;
        Color previousFGColor = GUI.contentColor;

        GUI.backgroundColor = s_colorBackgroundGUIPrimary;
        GUI.backgroundColor = s_colorBackgroundGUIPrimary;
        // GUI.contentColor = s_colorForegroundGUI; // Doesn't seem to work

        // Header + Expand / Collapse Button
        GUILayout.BeginHorizontal();
        GUILayout.Label("Normal Processors (" + processorList.GetProcessors().Count + ")", GUILayout.Width(s_widthHeaderLabel));

        if (!m_expanded)
        {
            if (GUILayout.Button("Expand", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = true;
            }
        }
        else
        {
            if (GUILayout.Button("Collapse", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = false;
            }
        }

        GUILayout.EndHorizontal();

        if (!m_expanded)
        {
            GUILayout.Space(12.0f);
        }

        // List management
        if (m_expanded)
        {
            Dictionary <string, System.Type> processorClasses = new Dictionary <string, System.Type>();
            processorClasses.Add("<None>", null);
            List <System.Type> allTypes = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPVoxAttributeNormalProcessorListItem)));
            allTypes = allTypes.OrderBy(x => (( NPVoxAttributeNormalProcessorListItem )x.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0]).ListPriority).ToList();
            foreach (System.Type factoryType in allTypes)
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )factoryType.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                if (attr.ClassType.BaseType != typeof(NPVoxNormalProcessor))
                {
                    continue;
                }

                processorClasses.Add(attr.EditorName, factoryType);
            }

            string[] processorKeys = processorClasses.Keys.ToArray();

            GUILayout.BeginHorizontal();
            GUILayout.Space(s_widthTab);
            m_indexPopupAddProcessor = EditorGUILayout.Popup(m_indexPopupAddProcessor, processorKeys);
            bool optionAdded = GUILayout.Button("Add");
            GUILayout.EndHorizontal();

            if (optionAdded)
            {
                System.Type processorClass = processorClasses[processorKeys[m_indexPopupAddProcessor]];
                if (processorClass != null)
                {
                    if (UnityEditor.AssetDatabase.GetAssetPath(processorList).Length == 0)
                    {
                        target.IncludeSubAssets(UnityEditor.AssetDatabase.GetAssetPath(target));
                    }
                    processorList.AddProcessor(processorClass)
                    .AddToAsset(UnityEditor.AssetDatabase.GetAssetPath(target));
                }
            }

            NPVoxNormalProcessor itemToMoveBack    = null;
            NPVoxNormalProcessor itemToMoveForward = null;

            foreach (NPVoxNormalProcessor processor in processorList.GetProcessors())
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )processor.GetType().GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                GUILayout.Space(s_verticalSpacePerItem);

                GUILayout.BeginHorizontal();
                GUILayout.Space(s_widthTab);
                GUILayout.Label(attr.EditorName, GUILayout.MinWidth(s_widthMinItemName));

                GUILayout.Space(20.0f);

                GUI.backgroundColor = s_colorBackgroundGUISecondary;

                if (GUILayout.Button("View / Edit"))
                {
                    NPVoxNormalProcessorPreview preview = NPVoxNormalProcessorPreview.ShowWindow(processor.GetType());
                    preview.SetContext(processor.GeneratePreviewContext(target));
                }

                GUILayout.Space(20.0f);

                if (GUILayout.Button("^", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveBack = processor;
                }

                if (GUILayout.Button("v", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveForward = processor;
                }

                if (GUILayout.Button("X", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    processorList.DestroyProcessor(processor);
                    break;
                }

                GUI.backgroundColor = s_colorBackgroundGUIPrimary;

                GUILayout.EndHorizontal();

                processor.OnGUI();
                GUILayout.Space(10.0f);
            }

            if (itemToMoveBack)
            {
                processorList.MoveProcessorBack(itemToMoveBack);
                itemToMoveBack = null;
            }

            if (itemToMoveForward)
            {
                processorList.MoveProcessorForward(itemToMoveForward);
                itemToMoveForward = null;
            }

            GUILayout.Space(s_verticalSpaceEnd);
        }

        // Restore previous gui style
        GUI.backgroundColor = previousBGColor;
        GUI.contentColor    = previousFGColor;

        EditorGUI.EndProperty();
    }