Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by frosted · Mar 15, 2014 at 10:38 PM · c#terrainraw

C#: Generate Raw File from byte[]?

I'm generating splat maps from code, and I'm at the point where I'm trying to import the generated images into unity.

Anyone done this, or know exactly what the format is?

Is it just a series of bytes in sets of 3 for rgb, in height/width ?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Eric5h5 · Mar 15, 2014 at 11:24 PM

Splat maps are RGBA, not RGB. The format is whatever you want, but to use SetAlphamaps it needs to be converted to a float[,,] array. See the ApplySplatmap script included with Fractscape, which exports splat maps as .tga.

Comment
Add comment · Show 5 · Share
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
avatar image frosted · Mar 16, 2014 at 02:03 PM 0
Share

Sorry if the question was too vague (and incorrect! I wasn't dealing with splatmaps at this point - am dealing with relief maps). Sorry for the confusion. What I'd like to do is be able to save each of the heightmaps as .raw then use the terrain inspector to import them. It just makes it a little easier if you're generating a ton of them to have it saved as an image.

What I'm currently doing is just saving a set of bytes and applying them with:

         byte[] bytes = File.ReadAllBytes( @"..." );
         Terrain t = FindObjectOfType< Terrain >();
         int size = ( int ) $$anonymous$$athf.Sqrt( bytes.Length );
         float[,] heights = new float[size,size];
         Debug.Log( bytes.Length  );
         for (int i = 0; i < bytes.Length; i++  ) {
             int x = i%size;
             int y = i/size;
             float p = ( bytes[ i ]) / 256f ;
             heights[ x, y ] = p;
         }

         t.terrainData.SetHeights(0, 0, heights );

It'd be nicer though to drop this code entirely and just use the built in inspector.

avatar image Eric5h5 · Mar 16, 2014 at 02:30 PM 0
Share

Oh, raw image files are just that, a series of bytes. Not rgb, just the grayscale data. So two bytes per pixel, either little-endian or big-endian. No formatting data.

avatar image frosted · Mar 16, 2014 at 02:38 PM 0
Share

Thanks for your help Eric!

Sorry if this is a really dumb question but, what exactly are the two bytes per pixel?

avatar image Eric5h5 · Mar 16, 2014 at 02:47 PM 0
Share

The heights range from 0 to 65535, so each pixel is a unsigned short (ushort), which is two bytes, the low byte and the high byte. Or vice versa.

avatar image frosted · Mar 16, 2014 at 02:48 PM 0
Share

you rock! Thanks.

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

22 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

Related Questions

Distribute terrain in zones 3 Answers

Raw File / Heightmap Switch at Runtime 1 Answer

Multiple Cars not working 1 Answer

Need Pointer: How to create 2D map in Unity? 1 Answer

[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ? 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