elasticsea / unity-fracture Goto Github PK
View Code? Open in Web Editor NEWFracture any mesh at runtime
License: MIT License
Fracture any mesh at runtime
License: MIT License
Hi,
I am trying to adapt the code to use my own custom mesh with NvBlast. I imported in Unity a mesh made with an external 3D modelling package and then I fed it to the CreateWall object in the scene (basically my own mesh is fed as the cubeMesh in the script). Unfortunately Unity crashes.
On the other hand, if I try to feed one of Unity's built-in meshes (cube, sphere, capsule..), everything works fine.
After debugging for a while I realised that the crash occurs when the Fracture object calls setSourceMesh(nvMesh), so exactly inside the Bake method.
Any idea what is preventing my own meshes from working?
Thanks in advance
Thank you for publishing this awesome project.
I'm trying to use this to remove chunks instead of blast them away. So, I modified the ChunkNode.cs
script to try to Destroy the pieces when they're clicked (added void OnMouseDown, for example) but this caused problems with the script still trying to access Rigidbodies. I also tried to add logic like "if (rb)" instead of running Rigidbody-accessing codeblocks by default.
I'm not that comfortable with C#, honestly, so I was wondering if anyone could take a look and let me know the correct way to modify this script's behavior to simply remove Mouse-clicked chunks, rather than blast them flying away?
My poorly changed code:
using System.Collections.Generic;
using System.Linq;
using Project.Scripts.Utils;
using UnityEngine;
namespace Project.Scripts.Fractures
{
public class ChunkNode : MonoBehaviour
{
public HashSet<ChunkNode> Neighbours = new HashSet<ChunkNode>();
public ChunkNode[] NeighboursArray = new ChunkNode[0];
private Dictionary<Joint, ChunkNode> JointToChunk = new Dictionary<Joint, ChunkNode>();
private Dictionary<ChunkNode, Joint> ChunkToJoint = new Dictionary<ChunkNode, Joint>();
private Rigidbody rb;
private Vector3 frozenPos;
private Quaternion forzenRot;
private bool frozen;
public bool IsStatic => rb.isKinematic;
public Color Color { get; set; } = Color.black;
public bool HasBrokenLinks { get; private set; }
void OnMouseDown()
{
Destroy(this.gameObject);
return;
}
private bool Contains(ChunkNode chunkNode)
{
return Neighbours.Contains(chunkNode);
}
private void FixedUpdate()
{
// Kinda hacky, but otherwise the chunks slowly drift apart.
if (frozen)
{
transform.position = frozenPos;
transform.rotation = forzenRot;
}
}
public void Setup()
{
rb = GetComponent<Rigidbody>();
Freeze();
JointToChunk.Clear();
ChunkToJoint.Clear();
foreach (var joint in GetComponents<Joint>())
{
var chunk = joint.connectedBody.GetOrAddComponent<ChunkNode>();
JointToChunk[joint] = chunk;
ChunkToJoint[chunk] = joint;
}
foreach (var chunkNode in ChunkToJoint.Keys)
{
Neighbours.Add(chunkNode);
if (chunkNode.Contains(this) == false)
{
chunkNode.Neighbours.Add(this);
}
}
NeighboursArray = Neighbours.ToArray();
}
private void OnJointBreak(float breakForce)
{
HasBrokenLinks = true;
}
public void CleanBrokenLinks()
{
var brokenLinks = JointToChunk.Keys.Where(j => j == false).ToList();
foreach (var link in brokenLinks)
{
var body = JointToChunk[link];
JointToChunk.Remove(link);
ChunkToJoint.Remove(body);
body.Remove(this);
Neighbours.Remove(body);
}
NeighboursArray = Neighbours.ToArray();
HasBrokenLinks = false;
}
private void Remove(ChunkNode chunkNode)
{
ChunkToJoint.Remove(chunkNode);
Neighbours.Remove(chunkNode);
NeighboursArray = Neighbours.ToArray();
}
public void Unfreeze()
{
frozen = false;
rb.constraints = RigidbodyConstraints.None;
rb.useGravity = true;
rb.gameObject.layer = LayerMask.NameToLayer("Default");
}
private void Freeze()
{
frozen = true;
rb.constraints = RigidbodyConstraints.FreezeAll;
rb.useGravity = false;
rb.gameObject.layer = LayerMask.NameToLayer("FrozenChunks");
frozenPos = rb.transform.position;
forzenRot = rb.transform.rotation;
}
private void OnDrawGizmos()
{
Gizmos.color = Color;
Gizmos.DrawSphere(transform.TransformPoint(transform.GetComponent<Rigidbody>().centerOfMass), 0.1f);
foreach (var joint in JointToChunk.Keys)
{
if (joint)
{
if (rb)
{
var from = transform.TransformPoint(rb.centerOfMass);
if (joint.connectedBody)
{
var to = joint.connectedBody.transform.TransformPoint(joint.connectedBody.centerOfMass);
Gizmos.DrawLine(from, to);
}
}
}
}
}
private void OnDrawGizmosSelected()
{
foreach (var node in Neighbours)
{
var mesh = node.GetComponent<MeshFilter>().mesh;
Gizmos.color = Color.yellow.SetAlpha(.2f);
Gizmos.DrawMesh(mesh, node.transform.position, node.transform.rotation);
}
}
}
}
Does this project support nvblast sleeping and multi threading?
Check the section "groups and parallel processing"
https://docs.nvidia.com/gameworks/content/gameworkslibrary/blast/blast.htm
If you shoot anything in the level, Unity will raise null ref exception because Event System is missing. After manually adding it to the scene, the sample runs :)
Hi,
In my custom scene, if I generate a wall with 500 chunks (each with a blue outer material and white inner material), I roughly get 2000 batches.
Now, I am still learning about graphics so it may easily be a misunderstanding from my side, but I would expect the number of batches to be 1000, since there are 2 different materials per chunk, thus 2*500 = 1000.
Moreover, since they are sharing the two repeated materials, shouldn't batching actually be much lower, thus actually saving ms?
What rendering concepts am I missing?
Thanks in advance
Was wondering how to fix this issue?
I tried changing the fractured.transform.SetParent(transform) within CreateWalls.cs to fractured.transform.SetParent(transform, true) with no luck.
Any advice?
I search for documentation of NvBlastExtUnity_x64.dll then I got this project : https://github.com/NVIDIAGameWorks/Blast.
But I still cannot find the specific doc of NvBlastExtUnity_x64.dll.
This works really well in the unity editor and with x64 windows builds, however, when I build to android I run into problems.
I used android logcat to pinpoint exactly what was happening. Here is the output from the log file.
Essentially the NvBlastExtUnity_x64.dll isn't getting included in the build. Do you have any thoughts on how to fix this?
I am wondering if there is a way to move a fractured mesh. In my game I want the Player be able to pick it up and carry it around, but in Editor it's acting like it's glued to the ground.
I'm using Unity 2022.2.4f1.
The blend files in the demo are not supported so I exported them as FBX, like the dragon. Unfortunately they do not get fragmented into chunks. What could be the issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.