Comments (3)
i had this same problem, what's happening, as near as i can tell, is that the mesh is taking the scale set by the scale of the gameobject, so if you had a cube of 1x1x1 and you scaled it to 10x10x10 the newly created mesh would be 10x10x10 when you set the mesh of your gameobject this 10x10x10 cube gets scaled up by 10x10x10 and be 100x100x100.
in my case i just scaled it back down before adding it to the mesh:
Mesh scaleMesh(Mesh mesh, Vector3 scale)
{
var baseVertices = mesh.vertices;
var vertices = new Vector3[baseVertices.Length];
for (var i = 0; i < vertices.Length; i++)
{
var vertex = baseVertices[i];
vertex.x = vertex.x * scale.x;
vertex.y = vertex.y * scale.y;
vertex.z = vertex.z * scale.z;
vertices[i] = vertex;
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
return mesh;
}
Mesh centreMesh(Mesh mesh, Vector3 centre)
{
var baseVertices = mesh.vertices;
var vertices = new Vector3[baseVertices.Length];
for (var i = 0; i < vertices.Length; i++)
{
var vertex = baseVertices[i];
vertex.x = vertex.x + centre.x;
vertex.y = vertex.y + centre.y;
vertex.z = vertex.z + centre.z;
vertices[i] = vertex;
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
return mesh;
}
Vector3 getScale(Vector3 orig, Vector3 newVec)
{
return new Vector3(orig.x / newVec.x, orig.y / newVec.y, orig.z / newVec.z);
}
those are the functions i made to do this, then i do this:
CSG_Model result = Boolean.Subtract(me, cutter);
var factor=getScale(MFer.mesh.bounds.extents * 2.0f, result.mesh.bounds.extents * 2.0f);
var newMesh=scaleMesh(result.mesh, factor);
Vector3 CentreFactor = MFer.mesh.bounds.center - newMesh.bounds.center;
newMesh = centreMesh(newMesh, CentreFactor);
MFer.mesh = newMesh;
where MFer is the meshfilter for the object "me" in the subtract function.
from pb_csg.
i had this same problem, what's happening, as near as i can tell, is that the mesh is taking the scale set by the scale of the gameobject, so if you had a cube of 1x1x1 and you scaled it to 10x10x10 the newly created mesh would be 10x10x10 when you set the mesh of your gameobject this 10x10x10 cube gets scaled up by 10x10x10 and be 100x100x100.
in my case i just scaled it back down before adding it to the mesh:
Mesh scaleMesh(Mesh mesh, Vector3 scale) { var baseVertices = mesh.vertices; var vertices = new Vector3[baseVertices.Length]; for (var i = 0; i < vertices.Length; i++) { var vertex = baseVertices[i]; vertex.x = vertex.x * scale.x; vertex.y = vertex.y * scale.y; vertex.z = vertex.z * scale.z; vertices[i] = vertex; } mesh.vertices = vertices; mesh.RecalculateNormals(); mesh.RecalculateBounds(); return mesh; } Mesh centreMesh(Mesh mesh, Vector3 centre) { var baseVertices = mesh.vertices; var vertices = new Vector3[baseVertices.Length]; for (var i = 0; i < vertices.Length; i++) { var vertex = baseVertices[i]; vertex.x = vertex.x + centre.x; vertex.y = vertex.y + centre.y; vertex.z = vertex.z + centre.z; vertices[i] = vertex; } mesh.vertices = vertices; mesh.RecalculateNormals(); mesh.RecalculateBounds(); return mesh; } Vector3 getScale(Vector3 orig, Vector3 newVec) { return new Vector3(orig.x / newVec.x, orig.y / newVec.y, orig.z / newVec.z); }
those are the functions i made to do this, then i do this:
CSG_Model result = Boolean.Subtract(me, cutter); var factor=getScale(MFer.mesh.bounds.extents * 2.0f, result.mesh.bounds.extents * 2.0f); var newMesh=scaleMesh(result.mesh, factor); Vector3 CentreFactor = MFer.mesh.bounds.center - newMesh.bounds.center; newMesh = centreMesh(newMesh, CentreFactor); MFer.mesh = newMesh;
where MFer is the meshfilter for the object "me" in the subtract function.
Did you ever figure out how to make the object keep it's proportions when rotating?
from pb_csg.
I solved my issue #28
from pb_csg.
Related Issues (20)
- 2D drawing from 3d HOT 2
- Cutting a hole in the wall (Cube in the center of the Cube) HOT 1
- Mesh substraction results in non centered mesh HOT 1
- Concave meshes not supported
- trying to do Mesh Subtraction , but getting an exception , for these obj's?
- Trying to do mesh subtraction , of 2 obj's but getting this exception? HOT 2
- The name 'CSG' does not exist in the current context HOT 3
- Is This Still Possible HOT 2
- Subtracting two meshes, this is the results, am I expecting too much or have I messed something up?
- Cut mesh returns warped and out of position if it has rotation AND uneqal scale values HOT 1
- Bug fix with u [CSG_Model.cs] HOT 1
- Big scale size wavefront mesh failed to intersect... HOT 1
- Polygon multiplication bug in Node.AllPolygons()
- Complete PR HOT 2
- 50% of the time causes a stackoverflow exception when using standard subtract demo HOT 3
- Code to be fixed. HOT 1
- Doesn't work for flat mesh like Quad or Plane or any other generated flat mesh
- Check out my Repo for the best version with my own implementation, bug fixes and improvements HOT 1
- Do not have Universal Render Pipeline Support
- TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 96 HOT 1
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 pb_csg.