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
1
Question by Julian-S · Jun 15, 2013 at 11:29 PM · cameracubevoxelocclusiondestructible

Demolishable object that won't kill my framerate

I have a voxel-based object that moves around my world. Right now I have it so that the object is made up of many separate cube objects parented to the main object. Each of these separate cubes has a script attached that makes it so they unparent when hit by a projectile and thus the object is completely destructible.

The problem is, the main object is then made up of about 900 separate cubes, and all of them, even the inner ones are always loaded.

I've tried InstantOC, an occlusion culling system, but even at a high raycast sample rate (which gets to be similarly expensive on it's own), the cubes don't always render properly, especially at semi-far distances.

I really need my object to be completely destructible as it is with just as many individual objects, but this is a major roadblock as I need to have many of these objects on screen at once eventually, so this needs to be solved before I move on.

If you could offer any help or suggestions, I would greatly appreciate it, thanks!

Comment
Add comment · Show 11
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 Julian-S · Jun 16, 2013 at 06:20 AM 0
Share

So, I was thinking that I could set up a parenting system for the entire object where each cube would have a script that would enable the inner objects touching it when it gets knocked off, but there must be a better way.

avatar image Julian-S · Jun 18, 2013 at 04:47 AM 0
Share

Another thought is that I could do the object in shells, with the outer shell always visible, and then the inner ones done with occlusion culling. And then once enough pieces fall off the outer shell, the nextmost inner one completely renders regardless of occlusion culling, and so on to the innermost shell.

avatar image whydoidoit · Jun 18, 2013 at 05:54 AM 2
Share

Well the "easiest" way is not to use separate game objects/meshes and to create a data structure that models your cube and then when you need to divide it (or whatever) you modify the mesh associated with the cube. Using a subdivision system (which would be non-trivial to write) you could have it so that the original mesh is just 24 vertices and then as you hit blocks you would alter the mesh. That said you would benefit from some culling if you made it from sections and then applied that process to those.

avatar image Julian-S · Jun 18, 2013 at 05:57 AM 0
Share

That sounds interesting. Is there any example of an implementation of that that you could refer me to?

avatar image whydoidoit · Jun 18, 2013 at 05:44 PM 1
Share

They turn them into multiple mesh combinations like I'm suggesting, allowing the GPU to do the heavy lifting and the "simple" voxel model to be represented by a suitably compact data structure.

A simple cube made up of 1000s of other cubes can be rendered as a single 6 faced cube when complete, each removal of a block can complicate it, but perhaps not too much in truth. Using GameObjects is going to force an almighty amount of culling and overdrawing that is unnecessary.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Zarenityx · Jul 09, 2013 at 01:56 PM

You have fallen into the biggest and most fallen into trap in the world of voxel-making. Voxels aren't actually cubes. If they were, then even a very small world, say 10x10x10 blocks would be 1000 cubes, which means 12000 triangles and 24000 vertices. Voxel engines actually use 'hypothetical voxels', which contain all of the information you might need to construct a voxel (uv coords, light, light emission, solidity, transparency...). Everything except a transform(because this is dependent on their location within the chunk. Then you need to make chunks(these can be objects), with a script that both stores a 3d array of hypotheticals, and then uses them to proceduraly generate a mesh for the chunk that only shows the faces which would be visible.

Essentially: Take this voxel. If it is solid, then proceed, otherwise skip it and move on. If there is a transparent voxel on this side, build a side of the cube, otherwise skip that side and go on.(do this for all of the sides) Then move on to the next voxel...

REMEMBER! YOU NEED AIR VOXELS! (non-solid, transparent voxels).

VOXEL GENERATION CAN BE VERY EASY, BUT REMEMBER: VOXELS ARE NOT OBJECTS I hope this helped. I am working on a voxel engine as well, and once I learned about this, My month long brain-ache finally stopped.

Comment
Add comment · Show 4 · 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 Julian-S · Jul 10, 2013 at 01:02 AM 0
Share

Awesome! This makes sense, thank you. Now to figure out how to implement this... Does this mean I can't use qubicle to create my models?

avatar image Zarenityx · Jul 10, 2013 at 02:13 PM 0
Share

I am not sure about all the details of Qubicle, having never actually used it, but to do the hypothetical voxel thing, your mesh needs to be procedurally generated. Essentially the voxels themselves don't have models, they map the model of the chunk. If you want fancy looking voxels, you may want to add a smoothing algorithm or something, otherwise it means long, tedious hours of procedural mesh coding. You could use Qubicle for the models of your mobs and stuff, but not for the actual voxels. As I understand it, Qubicle itself is a voxel engine, which contains only one chunk, then exports the model of the chunk that you edited. And if you want the objects to be destructible, this won't work. Sorry.

avatar image Zarenityx · Jul 10, 2013 at 02:16 PM 0
Share

Also, I forgot to mention a few simple things that really gave me brain-aches before I figured them out-

Each chunk must be re-rendered every time a voxel is added/removed

You need to overload all the arrays, otherwise you will get a ton of out of range errors

Handle generation by the world, but rendering by the chunks.

avatar image Julian-S · Jul 11, 2013 at 08:50 PM 0
Share

Ah, so essentially I'll be generating my terrain procedurally with the method that you're describing, and all my models with Qubicle.

Even though it doesn't really relate to the destructible object problem I was facing, this is still great information for when I begin generating large chunks of terrain! Thanks :)

avatar image
0

Answer by aldonaletto · Jun 18, 2013 at 04:51 PM

I would try a different approach: child the cubes to the healthy object and keep them deactivated - this way the cubes aren't rendered and don't waste time with physics calculations. When needed, detach and activate the children and destroy the healthy object.

The hierarchy could be something like this:

 HealthyObject // the healthy version, is active from the beginning
   DestroyedVersion // damaged version - empty object deactivated from the beginning 
     Cube // object pieces, all of them childed to the empty DestroyedObject
     Cube // the pieces are set active by default, but will stay deactivated
     Cube // because their parent isn't active
     ...

When the object is hit, set DestroyedVersion.transform.parent to null in order to detach it and destroy or deactivate HealthyObject: all pieces below DestroyedVersion in the hierarchy will wake up, since they already were active (although kept inactive due to their parent being deactivated).

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 Julian-S · Jun 18, 2013 at 05:08 PM 0
Share

If I understand properly what you are saying here, all of the cubes would then fall off after the healthy object is hit. The problem with that is that I need all of the cubes as independent pieces who each react to being hit separately. I don't know if I'm explaining this well. Basically if I still wanted to achieve what I'm trying to achieve using this, the hierarchy would be like this:

      Healthy Object
           DestroyedVersion
                Cube
 
      Healthy Object
           DestroyedVersion
                Cube
 
 //Etc. for each individual cube

which wouldn't save me any.

avatar image aldonaletto · Jun 18, 2013 at 05:16 PM 0
Share

I thought you wanted to make the object completely explode into pieces when hit. If the object must be destroyed partially according to the impact, this approach just makes things worse. $$anonymous$$aybe you could keep the inner cubes deactivated, but this would require a smart code to decide which cubes are exposed, and activate them.

avatar image Julian-S · Jun 18, 2013 at 05:18 PM 0
Share

Yeah I know, which is exactly the kind of code I want to avoid writing haha...

avatar image aldonaletto · Jun 18, 2013 at 05:27 PM 0
Share

$$anonymous$$aybe this could be implemented with a tridimensional GameObject array containing references to the cubes according to their positions. The script should activate the objects that have at least one neighbor empty (in six directions - corners don't count), and a detached cube should store null in its array position, so that the exposed neighbours could be activated by the control script.

avatar image Julian-S · Jun 18, 2013 at 05:33 PM 0
Share

Yes, that's the sort of thing I need to code. However, a couple of things first that might complicate it a little. The main object is made up of cubes, but isn't a cube itself. So the main object is irregularly shaped. Also, to avoid even more cubes, some of the pieces that need to fall off are made up of a few cubes (think tetris shapes). Also, the inside of the main object has some hollow areas.

avatar image
0

Answer by predatordpc · Jun 18, 2013 at 04:52 PM

maybe make particle system with those cubes as an particles, and when object gets hit maybe change it to other model (maybe 1 block? or replace with explosion ), then some script enabling particle system shoting cubes in all directions

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 Julian-S · Jun 18, 2013 at 05:24 PM 0
Share

Thanks for the suggestion, but I don't think that will work for what I'm going for.

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

19 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

Related Questions

One wall cube in the Scene is not shown by Camera in Game view 0 Answers

Camera View that has a lower Depth than the main Camera is being rendered in front of it on the right eye with Google Cardboard 0 Answers

Cube doesn't follow camera 1 Answer

Making a camera Pan around a cube 1 Answer

Return an array of meshes displayed on screen 3 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