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 Smots · Jun 14, 2013 at 09:57 AM · colorsavefilevoxelserialize

Saving 3D color array to file

I've created myself a little voxel (cube) editor which basically creates a 3D array of colors:

 var Model:Color[,,];

One of these colors is handled by the code as a non-block (pitch-black = 0,0,0), so there's no case of null blocks or something of the like. The Model is a member variable of the script file/class, so my functions don't need it as a parameter (for now).

The size (at the moment) is always 16x16x16.

Now that I've got a basic editor I'd like to create a simple save/load function:

 function Save(File:string) ...
 
 function Load(File:string) ...

I've found examples of text and xml files, but I'd like to serialize/pack this variable. Is it possible to save/load this variable directly or is a conversion required? (example: converting Color[16,16,16] to Float[16,16,16,3]). I'd really like to see a code example of how this (or something similar) is achieved.

Thanks in advance.

Ps. Should it be helpful, I don't need the alpha channel, it's always 1.

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 Smots · Jun 18, 2013 at 09:12 AM

After tinkering for a couple of hours I found the solution.

For storing I loop through each voxel and convert each color channel to a byte value (0..255). I do this by multiplying by 255. So basically I convert to 24BPP (or BPV).

When loading I convert each byte back by dividing by 255.0

I can post the code here later if anyone is interested.

Comment
Add comment · Show 1 · 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 CarterG81 · May 08, 2014 at 11:59 PM 0
Share

"I can post the code here later if anyone is interested."

Why not just do it anyway? Why wait to see if "anyone is interested"?

There is no reason NOT to post it anyway, in CASE anyone is interested, rather than IF anyone is interested.

Doing it anyway, builds Unity Answers to become a greater resource. Hiding it but freely giving it "if someone asks" is silly because it's as if you never even said anything.

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

15 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

Related Questions

How can i save objects to a file 1 Answer

Unity Blackberry - Save file on device 0 Answers

Unity3: can I serialize non-POD types? (Color, Vector3, etc.)? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

Loading magica vox files into 3d byte array. 0 Answers


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