Unity

Probuilder CSG 사용

Dean83 2023. 10. 18. 21:42

CSG(ProBuilder.Csg)

  • Boolean operations를 위한 API
  • 추가설명
    • 2개의 오브젝트 간, 교차, 합, 차 계산을 통해 새로운 오브젝트를 생성
    https://www.youtube.com/watch?v=SpQsbqxAK4I
  • Packages/com.unity.probuilder/External/CSG의 Classes, CSG, AssemblyInfo Script폴더 내 복사
  • 상세 코드
  •  
public static Model Union(GameObject lhs, GameObject rhs)
{
		Model csg_model_a = new Model(lhs);
		Model csg_model_b = new Model(rhs);
        
		Node a = new Node(csg_model_a.ToPolygons());
		Node b = new Node(csg_model_b.ToPolygons());

		List<Polygon> polygons = Node.Union(a, b).AllPolygons();

		return new Model(polygons);
}
public static Model Subtract(GameObject lhs, GameObject rhs)
{
		Model csg_model_a = new Model(lhs);
		Model csg_model_b = new Model(rhs);

		Node a = new Node(csg_model_a.ToPolygons());
		Node b = new Node(csg_model_b.ToPolygons());

		List<Polygon> polygons = Node.Subtract(a, b).AllPolygons();

		return new Model(polygons);
}

public static Model Intersect(GameObject lhs, GameObject rhs)
{
		Model csg_model_a = new Model(lhs);
		Model csg_model_b = new Model(rhs);

		Node a = new Node(csg_model_a.ToPolygons());
		Node b = new Node(csg_model_b.ToPolygons());

		List<Polygon> polygons = Node.Intersect(a, b).AllPolygons();

		return new Model(polygons);
}