Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        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);
        }