Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TySim · Jan 13, 2016 at 02:34 AM · meshexport

Need Help combining cubes and exporting

I am at wits end....

The project is to read a data file and place cubes. It then should combine all the cubes into one big mesh and export it to an .obj file.

I can read the file. I can place the cubes. However, combining them and exporting them does not work. I went through just about every post on here related to these two issues I could find. I copy and pasted the code, tried playing with it tried fooling it.... Still can not get the last two pieces of the puzzle.

Here is the code....

 using UnityEngine;
 using System.Collections;
 using System.Text;
 using System.IO;
 using System.Collections.Generic;
 
 
 [RequireComponent(typeof(MeshFilter))]
 [RequireComponent(typeof(MeshRenderer))]
 
 public class PlaceCubes : MonoBehaviour
 {
     void Start()
     {
         Debug.Log("I Am Alive");
        //var FinalMesh = new Mesh();
         int i = 0;
         var fileName = "c:\\assets\\NewAsteroid001.raw";
         var sr = new StreamReader(fileName);
         var fileContents = sr.ReadToEnd();
         sr.Close();
         var lines = fileContents.Split("\n"[0]);
         GameObject[] cube = new GameObject[lines.Length];
         Debug.Log(lines.Length + " Total lines Read");
         while (i < (lines.Length-1))
             {
             var Elements = lines[i].Split(',');
             if (Elements.Length > 0) {
                 var XCoord = float.Parse(Elements[0]);
                 var YCoord = float.Parse(Elements[1]);
                 var ZCoord = float.Parse(Elements[2]);
                 var XLen = float.Parse(Elements[3]);
                 var YLen = float.Parse(Elements[4]);
                 var ZLen = float.Parse(Elements[5]);
                 cube[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
                 cube[i].transform.position = new Vector3(XCoord, YCoord, ZCoord);
                 cube[i].transform.localScale = new Vector3(XLen, YLen, ZLen);
                 i++;
             }
         }
         MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
         CombineInstance[] combine = new CombineInstance[meshFilters.Length];
         i = 0;
         Debug.Log(meshFilters.Length + " Mesh Filters detected");
         while (i < meshFilters.Length)
         {
             combine[i].mesh = meshFilters[i].sharedMesh;
             combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
             i++;
         }
         transform.GetComponent<MeshFilter>().mesh = new Mesh();
         transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
         ObjExporter.MeshToFile(GetComponent<MeshFilter>(), "c:\\assets\\NewAsteroid001.obj");
     }
 }
 

Debug output seems right until the combine part where it tells me there is only one meshfilter despite there being 15039 cubes.

As far as the export goes.... It exports precisely one cube....

Any help would be appreciated. Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

39 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigged model exporting from Blender to Unity 0 Answers

How do I deserialize a CompressedMesh from a Text-Based scene file? 0 Answers

Plane mesh merging and optimizing? 0 Answers

Problem with character meshes in Unity (exported from blender) 2 Answers

Get an Inflated Mesh Collider (vertices and faces) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges