tvtig / unitylightsaber Goto Github PK
View Code? Open in Web Editor NEWA lighsaber modelled in blender and brough to life in unity
License: MIT License
A lighsaber modelled in blender and brough to life in unity
License: MIT License
I am using this code in my project and it helped a lot! Just a minor issue that if the original mesh has a texture, it won't stay at the same place after the slice. Is it possible to solve without adding too much code? Thank you!
First of all, I would like to thank you for creating this and uploading it to github.
I've been playing around with this, and it turns out there are unnecessary IndexOf calls (vertIndex var can just be meshTriangles[i], [i+1] and so on) which take a lot of execution time (around 70% of it) - it would be nice to change that in source repo for any other people trying it in the future.
Additionally, I believe replacing
Vector3 vert1 = meshVerts[meshTriangles[i]];
int vert1Index = Array.IndexOf(meshVerts, vert1);
It should be:
int vert1Index = meshTriangles[i];
Vector3 vert1 = meshVerts[vert1Index];
If you intend for others to be able to use this, you'll need to use a license, otherwise it goes under copyright law. So if you want it to be usable by others consider adding a Open Source License like MIT License, or similar.
Here are a few to choose from: https://opensource.org/licenses
Hello,
Thank you for this, it's great!
I've been trying to use it in a simpler way (i.e. not using a light saber, just creating my own plane), but I run into some weird behavior. I'm slicing a very thin wall with a horizontal plane:
Plane pl = new Plane(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(6.0f, 3.0f, 7.5f)); GameObject[] slices = Slicer.Slice(pl, hit.transform.gameObject);
The slicing seems to be fine, except that one of the 2 new parts is wrongly placed, as illustrated below.
Furthermore, there is no Mesh component in the inspector, is that normal?
Well, anyways thanks a lot ;)
You have a Plane object, so you could use Plane.GetDistanceToPoint() method instead of casting a Ray:
https://github.com/Tvtig/UnityLightsaber/blame/d3635f5dbc568356923918ad3aca30b7b4268c72/Assets/Scripts/SlicesMetadata.cs#L523
With given distances you could calculate intersection point using this code:
float t = startDistance / (startDistance - endDistance);
return Vector3.Lerp(vertices[vertexStartIdx], vertices[vertexEndIdx], t);
IndexOf finds the first item. When we don't use shared vertices it always finds the first one and it causes display errors.
This code:
vertices.Add(vertex);
normals.Add(normal);
uvs.Add(uv);
triangles.Add(vertices.IndexOf(vertex));
Should be:
triangles.Add(vertices.Count);
vertices.Add(vertex);
normals.Add(normal);
uvs.Add(uv);
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.