public static bool GenerateBoxSubMesh(CSGBrushSubMesh subMesh, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions) { if (!BoundsExtensions.IsValid(min, max)) { return(false); } if (surfaceAssets.Length != 6 || surfaceDescriptions.Length != 6) { return(false); } if (min.x > max.x) { float x = min.x; min.x = max.x; max.x = x; } if (min.y > max.y) { float y = min.y; min.y = max.y; max.y = y; } if (min.z > max.z) { float z = min.z; min.z = max.z; max.z = z; } subMesh.Polygons = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions); subMesh.HalfEdges = boxHalfEdges.ToArray(); subMesh.Vertices = BrushMeshFactory.CreateBoxVertices(min, max); return(true); }
public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceFlags surfaceFlags = SurfaceFlags.None) { if (!BoundsExtensions.IsValid(min, max)) { brushMeshAsset.Clear(); return(false); } if (surfaceAssets.Length != 6) { brushMeshAsset.Clear(); return(false); } if (min.x > max.x) { float x = min.x; min.x = max.x; max.x = x; } if (min.y > max.y) { float y = min.y; min.y = max.y; max.y = y; } if (min.z > max.z) { float z = min.z; min.z = max.z; max.z = z; } brushMeshAsset.Polygons = CreateBoxAssetPolygons(surfaceAssets, surfaceFlags); brushMeshAsset.HalfEdges = boxHalfEdges.ToArray(); brushMeshAsset.Vertices = BrushMeshFactory.CreateBoxVertices(min, max); brushMeshAsset.CalculatePlanes(); brushMeshAsset.SetDirty(); return(true); }
protected override void UpdateGeneratorInternal() { if (surfaceAssets == null) { var defaultRenderMaterial = CSGMaterialManager.DefaultWallMaterial; var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial; surfaceAssets = new CSGSurfaceAsset[6] { CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial), CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial), CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial), CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial), CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial), CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial) }; } if (surfaceDescriptions == null || surfaceDescriptions.Length != 6) { // TODO: make this independent on plane position somehow var surfaceFlags = CSGDefaults.SurfaceFlags; surfaceDescriptions = new SurfaceDescription[6] { new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 }, new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 }, new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 }, new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 }, new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 }, new SurfaceDescription { UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0 } }; } if (BoundsExtensions.IsValid(bounds.min, bounds.max)) { BrushMeshAssetFactory.GenerateBoxAsset(brushMeshAsset, bounds, surfaceAssets, surfaceDescriptions); } else { brushMeshAsset.Clear(); } }
public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions) { if (!BoundsExtensions.IsValid(min, max)) { brushMeshAsset.Clear(); Debug.LogError("bounds is of an invalid size " + (max - min)); return(false); } if (surfaceDescriptions == null || surfaceDescriptions.Length != 6) { brushMeshAsset.Clear(); Debug.LogError("surfaceDescriptions needs to be an array of length 6"); return(false); } if (surfaceAssets == null || surfaceAssets.Length != 6) { brushMeshAsset.Clear(); Debug.LogError("surfaceAssets needs to be an array of length 6"); return(false); } if (min.x > max.x) { float x = min.x; min.x = max.x; max.x = x; } if (min.y > max.y) { float y = min.y; min.y = max.y; max.y = y; } if (min.z > max.z) { float z = min.z; min.z = max.z; max.z = z; } brushMeshAsset.Polygons = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions); brushMeshAsset.HalfEdges = boxHalfEdges.ToArray(); brushMeshAsset.Vertices = BrushMeshFactory.CreateBoxVertices(min, max); brushMeshAsset.CalculatePlanes(); brushMeshAsset.SetDirty(); return(true); }