public Mesh GetMeshForMaterial(Material sourceMaterial, int fitVertices = 0) { if (materialMeshDictionary.Contains(sourceMaterial)) { List <MaterialMeshDictionary.MeshObjectMapping> mappings = materialMeshDictionary[sourceMaterial]; Mesh lastMesh = mappings[mappings.Count - 1].Mesh; if (lastMesh.vertices.Length + fitVertices < MESH_VERTEX_LIMIT) { return(lastMesh); } } Mesh mesh = new Mesh(); materialMeshDictionary.Add(sourceMaterial, mesh, null); if (sourceMaterial == null) { CSGFactory.CreateMaterialMesh(this.transform, GetDefaultMaterial(), mesh); } else { CSGFactory.CreateMaterialMesh(this.transform, sourceMaterial, mesh); } return(mesh); }
protected virtual void Update() { if (Application.isPlaying) { bool buildOccurred = CSGFactory.Tick(); if (buildOccurred) { OnBuildComplete(); } } }
/// <summary> /// Builds the brushes into final meshes /// </summary> /// <param name="forceRebuild">If set to <c>true</c> all brushes will be built and cached data ignored, otherwise SabreCSG will only rebuild brushes it knows have changed</param> /// <param name="buildInBackground">If set to <c>true</c> the majority of the build will occur in a background thread</param> public virtual void Build(bool forceRebuild, bool buildInBackground) { // If any of the build settings have changed, force all brushes to rebuild if (!lastBuildSettings.IsBuilt || CSGBuildSettings.AreDifferent(buildSettings, lastBuildSettings)) { forceRebuild = true; } // Make sure we have the most accurate list of brushes, ignoring inactive objects brushes = new List <Brush>(transform.GetComponentsInChildren <Brush>(false)); // Let each brush know it's about to be built for (int i = 0; i < brushes.Count; i++) { brushes[i].PrepareToBuild(brushes, forceRebuild); } // Perform a check to make sure the default material is OK Material defaultMaterial = GetDefaultMaterial(); if (defaultMaterial == null) { Debug.LogError("Default fallback material file is missing, try reimporting SabreCSG"); } // Make sure the build context has been initialized. if (buildContext == null) { buildContext = BuildContext; } BuildStatus buildStatus = CSGFactory.Build(brushes, buildSettings, buildContext, this.transform, materialMeshDictionary, collisionMeshDictionary, polygonsRemoved, forceRebuild, OnBuildProgressChanged, OnFinalizeVisualMesh, OnFinalizeCollisionMesh, buildInBackground); if (buildStatus == BuildStatus.Complete) { OnBuildComplete(); } }
public Mesh GetMeshForCollision(int fitVertices = 0) { Mesh lastMesh = collisionMeshDictionary.Last(); if (lastMesh.vertices.Length + fitVertices < MESH_VERTEX_LIMIT) { return(lastMesh); } Mesh mesh = new Mesh(); collisionMeshDictionary.Add(mesh); CSGFactory.CreateCollisionMesh(this.transform, mesh); return(mesh); }
public virtual bool Build(bool forceRebuild) { brushes = new List <Brush>(transform.GetComponentsInChildren <Brush>(false)); // Let each brush know it's about to be built for (int i = 0; i < brushes.Count; i++) { brushes[i].PrepareToBuild(brushes, forceRebuild); } Material defaultMaterial = GetDefaultMaterial(); if (defaultMaterial == null) { Debug.LogError("Default material file is missing, try reimporting SabreCSG"); } bool buildOccurred = CSGFactory.Build(brushes, buildSettings, buildContext, this.transform, GetDefaultMaterial(), ref materialMeshDictionary, ref collisionMeshDictionary, polygonsRemoved, forceRebuild, OnBuildProgressChanged); polygonsRemoved = false; if (buildOccurred) { UpdateBrushVisibility(); // Mark the brushes that have been built (so we can differentiate later if new brushes are built or not) builtBrushes.Clear(); builtBrushes.AddRange(brushes); FirePostBuildEvents(); } return(buildOccurred); }