コード例 #1
0
    public void GenerateAndApplyMesh()
    {
        Mesh mesh = terrainGenerator.GenerateMesh();

        meshFilter.mesh = mesh;

        float[,] heightmap = terrainGenerator.heightmapGenerator.GenerateNoisemap();
        Texture2D heightmapTexture = Texture2DUtility.FromNoisemap(heightmap);
        Texture2D normalmapTexture = Normalmap.getNormalMap(heightmapTexture, 2);

        meshRenderer.sharedMaterial.EnableKeyword("_NORMALMAP");
        meshRenderer.sharedMaterial.EnableKeyword("_PARALLAXMAP");

        meshRenderer.sharedMaterial.SetTexture("_BumpMap", normalmapTexture);
        meshRenderer.sharedMaterial.SetTexture("_ParallaxMap", heightmapTexture);
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        bool changed = DrawDefaultInspector();

        autoUpdate = EditorGUILayout.Toggle("Auto Update", autoUpdate);
        if ((changed && autoUpdate) || GUILayout.Button("Generate"))
        {
            NoisemapGenerator generator = (NoisemapGenerator)target;
            float[,] heightmap = generator.GenerateNoisemap();
            texture            = Texture2DUtility.FromNoisemap(heightmap);
        }

        if (texture != null && GUILayout.Button("Save as png"))
        {
            File.WriteAllBytes("Assets/texture.png", texture.EncodeToPNG());
        }

        if (texture != null)
        {
            GUILayout.Box(texture);
        }
    }