Ejemplo n.º 1
0
    public void CreateGameObject(VTKNode node)
    {
        string gameObjectName = VTK.GetGameObjectName(node);

        Debug.Log("Create gameobject " + gameObjectName);

        if (node.filter.outputType == VTK.DataType.PolyData)
        {
            //Create gameobject
            VtkToUnity vtu = new VtkToUnity(node.filter.vtkFilter.GetOutputPort(),
                                            VTK.GetGameObjectName(node));
            vtu.go.transform.parent = gameObject.transform;
            vtu.ColorBy(Color.magenta);
            vtu.Update();

            gameObjects.Add(vtu.go.name, vtu);

            if (node.filter.outputType == VTK.DataType.PolyData)
            {
                //Add mesh for controller support
                GameObject   go = FindGameObject(gameObjectName);
                MeshCollider mc = go.AddComponent <MeshCollider>();
                mc.isTrigger = true;
                ControllerGameObject cg = go.AddComponent <ControllerGameObject>();
                cg.node = node;
                cg.Initialize();
            }
        }
    }
Ejemplo n.º 2
0
    public void PreloadNode(VTKNode node)
    {
        Debug.Log("Preload data for " + node.name);

        string objectName = VTK.GetGameObjectName(node);

        //Set filter
        if (node.isRoot)
        {
            if (dataType == VTK.DataType.PolyData)
            {
                polyDataReader = vtkXMLPolyDataReader.New();
                polyDataReader.SetFileName(filepath);
                polyDataReader.Update();

                node.filter.vtkFilter  = polyDataReader;
                node.filter.outputType = VTK.DataType.PolyData;
            }

            if (dataType == VTK.DataType.UnstructuredGrid)
            {
                unstructuredGridReader = vtkXMLUnstructuredGridReader.New();
                unstructuredGridReader.SetFileName(filepath);
                unstructuredGridReader.Update();

                node.filter.vtkFilter  = unstructuredGridReader;
                node.filter.outputType = VTK.DataType.UnstructuredGrid;
            }
        }
        else
        {
            node.filter.node = node;
            node.filter.UpdateInput();
            node.filter.SetPlaymodeParameters();
        }

        //Set properties
        node.properties.node = node;
        node.properties.SetPlaymodeParameters();
        node.properties.Read();

        //Set vtkToUnity
        VtkToUnity vtu;

        if (gameObjects.TryGetValue(objectName, out vtu))
        {
            gameObjects.Set(objectName, new VtkToUnity(node.filter.vtkFilter.GetOutputPort(),
                                                       FindGameObject(objectName)));

            node.UpdateProperties();             //Some filters need stuff from properties
        }

        //Set controller script
        ControllerGameObject cg = node.filter.gameObject.GetComponent <ControllerGameObject>();

        if (cg != null)
        {
            cg.node = node;
            cg.Initialize();
        }

        //Do it for the kids
        if (node.hasChildren)
        {
            foreach (VTKNode child in node.children)
            {
                //Set parent reference
                child.parent = node;

                PreloadNode(child);
            }
        }
    }