Comments (3)
I have not tried your code, but from what you have described, my guess is that the unity cube is actually 6 separate planes (almost certain about this). The plane-cut can work on that, but the result is still separate mesh patches. To do a hole-fill, the cube faces need to be welded along the borders.
An easy way to do this is to add the unity Mesh vertices to a Dictionary, where you assign a new vertex id only if the vertex is not already in the dictionary (my Vertex3d can be used as a Dictionary key). Then your mapV will map some input-triangle vertices to the same output vertex, and the result will be welded together.
This will break UVs, though. If you need to preserve UVs through this...that is more complicated.
from geometry3sharp.
Ahh, right. This must be the case since all the sides of the Unity cube have separate normals. So it should be possible to create a loop out of those CutSpans I guess.
I'll probably just go with your solution and always process the mesh as "closed". Then I'll break it up to create separate faces if needed.
Thanks!
from geometry3sharp.
It works :)
Ran into some numerical issues during cutting, but nothing that couldn't been fixed with small offsets.
Here is the code for creating the merged mesh if anyone is interested:
public static DMesh3 ToDMesh3Merged(this Mesh mesh) {
DMesh3 result = new DMesh3(bWantNormals: false);
var verts = mesh.vertices;
var tris = mesh.triangles;
Dictionary<Vector3d, int> vertexHashToUnityVertexIndex = new Dictionary<Vector3d, int>();
int[] unityVertexIndexToDMeshVertexIndex = new int[verts.Length];
for (int i = 0; i < verts.Length; i++) {
var vert = (Vector3d) verts[i];
if (vertexHashToUnityVertexIndex.ContainsKey(vert)) {
var mergedUnityVertexIndex = vertexHashToUnityVertexIndex[vert];
unityVertexIndexToDMeshVertexIndex[i] = unityVertexIndexToDMeshVertexIndex[mergedUnityVertexIndex];
} else {
int vertId = result.AppendVertex(
new NewVertexInfo {
v = vert,
}
);
vertexHashToUnityVertexIndex[vert] = i;
unityVertexIndexToDMeshVertexIndex[i] = vertId;
}
}
for (int i = 0; i < tris.Length; i += 3) {
result.AppendTriangle(
unityVertexIndexToDMeshVertexIndex[tris[i]],
unityVertexIndexToDMeshVertexIndex[tris[i+1]],
unityVertexIndexToDMeshVertexIndex[tris[i+2]]);
}
return result;
}
Also, here is some code to split all vertices, if you want to do some flat-shaded stuff:
public static DMesh3 ToSplittedDMesh3(this DMesh3 dm) {
DMesh3 result = new DMesh3(bWantNormals: false);
foreach (var triIndex in dm.TriangleIndices()) {
var tri = dm.GetTriangle(triIndex);
var a = result.AppendVertex(dm.GetVertex(tri.a));
var b = result.AppendVertex(dm.GetVertex(tri.b));
var c = result.AppendVertex(dm.GetVertex(tri.c));
result.AppendTriangle(a, b, c);
}
return result;
}
from geometry3sharp.
Related Issues (20)
- Is this project dead? HOT 1
- Get brick materials right
- Fix hover info on bricks
- Rewrite right pointer (PLEASE!) HOT 1
- Mesh expansion and comparison
- Refactor cursor3d
- Refactor HandR and HandL to use input action class
- Write playmode tests for right pointer flow
- Rider clean project to adjust line length
- Break up LDrawConfig into different classes
- Refactor BrickMaterialsLoader (PLEASE!!!)
- Example of mesh volume calculation HOT 3
- 这个可以做曲面拟合吗?
- Can this be used for surface fitting?
- Narrow band SDF generation from meshes is adding a shell to objects HOT 1
- Minkowski sum 3D
- Get closest vertex on mesh surface HOT 2
- Boolean operations on polygons and polyhedra?
- Quadratic Bezier Curves HOT 1
- Is it possible to combine 2 adjacent polygons into 1 polygon
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geometry3sharp.