public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyObject(ringGameObject);
        SGT_Helper.DestroyObjects(generatedMeshes);
        SGT_Helper.DestroyObject(ringMaterial);
    }
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(starfieldGameObject);
        SGT_Helper.DestroyObject(starfieldMaterial);
        SGT_Helper.DestroyObjects(meshes);
    }
Ejemplo n.º 3
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(surfaceGameObject);
        SGT_Helper.DestroyGameObject(oblatenessGameObject);
        SGT_Helper.DestroyGameObject(atmosphereGameObject);
        SGT_Helper.DestroyObjects(surfaceMaterials);
        SGT_Helper.DestroyObject(atmosphereMaterial);
        SGT_Helper.DestroyObject(atmosphereTexture);
        SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
    }
    public new void OnDestroy()
    {
        base.OnDestroy();

        if (sideCombinedMeshes != null)
        {
            for (var i = 0; i < 6; i++)
            {
                SGT_Helper.DestroyObjects(sideCombinedMeshes[i]);
            }
        }

        DestroyPatches();
    }
Ejemplo n.º 5
0
    public void RemoveAll()
    {
        if (meshes != null)
        {
            meshes.Clear();
        }

        if (meshGameObjects != null)
        {
            SGT_Helper.DestroyObjects(meshGameObjects);

            meshGameObjects.Clear();
        }
    }
Ejemplo n.º 6
0
    public void Regenerate()
    {
        RecalculateWeights();

        if (debrisList != null)
        {
            SGT_Helper.DestroyObjects(debrisList);

            debrisList.Clear();
        }

        for (var i = 0; i < debrisCountMax; i++)
        {
            SpawnDebris(false);
        }
    }
Ejemplo n.º 7
0
    public new void OnDestroy()
    {
        base.OnDestroy();

        SGT_Helper.DestroyGameObject(surfaceGameObject);
        SGT_Helper.DestroyGameObject(atmosphereGameObject);
        SGT_Helper.DestroyGameObject(cloudsGameObject);

        SGT_Helper.DestroyObjects(surfaceMaterials);
        SGT_Helper.DestroyObject(atmosphereMaterial);
        SGT_Helper.DestroyObjects(cloudsMaterials);

        SGT_Helper.DestroyObject(surfaceLightingTexture);
        SGT_Helper.DestroyObject(atmosphereTexture);
        SGT_Helper.DestroyObject(atmosphereSurfaceTexture);
        SGT_Helper.DestroyObject(cloudsLightingTexture);
    }
Ejemplo n.º 8
0
    private void UpdateMaterial()
    {
        var targetSurfaceTechnique    = "Variant";
        var targetAtmosphereTechnique = "Variant";

        if (starObserver != null)
        {
            if (InsideAtmosphere(starObserver.transform.position) == false)
            {
                targetSurfaceTechnique    += "Outer";
                targetAtmosphereTechnique += "Outer";
            }
        }

        if (atmosphereSurfacePerPixel == true)
        {
            targetSurfaceTechnique += "PerPixel";
        }

        // Update surface?
        if (surfaceMaterials == null || (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration)))
        {
            SGT_Helper.DestroyObjects(surfaceMaterials);

            surfaceTechnique = targetSurfaceTechnique;
            surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(surfaceMultiMesh.Configuration, "Hidden/SGT/StarSurface/" + surfaceTechnique, surfaceRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue);
        }

        // Update atmosphere?
        if (atmosphereTechnique != targetAtmosphereTechnique || atmosphereMaterial == null)
        {
            SGT_Helper.DestroyObject(atmosphereMaterial);

            atmosphereTechnique = targetAtmosphereTechnique;
            atmosphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/StarAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue);
        }
    }
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            modified = false;

            SGT_Helper.DestroyObjects(generatedMeshes);

            SGT_Helper.BeginRandomSeed(ringSeed);
            {
                var remainingAsteroids = ringAsteroidCount;
                var asteroidsPerMesh   = SGT_Helper.MeshVertexLimit / 4;
                var newMeshes          = new MeshList();

                while (remainingAsteroids > 0)
                {
                    var asteroidsInMesh = Mathf.Min(remainingAsteroids, asteroidsPerMesh);

                    newMeshes.Add(GenerateAsteroidMesh(asteroidsInMesh));

                    remainingAsteroids -= asteroidsInMesh;
                }

                generatedMeshes = newMeshes.ToArray();

                if (ringMultiMesh != null)
                {
                    ringMultiMesh.ReplaceAll(generatedMeshes);
                    ringMultiMesh.Update();
                }
            }
            SGT_Helper.EndRandomSeed();
        }
    }
Ejemplo n.º 10
0
    private void UpdateTechnique()
    {
        var targetSurfaceTechnique    = "Variant";
        var targetAtmosphereTechnique = string.Empty;
        var tagetCloudsTechnique      = string.Empty;

        if (atmosphere == true)
        {
            targetSurfaceTechnique   += "Atmosphere";
            targetAtmosphereTechnique = "Variant";

            if (planetObserver != null)
            {
                if (InsideAtmosphere(planetObserver.transform.position) == false)
                {
                    targetSurfaceTechnique    += "Outer";
                    targetAtmosphereTechnique += "Outer";
                }
            }

            if (atmosphereScattering == true)
            {
                //targetSurfaceTechnique    += "Scattering";
                targetAtmosphereTechnique += "Scattering";
            }
        }

        if (clouds == true)
        {
            tagetCloudsTechnique = "Variant";
        }

        if (surfaceTextureNormal.ContainsSomething == true)
        {
            targetSurfaceTechnique += "Normal";
        }

        if (surfaceTextureSpecular.ContainsSomething == true)
        {
            targetSurfaceTechnique += "Specular";
        }

        if (shadow == true)
        {
            switch (shadowCasterType)
            {
            case SGT_ShadowOccluder.Ring:
            {
                targetSurfaceTechnique += "RingShadow";

                if (atmosphere == true)
                {
                    targetAtmosphereTechnique += "RingShadow";
                }

                if (clouds == true)
                {
                    tagetCloudsTechnique += "RingShadow";
                }
            }
            break;

            case SGT_ShadowOccluder.Planet:
            {
                targetSurfaceTechnique += "PlanetShadow";

                if (atmosphere == true)
                {
                    targetAtmosphereTechnique += "PlanetShadow";
                }

                if (clouds == true)
                {
                    tagetCloudsTechnique += "PlanetShadow";
                }
            }
            break;
            }
        }

        if (surfaceTextureDetail != null)
        {
            targetSurfaceTechnique += "Detail";
        }

        if (surfaceMaterials != null && (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration)))
        {
            surfaceMaterials = SGT_Helper.DestroyObjects(surfaceMaterials);
        }

        if (atmosphereMaterial != null && (atmosphere == false || atmosphereTechnique != targetAtmosphereTechnique))
        {
            atmosphereMaterial = SGT_Helper.DestroyObject(atmosphereMaterial);
        }

        if (cloudsMaterials != null && (clouds == false || cloudsTechnique != tagetCloudsTechnique || SGT_ArrayHelper.ContainsSomething(cloudsMaterials) == false || cloudsMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(CloudsConfiguration)))
        {
            cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials);
        }

        // Create planet surface shaders?
        if (surfaceMaterials == null)
        {
            updateShader    |= ShaderFlags.Surface;
            surfaceTechnique = targetSurfaceTechnique;
            surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(SurfaceConfiguration, "Hidden/SGT/PlanetSurface/" + surfaceTechnique, surfaceRenderQueue);
        }
        else
        {
            SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue);
        }

        // Create planet atmosphere shaders?
        if (atmosphere == true)
        {
            if (atmosphereMaterial == null)
            {
                updateShader       |= ShaderFlags.Atmosphere;
                atmosphereTechnique = targetAtmosphereTechnique;
                atmosphereMaterial  = SGT_Helper.CreateMaterial("Hidden/SGT/PlanetAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue);
            }
            else
            {
                SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue);
            }
        }

        // Create planet cloud shaders?
        if (clouds == true)
        {
            if (cloudsMaterials == null)
            {
                updateShader   |= ShaderFlags.Clouds;
                cloudsTechnique = tagetCloudsTechnique;
                cloudsMaterials = SGT_SurfaceConfiguration_.CreateMaterials(CloudsConfiguration, "Hidden/SGT/PlanetClouds/" + cloudsTechnique, atmosphereRenderQueue);
            }
            else
            {
                SGT_Helper.SetRenderQueues(cloudsMaterials, atmosphereRenderQueue);
            }
        }
        else
        {
            if (cloudsMaterials != null)
            {
                cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials);
            }
        }
    }
    private System.Collections.IEnumerator Update_Coroutine()
    {
        if (patchIndices == null)
        {
            RebuildPatchIndices();
        }

        sideCombinedMeshes = new Mesh[6][];

        // Main loop
        for (;;)
        {
            if (sides != null)
            {
                var sgtVector3 = new SGT_FillVector3();
                SendMessage("FillSurfaceObserverPosition", sgtVector3, SendMessageOptions.DontRequireReceiver);
                surfaceObserverPosition = sgtVector3.Vector3;

                var splitList = new PatchList();

                // Begin budgeting
                budgetUsage.Reset();
                budgetUsage.Start();

                // Update all patches
                for (var i = 0; i < sides.Length; i++)
                {
                    UpdatePatch(sides[i], surfaceObserverPosition, splitList);

                    /* Defer operation? */ if (OverBudgetCheck("Update Patches") == true)
                    {
                        yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                    }
                }

                // Split patches?
                if (splitList.Count > 0)
                {
                    var splitCount = 0;

                    for (var i = 0; i < splitList.Count; i++)
                    {
                        splitCount += 1;

                        SplitPatch(splitList[i]);

                        if (splitCount == maxSplitsPerFrame)
                        {
                            splitCount = 0;

                            /* Defer operation? */ if (OverBudgetCheck("Split Patches") == true)
                            {
                                yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                            }
                        }
                    }
                }

                // Rebuild mesh?
                if (rebuild == true)
                {
                    rebuild = false;

                    var totalSurfaces         = SGT_SurfaceConfiguration_.SurfaceCount(surfaceConfiguration);
                    var newSideCombinedMeshes = new Mesh[6][];

                    for (var surfaceIndex = 0; surfaceIndex < totalSurfaces; surfaceIndex++)
                    {
                        var buildList = new PatchList();

                        // Begin budgeting
                        budgetUsage.Reset();
                        budgetUsage.Start();

                        switch (surfaceConfiguration)
                        {
                        case SGT_SurfaceConfiguration.Sphere:
                        {
                            for (var i = 0; i < 6; i++)
                            {
                                BuildPatch(sides[i], buildList);

                                /* Defer operation? */ if (OverBudgetCheck("Build Patches") == true)
                                {
                                    yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                                }
                            }
                        }
                        break;

                        case SGT_SurfaceConfiguration.Cube:
                        {
                            BuildPatch(sides[surfaceIndex], buildList);

                            /* Defer operation? */ if (OverBudgetCheck("Build Patches") == true)
                            {
                                yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                            }
                        }
                        break;
                        }

                        // Stitch patches
                        var stitchCount = 0;

                        for (var i = 0; i < buildList.Count; i++)
                        {
                            stitchCount += 1;

                            StitchPatch(buildList[i]);

                            if (stitchCount == maxStitchesPerFrame)
                            {
                                stitchCount = 0;

                                /* Defer operation? */ if (OverBudgetCheck("Sitch Patches") == true)
                                {
                                    yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                                }
                            }
                        }

                        var combinedMeshesList = new MeshList();
                        var combineFrom        = 0;
                        var patchesPerMesh     = verticesPerMesh / ((patchResolution + 1) * (patchResolution + 1));

                        // Create sub meshes
                        for (var i = 0; i < buildList.Count; i++)
                        {
                            var combineCount = (i + 1) - combineFrom;

                            if (combineCount == patchesPerMesh || i == (buildList.Count - 1))
                            {
                                var combinedMesh = CombinePatches(buildList, combineFrom, combineFrom + combineCount);

                                combinedMeshesList.Add(combinedMesh);

                                combineFrom = i + 1;

                                /* Defer operation? */ if (OverBudgetCheck("Combine Patches") == true)
                                {
                                    yield return(new WaitForEndOfFrame()); budgetUsage.Reset(); budgetUsage.Start();
                                }
                            }
                        }

                        var combinedMeshes = combinedMeshesList.ToArray();

                        // Append index to name?
                        if (combinedMeshes.Length > 1)
                        {
                            for (var i = 0; i < combinedMeshes.Length; i++)
                            {
                                combinedMeshes[i].name = "(" + (i + 1) + "/" + combinedMeshes.Length + ") " + combinedMeshes[i].name;
                            }
                        }

                        newSideCombinedMeshes[surfaceIndex] = combinedMeshes;
                    }

                    // Delete old meshes and swap
                    for (var i = 0; i < 6; i++)
                    {
                        SGT_Helper.DestroyObjects(sideCombinedMeshes[i]);
                    }

                    sideCombinedMeshes = newSideCombinedMeshes;

                    var generatedSurfaceMultiMesh = new SGT_SurfaceMultiMesh();

                    generatedSurfaceMultiMesh.Configuration = surfaceConfiguration;

                    for (var i = 0; i < totalSurfaces; i++)
                    {
                        generatedSurfaceMultiMesh.ReplaceAll(sideCombinedMeshes[i], i);
                    }

                    SendMessage("SetSurfaceMultiMesh", generatedSurfaceMultiMesh, SendMessageOptions.DontRequireReceiver);

                    SendMessage("TessellationFinished", this, SendMessageOptions.DontRequireReceiver);
                }
            }

            if (minUpdateInterval > 0.0f)
            {
                yield return(new WaitForSeconds(minUpdateInterval));
            }
            else
            {
                yield return(new WaitForEndOfFrame());
            }
        }
    }
Ejemplo n.º 12
0
 public void OnDestroy()
 {
     SGT_Helper.DestroyObjects(atlases);
 }
Ejemplo n.º 13
0
    public SGT_PackerResult Pack()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            atlases = SGT_Helper.DestroyObjects(atlases);
            outputs = Compile();

            // Can't pack nothing
            if (outputs.Count != 0)
            {
                // Sort into largest first
                outputs.Sort((a, b) => (int)b.OutputRect.width - (int)a.OutputRect.width);

                // Find base size
                var baseSize = Mathf.NextPowerOfTwo((int)outputs[0].OutputRect.width);

                // Largest texture is larger than maxTextureSize
                if (baseSize > (int)atlasMaxSize)
                {
                    return(SGT_PackerResult.AtlasTooSmall);
                }

                // Create first bin
                var bins = new BinList(1);

                bins.Add(new SGT_PackerBin(0, baseSize, (int)atlasMaxSize));

                // Pack all textures
                foreach (var output in outputs)
                {
                    // Fits in existing bins?
                    foreach (var bin in bins)
                    {
                        if (bin.Pack(output) == true)
                        {
                            goto FoundBin;
                        }
                    }

                    // Create new bin?
                    if (atlasCountMax <= 0 || bins.Count < atlasCountMax)
                    {
                        var newBin = new SGT_PackerBin(bins.Count, baseSize, (int)atlasMaxSize);

                        if (newBin.Pack(output) == false)
                        {
                            return(SGT_PackerResult.Unknown);
                        }

                        bins.Add(newBin);
                    }
                    // Too many bins?
                    else
                    {
                        return(SGT_PackerResult.NotEnoughAtlases);
                    }

FoundBin:
                    continue;
                }

                // Build textures
                atlases = new Texture2D[bins.Count];

                for (var i = 0; i < bins.Count; i++)
                {
                    var bin     = bins[i];
                    var texture = new Texture2D(bin.Size, bin.Size, atlasFormat, atlasMipMaps);

                    texture.anisoLevel = atlasAnisoLevel;
                    texture.wrapMode   = TextureWrapMode.Clamp;
                    texture.filterMode = atlasFilterMode;

                    for (var y = 0; y < texture.width; y++)
                    {
                        for (var x = 0; x < texture.height; x++)
                        {
                            texture.SetPixel(x, y, Color.black);
                        }
                    }

                    atlases[i] = texture;
                }

                // Paste textures
                foreach (var output in outputs)
                {
                    var texture = atlases[output.OutputTextureId];

                    output.PasteInto(texture);
                }

                // Apply pastes
                foreach (var texture in atlases)
                {
                    texture.Apply();
                }
            }

            MarkAsUnmodified();
        }

        return(SGT_PackerResult.Success);
    }
 private void DestroyGeneratedMeshes()
 {
     meshDatas = null;
     meshes    = SGT_Helper.DestroyObjects(meshes);
 }