Git Product home page Git Product logo

unity-fracture's Introduction

Unity Fracture

preview_github.mp4

FractureThis.cs script takes all meshes in its gameobject and merges them. This global mesh is send to nvblast for fracturing into chunks. The inside part of the chunk has new UVs generated for material to be applied. Original gameobject is hidden and each chunk mesh is converted to gameobject with rigibody. Neighboring chunks are tethered with fixedjoints.

Requirements

How does this work?

  1. Cut the mesh into smaller meshes chunks
  2. Add rigidbody component to each chunk
  3. Connect chunks with fixed joints that break with force

1) Cut the mesh into smaller meshes chunks

I stumbled upon this forum thread https://forum.unity.com/threads/nvidia-blast.472623 where someone figured out how to use Nvidia blast library in the Unity. Feed the library with mesh (must have vertices, triangles, uvs and closed without missing any faces) to this library and receive mesh chunks.

2) Add rigidbody component to each chunk

Convert each mesh chunk into a gameobject with rigidbody. Without anything holding the chunks together they crumble to the ground. Connect the chunks with fixed joints, so they stay in place. Take each chunk and its neighbors (chunks that are in close proximity or in touch) and connect them with fixed joints.

Issue #1 - Structure is wobbly

This is not ideal, the joints are not 100% fixed in place due to how PhysX resolves collisions. There is a big deal of springiness within the joints. The structure ripples when force is applied and acts like a it is made out of jello.

Solution #1 - Freeze rigidbodies

https://answers.unity.com/questions/230995/fixed-joint-not-really-fixed.html advised to freeze the rigidbody. Freezing the rigidbodies makes them stay in place (they drift apart after some time #1) and the rigidbodies still register impact and the joints can be broken.

Issue #2 - Rigidbodies float in the air

Rigidbodies will stay in place even though there is no support under them. They will only resume movement when all joints are broken.

Solution #2 - Introduce anchors

Let's create a graph of connected chunks. Traverse graph each frame and unfreeze chunks disconnected from anchors (kinematic body)

Chunk Graph Anchored chunks are red

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.