Ejemplo n.º 1
0
    public void SetSurfaceMultiMesh(SGT_SurfaceMultiMesh newSurfaceMultiMesh)
    {
        if (newSurfaceMultiMesh != null)
        {
            if (surfaceMesh == null)
            {
                surfaceMesh = new SGT_SurfaceMultiMesh();
            }

            newSurfaceMultiMesh.CopyMeshesInto(surfaceMesh);
        }
    }
Ejemplo n.º 2
0
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            if (displacementTexture != null && sourceSurfaceMesh != null)
            {
                if (generatedSurfaceMesh == null)
                {
                    generatedSurfaceMesh = new SGT_SurfaceMultiMesh();
                }

                // Destroy old meshes
                generatedSurfaceMesh.DestroyAllMeshes();

                sourceSurfaceMesh.CopyMeshesInto(generatedSurfaceMesh);

                var surfaceCount = generatedSurfaceMesh.Count;

                for (var i = 0; i < surfaceCount; i++)
                {
                    var multiMesh = generatedSurfaceMesh.GetMultiMesh(i);

                    if (multiMesh != null)
                    {
                        for (var j = 0; j < multiMesh.Count; j++)
                        {
                            var mesh = multiMesh.GetSharedMesh(j);

                            if (mesh != null)
                            {
                                mesh           = SGT_Helper.CloneObject(mesh);
                                mesh.hideFlags = HideFlags.DontSave;

                                var positions      = mesh.vertices;
                                var uv0s           = mesh.uv;
                                var newPositions   = new Vector3[positions.Length];
                                var displacementUV = Vector2.zero;

                                for (var k = 0; k < positions.Length; k++)
                                {
                                    var texture  = (Texture2D)null;
                                    var position = positions[k];

                                    switch (displacementTexture.Configuration)
                                    {
                                    case SGT_SurfaceConfiguration.Sphere:
                                    {
                                        texture = displacementTexture.GetTexture2D(0);

                                        if (texture != null)
                                        {
                                            displacementUV = useUV == true ? uv0s[k] : SGT_Helper.CartesianToPolarUV(position);

                                            if (clamp == true)
                                            {
                                                displacementUV = SGT_Helper.ClampCollapseV(displacementUV, SGT_Helper.PixelUV(texture));
                                            }
                                        }
                                    }
                                    break;

                                    case SGT_SurfaceConfiguration.Cube:
                                    {
                                        texture = displacementTexture.GetTexture2D(position);

                                        if (texture != null)
                                        {
                                            displacementUV = useUV == true ? uv0s[k] : SGT_Helper.CubeUV(position, true);

                                            if (clamp == true)
                                            {
                                                displacementUV = SGT_Helper.ClampUV(displacementUV, SGT_Helper.PixelUV(texture));
                                            }
                                        }
                                    }
                                    break;
                                    }

                                    var displacement = texture != null?texture.GetPixelBilinear(displacementUV.x, displacementUV.y).r : 0.0f;

                                    newPositions[k] = position * Mathf.Lerp(scaleMin, scaleMax, displacement);
                                }

                                mesh.name    += "(Displaced)";
                                mesh.vertices = newPositions;
                                mesh.bounds   = new Bounds(mesh.bounds.center, mesh.bounds.size * scaleMax);
                                mesh.RecalculateNormals();

                                multiMesh.SetSharedMesh(mesh, j);
                            }
                        }
                    }
                }

                MarkAsUnmodified();

                SendMessage("SetSurfaceMultiMesh", generatedSurfaceMesh, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Ejemplo n.º 3
0
	public void SetSurfaceMultiMesh(SGT_SurfaceMultiMesh newSurfaceMultiMesh)
	{
		if (newSurfaceMultiMesh != null)
		{
			if (surfaceMultiMesh == null) surfaceMultiMesh = new SGT_SurfaceMultiMesh();
			
			newSurfaceMultiMesh.CopyMeshesInto(surfaceMultiMesh);
		}
	}