ImportFile() public method

public ImportFile ( string filePath ) : Mesh
filePath string
return Mesh
Ejemplo n.º 1
0
    void loadmesh()
    {
        ObjImporter import = new ObjImporter();

        leftmesh  = import.ImportFile(Application.streamingAssetsPath + "/upper.obj");
        rightmesh = import.ImportFile(Application.streamingAssetsPath + "/bottom.obj");
    }
Ejemplo n.º 2
0
    void Load_RobotVis(Robot robot)
    {
        foreach (Module mod in robot.modules)
        {
            /* Mesh l = new Mesh() { vertices = mod.frames[0].meshVertices, uv = mod.frames[0].meshUvs, triangles = mod.frames[0].meshTriangles };
             * Mesh r = new Mesh() { vertices = mod.frames[1].meshVertices, uv = mod.frames[1].meshUvs, triangles = mod.frames[1].meshTriangles };*/
            ObjImporter import = new ObjImporter();
            Mesh        l      = import.ImportFile(dir + upperFrame_directory);//Should make variable: String upperDirectory = ...
            Mesh        r      = import.ImportFile(dir + bottomFrame_directory);

            frameVis.Add(new Frame_Vis(mod.frames[0].guid, l, AgxHelper(mod.frames[0].position), mod.frames[0].scale));
            frameVis.Add(new Frame_Vis(mod.frames[1].guid, r, AgxHelper(mod.frames[1].position), mod.frames[1].scale));
        }
    }
Ejemplo n.º 3
0
    void Start()
    {
        Debug.Log("LoadModel");



        GameObject CactusPart = new GameObject();

        CactusPart.AddComponent <Rigidbody>();
        CactusPart.GetComponent <Rigidbody>().isKinematic = false;
        CactusPart.GetComponent <Rigidbody>().useGravity  = true;
        CactusPart.transform.position = new Vector3(0, 0, 0);


        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile("C:/dev/CGAL-4.10/build/examples/Surface_mesh_segmentation/data/1_part_1.obj");

        MeshRenderer renderer = CactusPart.AddComponent <MeshRenderer>();
        MeshFilter   filter   = CactusPart.AddComponent <MeshFilter>();

        filter.mesh = holderMesh;

        CactusPart.AddComponent <MeshCollider>().sharedMesh = null;
        // CactusPart.GetComponent<MeshCollider>().sharedMesh = null;
        CactusPart.GetComponent <MeshCollider>().sharedMesh = holderMesh;
        CactusPart.GetComponent <MeshCollider>().convex     = true;
        //....
        //....
        //....

        Debug.Log("LoadModel Part2");
        CactusPart = new GameObject();
        CactusPart.AddComponent <Rigidbody>();
        CactusPart.GetComponent <Rigidbody>().isKinematic = false;
        CactusPart.GetComponent <Rigidbody>().useGravity  = true;
        CactusPart.transform.position = new Vector3(0, 0, 0);
        holderMesh  = newMesh.ImportFile("C:/dev/CGAL-4.10/build/examples/Surface_mesh_segmentation/data/2_part_2.obj");
        renderer    = CactusPart.AddComponent <MeshRenderer>();
        filter      = CactusPart.AddComponent <MeshFilter>();
        filter.mesh = holderMesh;

        CactusPart.AddComponent <MeshCollider>().sharedMesh = null;
        CactusPart.GetComponent <MeshCollider>().sharedMesh = holderMesh;
        CactusPart.GetComponent <MeshCollider>().convex     = true;
        //GetComponent<MeshCollider>().sharedMesh = null;
        // GetComponent<MeshCollider>().sharedMesh = holderMesh;
    }
Ejemplo n.º 4
0
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            print("space key was pressed");
            //GameObject instance = Instantiate(Resources.Load("model", typeof(GameObject))) as GameObject;
            ObjImporter importer  = new ObjImporter();
            Mesh        meshHello = importer.ImportFile("G:\\Dropbox\\Blender\\baseball.obj");
            //to get this mesh in the scene, we need an object
            GameObject myMesh = new GameObject("MyMesh");
            myMesh.transform.position = hookObject.transform.position;
            //add mesh fileter to this GameObject
            MeshFilter mf = myMesh.AddComponent <MeshFilter>();
            //set the mesh filter's mesh to our mesh
            mf.mesh = meshHello;
            //to see it, we have to add a renderer
            MeshRenderer mr = myMesh.AddComponent <MeshRenderer>();
            mr.material = material;


            //Rigidbody gameObjectsRigidBody = myMesh.AddComponent<Rigidbody>(); // Add the rigidbody.
            //gameObjectsRigidBody.mass = 5; // Set the GO's mass to 5 via the Rigidbody.

            //Collider gameObjectsCollider = myMesh.AddComponent<Collider>();
        }
    }
Ejemplo n.º 5
0
    public void Import(string mPath, string textPath)
    {
        modelPath = mPath;
        // Create mesh
        ObjImporter objImporter  = new ObjImporter();
        Mesh        importedMesh = objImporter.ImportFile(modelPath);

        // Create empty gameobject
        GameObject emptyGameObject = new GameObject();

        emptyGameObject.transform.position = new Vector3(0, 0, 0);

        // Add mesh to game object
        MeshFilter meshFilter = emptyGameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;

        meshFilter.sharedMesh = importedMesh;

        // Add mesh renderer
        MeshRenderer meshRenderer = emptyGameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;

        meshRenderer.material = mat;
        Texture2D tex = new Texture2D(2, 2);

        tex.LoadImage(File.ReadAllBytes(textPath));
        meshRenderer.material.SetTexture("_MainTex", tex);
        // Tell the boys
        if (ObjectImported != null)
        {
            ObjectImported(emptyGameObject);
        }
    }
Ejemplo n.º 6
0
    //! Adds blocks from mods to the game.
    public void AddModMeshes(Dictionary <string, Mesh> dictionary)
    {
        string modPath = Path.Combine(Application.persistentDataPath, "Mods");

        Directory.CreateDirectory(modPath);
        string[] modDirs = Directory.GetDirectories(modPath);
        foreach (string path in modDirs)
        {
            string meshPath = path + "/Models/";
            Directory.CreateDirectory(meshPath);
            DirectoryInfo d = new DirectoryInfo(meshPath);
            foreach (FileInfo file in d.GetFiles("*.obj"))
            {
                string filePath = meshPath + file.Name;
                string meshName = file.Name.Remove(file.Name.Length - 4);
                if (!dictionary.ContainsKey(meshName))
                {
                    ObjImporter importer = new ObjImporter();
                    Mesh        newMesh  = importer.ImportFile(filePath);
                    dictionary.Add(meshName, newMesh);
                    string   modName            = new DirectoryInfo(path).Name;
                    string[] commandLineOptions = Environment.GetCommandLineArgs();
                    if (commandLineOptions.Contains("-devel"))
                    {
                        Debug.Log("Mod " + "[" + modName + "]" + " created a new mesh: [" + meshName + "]");
                    }
                }
            }
        }
        playerController.gameManager.InitModBlocks();
    }
Ejemplo n.º 7
0
    // Start is called before the first frame update
    void Start()
    {
        ObjImporter newMesh    = new ObjImporter();
        Mesh        holderMesh = newMesh.ImportFile("/home/sourabh/Documents/TU-Berlin/Thesis/Sytheticdata/ml-imagesynthesis/Assets/CADPictures/PandaMale.obj");

        MeshSaver.SaveMesh(holderMesh, "PandaMale");
    }
Ejemplo n.º 8
0
    // ############################################################################



    // ############################################################################
    // load the collision object "collision_object.obj" from streamingassets folder
    // ############################################################################
    private void Change_Skybox_Collision_Object(stru_skymap_paths skymap_paths)
    {
        // collision object for reseting model (collision with blades)
        Mesh holder_mesh = new Mesh();

        //ObjImporter newMesh = new ObjImporter();
        holder_mesh = ObjImporter.ImportFile(skymap_paths.fullpath_collision_object);

        MeshFilter collision_object_mesh_filter = GameObject.Find("Collision Object").transform.Find("collisionobject").gameObject.GetComponent <MeshFilter>();

        collision_object_mesh_filter.mesh = holder_mesh;

        MeshCollider collision_object_mesh_collider = GameObject.Find("Collision Object").transform.Find("collisionobject").gameObject.GetComponent <MeshCollider>();

        collision_object_mesh_collider.sharedMesh = holder_mesh;

        collision_object_mesh_filter.mesh.RecalculateNormals();
        collision_object_mesh_collider.sharedMesh.RecalculateNormals();

        // collision object for landig
        Mesh holder_mesh2 = new Mesh();

        holder_mesh2 = ObjImporter.ImportFile(skymap_paths.fullpath_collision_landing_object);
        // this is calulated in the helicopter_ODE-thread at high update frequency
        helicopter_ODE.Set_AABB_Skybox_Collision_Landing_Mesh(holder_mesh2);
    }
Ejemplo n.º 9
0
    void Awake()
    {
        // save the parent GO-s pos+rot
        Vector3    position = transform.position;
        Quaternion rotation = transform.rotation;

        // move to the origin for combining
        transform.position = Vector3.zero;
        transform.rotation = Quaternion.identity;

        MeshFilter[]           filters = GetComponentsInChildren <MeshFilter>();
        List <CombineInstance> combine = new List <CombineInstance>();

        for (int i = 0; i < filters.Length; i++)
        {
            // skip the empty parent GO
            if (filters[i].sharedMesh == null)
            {
                continue;
            }

            // combine submeshes
            for (int j = 0; j < filters[i].sharedMesh.subMeshCount; j++)
            {
                CombineInstance ci = new CombineInstance();

                ci.mesh         = filters[i].sharedMesh;
                ci.subMeshIndex = j;
                ci.transform    = filters[i].transform.localToWorldMatrix;

                combine.Add(ci);
            }

            // disable child mesh GO-s
            filters[i].gameObject.SetActive(false);
        }

        MeshFilter filter = GetComponent <MeshFilter>();

        filter.mesh = new Mesh();
        filter.mesh.CombineMeshes(combine.ToArray(), true, true);

        // restore the parent GO-s pos+rot
        transform.position = position;
        transform.rotation = rotation;

        ObjExporter.MeshToFile(filter, Application.persistentDataPath + "testobj.obj");



        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile(Application.persistentDataPath + "testobj.obj");

        MeshRenderer renderer = g1.GetComponent <MeshRenderer>();
        MeshFilter   filter1  = g1.GetComponent <MeshFilter>();

        filter1.mesh = holderMesh;
    }
Ejemplo n.º 10
0
        private ObjImporter.meshStruct LoadObjMesh(
            string fileName,
            double scale)
        {
            ObjImporter importer = new ObjImporter();

            ObjImporter.meshStruct mesh = importer.ImportFile(fileName);

            Vector3d[] vertexStartPoint = new Vector3d[mesh.vertices.Length];

            for (int i = 0; i < mesh.vertices.Length; i++)
            {
                vertexStartPoint[i] = mesh.vertices[i];
            }

            OpenGLUtilities.UnitizeObject(ref vertexStartPoint);
            OpenGLUtilities.ScaleObject(ref vertexStartPoint, scale);

            for (int i = 0; i < mesh.vertices.Length; i++)
            {
                mesh.vertices[i] = vertexStartPoint[i];
            }

            return(mesh);
        }
Ejemplo n.º 11
0
    void Start()
    {
        ObjImporter newMesh    = new ObjImporter();
        Mesh        holderMesh = newMesh.ImportFile(fileLoc);

        // Mesh holderMesh  = FastObjImporter.Instance.ImportFile(fileLoc);

        MeshSaver.SaveMesh(holderMesh, meshname);
    }
Ejemplo n.º 12
0
    Robot Load_Robot(Robot robot)
    {
        //Initialize modules with joints and frames (+agx objects) : SHOULD BE IN SCENE DESIGNER, send triangles, verts and uvs!
        ObjImporter import = new ObjImporter();

        Mesh leftMesh = import.ImportFile(dir + upperFrame_directory); Bounds leftBound = leftMesh.bounds;
        Mesh rightMesh = import.ImportFile(dir + bottomFrame_directory); Bounds rightBound = rightMesh.bounds;

        //SET MESH
        foreach (Module mod in robot.modules)
        {
            mod.frames[0].SetMesh(AgxHelper(leftMesh.vertices), AgxHelper(leftMesh.uv), leftMesh.triangles); mod.frames[1].SetMesh(AgxHelper(rightMesh.vertices), AgxHelper(rightMesh.uv), rightMesh.triangles);
        }
        //Creates AgX objects and joint connections:
        robot.Initialize();//Initialize frames (creates AgX obj), initializes modules (connecting frames with joint), Locks modules together

        return(robot);
    }
Ejemplo n.º 13
0
 public void ImportModel()
 {
     if (Directory.Exists(Application.dataPath) && File.Exists(Application.dataPath + "/Model.obj"))
     {
         Mesh        mesh        = new Mesh();
         ObjImporter objImporter = new ObjImporter();
         mesh = objImporter.ImportFile(Application.dataPath + "/Model.obj");
         GameObject.FindGameObjectWithTag("BasicMeshes").GetComponent <CreateMesh>().CreateImportedObject(mesh);
     }
 }
Ejemplo n.º 14
0
    // Use this for initialization
    void Start()
    {
        target.text = "Foge";
        //LoadFBX ("http://163.143.133.204/test.fbx");
        var mymeshfilter = GetComponent(typeof(MeshFilter)) as MeshFilter;

        ObjImporter objImporter = new ObjImporter();

        mymeshfilter.mesh = objImporter.ImportFile("");
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Loads a mesh from a .obj file at runtime.
        /// </summary>
        /// <param name="meshPath">Mesh path relative to "plugins" BepInEx folder</param>
        /// <returns>Texture2D loaded, or null if invalid path</returns>
        public static Mesh LoadMesh(string meshPath)
        {
            string path = Path.Combine(Paths.PluginPath, meshPath);

            if (!File.Exists(path))
            {
                return(null);
            }

            return(ObjImporter.ImportFile(path));
        }
Ejemplo n.º 16
0
    public void LoadObj(string fileLocation)
    {
        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile(fileLocation);

        MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>();
        MeshFilter   filter   = gameObject.AddComponent <MeshFilter>();

        filter.mesh = holderMesh;
    }
Ejemplo n.º 17
0
    void Start()
    {
        InitMesh();
        ObjImporter objImporter = new ObjImporter();

        m = objImporter.ImportFile(objPath);

        m.RecalculateBounds();
        m.RecalculateNormals();

//		m= GetComponent<ObjImporter>().ImportFile(objPath);
    }
Ejemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile("C:/Users/cvpa2/Desktop/ng/output.obj");

        MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>();
        MeshFilter   filter   = gameObject.AddComponent <MeshFilter>();

        filter.mesh = holderMesh;
    }
Ejemplo n.º 19
0
        void Start()
        {
            Debugger = GameObject.Find("DIMOWALevelLoaderHandler").GetComponent <ClientDebuggerSide>();

            WWWHelper wwwHelper = new WWWHelper();

            StartCoroutine(ImportAllFiles());
            ObjImporter objImporter = new ObjImporter();

            //        \OuterWilds_Alpha_1_2_Data\OuterWilds_Alpha_1_2_Data\Assets\PGMAssets
            hookMesh = objImporter.ImportFile(@"PGMAssets\grapleHookModel.obj");

            modCamera = gameObject.FindWithRequiredTag("MainCamera").camera.transform;
            player    = gameObject.FindWithRequiredTag("Player").transform;
            ship      = gameObject.FindWithRequiredTag("Ship").transform;

            try
            {
                wavPlayer = gameObject.FindWithRequiredTag("Player").GetComponent <AudioSource>();
            }
            catch (Exception e)
            {
                Debugger.SendLog($"Erro ao pegar o AudioSource do player: {e}");
            }
            if (wavPlayer == null)
            {
                wavPlayer = gameObject.FindWithRequiredTag("Player").AddComponent <AudioSource>();
            }
            Debug.Log($"O wav player é {wavPlayer != null}");


            IsGrappling = false;

            lr = player.gameObject.AddComponent <LineRenderer>();

            lineThicness = 0.08f;
            lr.SetWidth(lineThicness, lineThicness);

            lr.material = new Material(Shader.Find("Diffuse"));

            lineColor         = new Color(1f, 1f, 0.36f, 1f);
            lr.material.color = lineColor;
            lr.SetVertexCount(0);


            aparenciaDoTexto = new GUIStyle
            {
                fontSize = 72
            };

            aparenciaDoTexto.normal.textColor = Color.gray;
        }
Ejemplo n.º 20
0
    private void importModel()
    {
        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile(Filenames.objectFilename);

        //MeshRenderer renderer = gameObject.AddComponent<MeshRenderer>();
        MeshFilter filter = gameObject.AddComponent <MeshFilter>();

        filter.mesh = holderMesh;
        gameObject.AddComponent <MeshCollider>();
    }
Ejemplo n.º 21
0
    void Load_Vis()
    {
        //Frames:
        foreach (Module mod in robot.modules)
        {
            /* Mesh l = new Mesh() { vertices = mod.frames[0].meshVertices, uv = mod.frames[0].meshUvs, triangles = mod.frames[0].meshTriangles };
             * Mesh r = new Mesh() { vertices = mod.frames[1].meshVertices, uv = mod.frames[1].meshUvs, triangles = mod.frames[1].meshTriangles };*/
            ObjImporter import = new ObjImporter();
            Mesh        l      = import.ImportFile(dir + upperFrame_directory);//Should make variable: String upperDirectory = ...
            Mesh        r      = import.ImportFile(dir + bottomFrame_directory);

            frameVis.Add(new Frame_Vis(mod.frames[0].guid, l, Sim_CoreHelper(mod.frames[0].position), (float)mod.frames[0].scale));
            frameVis.Add(new Frame_Vis(mod.frames[1].guid, r, Sim_CoreHelper(mod.frames[1].position), (float)mod.frames[1].scale));
        }

        foreach (Sensory_Module mod in robot.sensorModules)
        {
            sensorVis.Add(new Sensor_Vis(mod.guid, Sim_CoreHelper(mod.position), Sim_CoreHelper(mod.size)));
        }

        //Scene:
        Scene_Vis scene_vis = new Scene_Vis(scene.guid, Sim_CoreHelper(scene.vertices), scene.triangles, Sim_CoreHelper(scene.uvs), Sim_CoreHelper(scene.position), Resources.Load("grass") as Texture);
    }
Ejemplo n.º 22
0
    void Load_Robot(Robot robot)
    {
        //Initialize modules with joints and frames (+agx objects) : SHOULD BE IN SCENE DESIGNER, send triangles, verts and uvs!
        ObjImporter import = new ObjImporter();

        Mesh leftMesh = import.ImportFile(dir + upperFrame_directory); Bounds leftBound = leftMesh.bounds;
        Mesh rightMesh = import.ImportFile(dir + bottomFrame_directory); Bounds rightBound = rightMesh.bounds;

        //new z pos is start.z - meshLength*i.
        foreach (Module mod in robot.modules)
        {
            mod.frames[0].setMesh(Sim_CoreHelper(leftMesh.vertices), Sim_CoreHelper(leftMesh.uv), leftMesh.triangles); mod.frames[1].setMesh(Sim_CoreHelper(leftMesh.vertices), Sim_CoreHelper(rightMesh.uv), rightMesh.triangles);

            /*foreach (Frame frame in mod.frames)
             * {
             *  //frame.Initialize();
             * }
             */
            //mod.Initialize(mod.frames[0], mod.frames[1]);//calls Create_Hinge
        }
        robot.Initialize();//Initialize frames (creates AgX obj), initializes modules (connecting frames with joint), Locks modules together

        this.robot = robot;
    }
Ejemplo n.º 23
0
        private void LoadOBJ(GameObject obj, string filePath)
        {
            Mesh        holderMesh = new Mesh();
            ObjImporter newMesh    = new ObjImporter();

            holderMesh = newMesh.ImportFile(filePath);

            MeshFilter filter = obj.AddComponent <MeshFilter>();

            filter.mesh = holderMesh;

            MeshRenderer renderer = obj.AddComponent <MeshRenderer>();

            //Material defaultMat = new Material(Shader.Find("Standard"));
            //renderer.material = defaultMat;
        }
Ejemplo n.º 24
0
    //Download a ModelFile from the CouchDB specified by id and name
    private IEnumerator DownloadFile(Project project, float scale, Vector3 offset)
    {
        //string text = GetRequest("/" + id + "/topic_/file");
        string id;

        if (project.ids.TryGetValue(serviceName, out id))
        {
            Debug.Log("/" + id + "/topic_/file/");
            UnityWebRequest webop = CreateGetRequest("/" + id + "/topic_/file", true);

            yield return(webop.SendWebRequest());

            if (webop.isNetworkError && webop.responseCode != 200L)
            {
                Debug.Log(webop.error);
            }
            else
            {
                string text = webop.downloadHandler.text;
                Debug.Log(text.Length);
                ObjImporter importer = new ObjImporter();
                GameObject  obj      = GameObject.Find("Holograms/" + name).gameObject;
                obj.transform.localScale = new Vector3(scale, scale, scale);
                obj.name  = name;
                obj.layer = 0;
                obj.AddComponent <MeshRenderer>();
                obj.AddComponent <MeshFilter>();
                obj.AddComponent <MeshCollider>();
                obj.GetComponent <MeshFilter>().mesh       = importer.ImportFile(text);
                obj.GetComponent <MeshFilter>().sharedMesh = obj.GetComponent <MeshFilter>().mesh;
                obj.GetComponent <MeshFilter>().mesh.RecalculateNormals();
                obj.GetComponent <MeshFilter>().mesh.RecalculateTangents();
                obj.GetComponent <MeshFilter>().mesh.RecalculateBounds();
                obj.transform.localPosition = offset + new Vector3(0.0f, scale * obj.GetComponent <MeshFilter>().mesh.bounds.extents.y, 0.0f);

                obj.GetComponent <MeshCollider>().sharedMesh = null;
                obj.GetComponent <MeshCollider>().sharedMesh = obj.GetComponent <MeshFilter>().mesh;
                obj.GetComponent <MeshCollider>().convex     = false;
                obj.GetComponent <MeshCollider>().enabled    = true;
                obj.GetComponent <Renderer>().material       = Resources.Load <Material>("Materials/defaultMat");
                obj.GetComponent <Renderer>().enabled        = true;
                obj.SetActive(true);
            }
        }
    }
Ejemplo n.º 25
0
    public static GameObject ReadObjFromDisk(string filePath, string alternativeName)
    {
        var        m = ObjImporter.ImportFile(filePath);
        GameObject g = new GameObject(System.IO.Path.GetFileNameWithoutExtension(filePath));

        if (!string.IsNullOrEmpty(alternativeName))
        {
            g.name = alternativeName;
        }
        var mf = g.AddComponent <MeshFilter>();

        mf.sharedMesh = m;
        var coll = g.AddComponent <MeshCollider>();

        coll.sharedMesh = m;
        g.AddComponent <MeshRenderer>();
        return(g);
    }
Ejemplo n.º 26
0
//  This script imports a new model in .obj format
//  enter the path for the object in the holdermesh variable

    void Start()
    {
        // Debug.Log(Directory.Exists(modelPath));

        Mesh        holderMesh = new Mesh();
        ObjImporter newMesh    = new ObjImporter();

        holderMesh = newMesh.ImportFile(modelPath);

        //add mesh collider to the new imported object and bake it according to its mesh

        MeshCollider colliderMesh = gameObject.AddComponent <MeshCollider>();

        colliderMesh.convex     = true;
        colliderMesh.sharedMesh = holderMesh;

        // capsule collider
        // CapsuleCollider colliderMesh = gameObject.AddComponent<CapsuleCollider>();

        //adding a wireframe renderer

        MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>();

        filter = gameObject.AddComponent <MeshFilter>();
        Material wireframe = new Material(flatWireframe);

        filter.mesh = holderMesh;
        Renderer rend = GetComponent <Renderer>();

        if (rend != null)
        {
            rend.material = wireframe;
        }

        //aligning the camera to fit the screen

        // Vector3 xyz = filter.GetComponent<MeshFilter>().mesh.bounds.size;
        // float distance = Mathf.Max(xyz.x, xyz.y, xyz.z);
        // distance /= (2.0f * Mathf.Tan(0.5f * mainCam.fieldOfView * Mathf.Deg2Rad));
        // // Move camera in -z-direction; change '2.0f' to your needs
        // mainCam.transform.position = new Vector3(mainCam.transform.position.x, mainCam.transform.position.y, -distance * 2.0f);
    }
Ejemplo n.º 27
0
    public void LoadObject(string path)
    {
        Debug.Log("LoadObject: " + path.Length);

        //Destroy(Obj);
        Obj = new GameObject();

        ObjImporter objImporter = new ObjImporter();

        Mesh mesh = new Mesh();

        mesh = objImporter.ImportFile(path);

        MeshRenderer renderer = Obj.AddComponent <MeshRenderer>();

        renderer.material = new Material(shader);

        MeshFilter filter = Obj.AddComponent <MeshFilter>();

        filter.mesh = mesh;
    }
Ejemplo n.º 28
0
            /// <summary>
            /// Parse the Value from a string
            /// </summary>
            public void SetFromString(String s)
            {
                // Check if we are attempting to load a builtin mesh
                if (s.StartsWith("BUILTIN/"))
                {
                    String meshName = Regex.Replace(s, "BUILTIN/", "");
                    Value = Resources.FindObjectsOfTypeAll <Mesh>().First(mesh => mesh.name == meshName);
                    return;
                }

                String path = KSPUtil.ApplicationRootPath + "GameData/" + s;

                if (File.Exists(path))
                {
                    Value      = ObjImporter.ImportFile(path);
                    Value.name = Path.GetFileNameWithoutExtension(path);
                    return;
                }

                // Mesh was not found
                Value = null;
            }
Ejemplo n.º 29
0
        public override void loadAsset(bool downloadOverride = false)
        {
            base.loadAsset(downloadOverride);
            string Path = Application.persistentDataPath + data.localPath;

            if (checkLocalPath(Path) && !downloadOverride)
            {
                //StartCoroutine(LoadModel(Path))
                ObjImporter importer = new ObjImporter();
                Mesh        mesh     = importer.ImportFile(Path);
                setMesh(mesh);
            }
            else if (data.dataUrl != null && data.dataUrl != "" && tries < 2)
            {
                StartCoroutine(DownloadModel(data.dataUrl));
            }
            else
            {
                setMesh(defaultMesh);
                Debug.Log("no data found for " + type + " with localIdentifier " + localIdentifier);
            }
        }
Ejemplo n.º 30
0
    static Mesh LoadMesh(string value)
    {
        if (string.IsNullOrEmpty(value))
        {
            return(null);
        }
        Mesh mesh;

        if (value.Substring(0, 10) == "(#Interal)")
        {
            switch (value.Substring(10, value.Length - 10))
            {
            case "Cube":
                mesh = GameData.GameMeshes[0];
                break;

            case "Sphere":
                mesh = GameData.GameMeshes[1];
                break;

            case "Capsule":
                mesh = GameData.GameMeshes[2];
                break;

            case "Quad":
                mesh = GameData.GameMeshes[3];
                break;

            default:
                mesh = GameData.GameMeshes[0];      //Set cube as default mesh
                break;
            }
        }
        else
        {
            mesh = objImporter.ImportFile(System.IO.Directory.GetCurrentDirectory() + value);
        }
        return(mesh);
    }