Example #1
0
    void Update()
    {
        if (settingsChanged)
        {
            settingsChanged = false;
            if (mesh == null)
            {
                mesh = new Mesh();
            }
            else
            {
                mesh.Clear();
            }

            IcoSphereGenerator s = new IcoSphereGenerator();
            s.Generate(terrainResolution);
            mesh.vertices  = s.Vertices;
            mesh.triangles = s.Triangles;
            mesh.RecalculateBounds();
            mesh.RecalculateNormals();

            var g = GetOrCreateMeshObject("Mesh", mesh, material);
            if (!g.GetComponent <MeshCollider> ())
            {
                g.AddComponent <MeshCollider> ();
            }
            g.GetComponent <MeshCollider> ().sharedMesh = mesh;
        }
    }
    void SetupSphere()
    {
        sphereTransform       = new GameObject("Sphere Transform");
        sphereTransform.layer = DomeCameraRig.DOME_LAYER;
        sphereTransform.transform.SetParent(transform);
        sphereTransform.transform.position = gameObject.transform.position;
        sphereTransform.transform.rotation = gameObject.transform.rotation;

        sphere       = new GameObject("Dome Sphere");
        sphere.layer = DomeCameraRig.DOME_LAYER;
        IcoSphereGenerator.Create(sphere, true, 4);
        var sphereRenderer = sphere.AddComponent <MeshRenderer>();

        sphere.transform.SetParent(sphereTransform.transform);
        sphere.transform.position = sphereTransform.transform.position;
        sphere.transform.rotation = sphereTransform.transform.rotation;
        sphere.transform.Rotate(new Vector3(0, -135, 0));

        sphereRenderer.material.shader = Shader.Find("Unlit/Dome2ProjectorShader");
        sphereRenderer.material.SetTexture("_LeftTex", cameraRig.renderTextures[0]);
        sphereRenderer.material.SetTexture("_RightTex", cameraRig.renderTextures[1]);
        sphereRenderer.material.SetTexture("_TopTex", cameraRig.renderTextures[2]);
        sphereRenderer.material.SetTexture("_BottomTex", cameraRig.renderTextures[3]);

        sphereRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
        sphereRenderer.receiveShadows       = false;
        sphereRenderer.lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
        sphereRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;

        sphere.hideFlags = HideFlags.HideAndDontSave;

        sphereTransform.transform.Translate(0f, 0f, 1f);
        sphereTransform.transform.Rotate(-90f, 0f, 0f);
    }
    // Start is called before the first frame update
    void Start()
    {
        // Add icosphere
        geometryGenerator = this.gameObject.AddComponent <IcoSphereGenerator>();
        // Add sinewave
        soundGenerator = this.gameObject.AddComponent <SineWaveExample>();

        // Start sinewave coroutine
        sineWaveCoroutine = coroutineSineWave();
        StartCoroutine(sineWaveCoroutine);
    }
Example #4
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        IcoSphereGenerator generator = (IcoSphereGenerator)target;

        if (GUILayout.Button("Build Object"))
        {
            generator.GenerateMesh();
        }
    }
Example #5
0
        private Vector3[] GetVertices()
        {
            var sphereGen = new IcoSphereGenerator()
                            .SetCenter(Center)
                            .SetRadius(Radius)
                            .SetRecursionLevel(2)
                            .SetGradient(GradientUtils.ParseGradient("gradient(#808080, #606060 50%, #505050)"));

            var meshData = new MeshData(DummyMeshIndex.Default, sphereGen.CalculateVertexCount());

            sphereGen.Build(meshData);

            return(meshData.Vertices);
        }
    void Start()
    {
        if (isCylinder)
        {
            CylinderGenerator.Create(gameObject, true, 64);
        }
        else
        {
            IcoSphereGenerator.Create(gameObject, true, 5);
        }

        meshRenderer = gameObject.AddComponent <MeshRenderer>();
        if (isCylinder)
        {
            meshRenderer.material.shader = cylinderShader;
            meshRenderer.material.EnableKeyword("FROM_SPHERICAL");
            meshRenderer.material.SetFloat("_Fade", 1f);
            meshRenderer.material.SetFloat("_ShiftU", shiftU);
            meshRenderer.material.SetFloat("_ScaleV", scaleCylinderV);
        }
        else
        {
            meshRenderer.material.shader = sphereShader;
            meshRenderer.material.SetFloat("_Fade", 1f);
            meshRenderer.material.SetFloat("_ShiftU", shiftU);
        }

        infoBlock = new GameObject(name + " Info");
        infoBlock.transform.SetParent(transform);
        infoBlock.transform.localPosition = new Vector3(0f, -0.5f, 0.5f);
        infoBlock.transform.localRotation = Quaternion.Euler(45f, 0f, 0f);

        var infoText = infoBlock.AddComponent <TextMesh>();

        infoText.text          = "Record: Not yet loaded\nImage: N/A";
        infoText.anchor        = TextAnchor.MiddleCenter;
        infoText.fontSize      = 40;
        infoText.characterSize = 0.005f;

        OnValidate();

        if (Application.sandboxType != ApplicationSandboxType.NotSandboxed)
        {
            archive.jsonPath = Application.streamingAssetsPath;
        }
        archive.Load();
        ChangeRecord(-1);
    }
        /// <inheritdoc />
        public override IGameObject BuildArea(Tile tile, Rule rule, Area area)
        {
            base.BuildArea(tile, rule, area);

            if (tile.Registry.Contains(area.Id))
            {
                return(null);
            }
            tile.Registry.RegisterGlobal(area.Id);

            double   radius;
            Vector2d center;

            CircleUtils.GetCircle(tile.RelativeNullPoint, area.Points, out radius, out center);

            var elevation = ElevationProvider.GetElevation(center);
            var minHeight = rule.GetMinHeight();
            var color     = rule.GetFillColor();
            var gradient  = CustomizationService.GetGradient(color);

            int recursionLevel = rule.EvaluateDefault("recursion_level", 2);

            var center3d = new Vector3((float)center.X, elevation + minHeight, (float)center.Y);

            var sphereGen = new IcoSphereGenerator()
                            .SetCenter(center3d)
                            .SetRadius((float)radius)
                            .SetRecursionLevel(recursionLevel)
                            .SetGradient(gradient);

            var meshData = new MeshData(new SphereMeshIndex((float)radius, center3d),
                                        sphereGen.CalculateVertexCount());

            meshData.GameObject  = GameObjectFactory.CreateNew(GetName(area));
            meshData.MaterialKey = rule.GetMaterialKey();

            sphereGen.Build(meshData);

            BuildObject(tile.GameObject, meshData, rule, area);

            return(meshData.GameObject);
        }
Example #8
0
    // Use this for initialization
    void Start()
    {
        if (subdivisions < 1)
        {
            subdivisions = 1;
        }
        if (subdivisions > 6)
        {
            subdivisions = 6;
        }
        IcoSphereGenerator.Create(gameObject, insideOut, subdivisions);
        var sphereRenderer = gameObject.AddComponent <MeshRenderer>();

        if (material != null)
        {
            sphereRenderer.sharedMaterial = material;
        }
        else
        {
            sphereRenderer.material.shader = Shader.Find("EMPlus/LongLatShader");
            sphereRenderer.material.SetColor("_Color", color);
            sphereRenderer.material.SetFloat("_LineWidth", lineWidth);
        }
    }
        /// <inheritdoc />
        public override List <MeshData> Build(Building building)
        {
            Vector2d center;
            double   radius;

            CircleUtils.GetCircle(building.Footprint, out radius, out center);

            var center3d = new Vector3((float)center.X,
                                       building.Elevation + building.MinHeight + building.Height,
                                       (float)center.Y);

            var sphereGen = new IcoSphereGenerator()
                            .SetCenter(center3d)
                            .SetRadius((float)radius)
                            .SetRecursionLevel(2)
                            .IsSemiphere(true)
                            .SetGradient(CustomizationService.GetGradient(building.RoofColor));

            var mesh = CreateMesh(building.Footprint);

            var        floorCount       = building.Levels;
            var        floorVertexCount = mesh.Triangles.Count * 3 * 2 * floorCount;
            IMeshIndex floorMeshIndex   = new MultiPlaneMeshIndex(building.Levels, floorVertexCount);

            var roofVertexCount = sphereGen.CalculateVertexCount();

            var vertexCount = roofVertexCount + floorVertexCount;

            bool limitIsReached = false;

            if (vertexCount * 2 > Consts.MaxMeshSize)
            {
                vertexCount    = roofVertexCount;
                limitIsReached = true;
                floorMeshIndex = DummyMeshIndex.Default;
            }

            var meshIndex = new CompositeMeshIndex(2)
                            .AddMeshIndex(new SphereMeshIndex((float)radius, center3d))
                            .AddMeshIndex(floorMeshIndex);
            var meshData = new MeshData(meshIndex, vertexCount);

            // attach roof
            sphereGen.Build(meshData);

            if (!limitIsReached)
            {
                // attach floors
                AttachFloors(new RoofContext()
                {
                    Mesh      = mesh,
                    MeshData  = meshData,
                    MeshIndex = (MultiPlaneMeshIndex)floorMeshIndex,

                    Bottom             = building.Elevation + building.MinHeight,
                    FloorCount         = floorCount,
                    FloorHeight        = building.Height / floorCount,
                    FloorFrontGradient = CustomizationService.GetGradient(building.FloorFrontColor),
                    FloorBackGradient  = CustomizationService.GetGradient(building.FloorBackColor),

                    IsLastRoof = false
                });

                return(new List <MeshData>(1)
                {
                    meshData
                });
            }

            var meshDataList = BuildFloors(building, building.Levels, false);

            meshDataList.Add(meshData);
            return(meshDataList);
        }