Beispiel #1
0
        /// <summary>Validates if the materials are correct on this <see cref="RealtimeCSG.Legacy.Shape"/>, and fixes them if they are not.</summary>
        /// <returns>*true* if the shape has been modified, *false* if nothing changed</returns>
        public bool CheckMaterials()
        {
            bool dirty = false;

            if (Surfaces == null ||
                Surfaces.Length == 0)
            {
                Debug.LogWarning("Surfaces == null || Surfaces.Length == 0");
                return(true);
            }

            int maxTexGenIndex = 0;

            for (int i = 0; i < Surfaces.Length; i++)
            {
                maxTexGenIndex = Mathf.Max(maxTexGenIndex, Surfaces[i].TexGenIndex);
            }
            maxTexGenIndex++;

            if (TexGens == null ||
                TexGens.Length < maxTexGenIndex)
            {
                dirty = true;
                var newTexGens     = new TexGen[maxTexGenIndex];
                var newTexGenFlags = new TexGenFlags[maxTexGenIndex];
                if (TexGens != null &&
                    TexGens.Length > 0)
                {
                    for (int i = 0; i < TexGens.Length; i++)
                    {
                        newTexGens[i]     = TexGens[i];
                        newTexGenFlags[i] = TexGenFlags[i];
                    }/*
                      * for (int i = TexGens.Length; i < newTexGens.Length; i++)
                      * {
                      * newTexGens[i].Color = Color.white;
                      * }*/
                }
                TexGens     = newTexGens;
                TexGenFlags = newTexGenFlags;
            }

            /*
             * for (int i = 0; i < TexGens.Length; i++)
             * {
             *  if (TexGens[i].Color == Color.clear)
             *      TexGens[i].Color = Color.white;
             * }*/

            return(dirty);
        }
Beispiel #2
0
        /// <summary>Converts a <see cref="RealtimeCSG.Legacy.Surface"/>/<see cref="RealtimeCSG.Legacy.TexGen"/>/<see cref="RealtimeCSG.Legacy.TexGenFlags"/> combination into a <see cref="RealtimeCSG.Foundation.SurfaceDescription"/>.</summary>
        /// <param name="surface">A legacy <see cref="RealtimeCSG.Legacy.Surface"/> that describes how the texture space is orientated relative to the brush.</param>
        /// <param name="texGen">A legacy <see cref="RealtimeCSG.Legacy.TexGen"/> that describes how the texture coordinates are calculated in the <see cref="RealtimeCSG.Foundation.SurfaceDescription"/>.</param>
        /// <param name="texGenFlags">A legacy <see cref="RealtimeCSG.Legacy.TexGenFlags"/> enum that describes if the <see cref="RealtimeCSG.Foundation.SurfaceDescription"/> texture generation will be in world-space or brush-space.</param>
        /// <returns>A new <see cref="RealtimeCSG.Foundation.SurfaceDescription"/></returns>
        public static SurfaceDescription CreateSurfaceDescription(Surface surface, TexGen texGen, TexGenFlags texGenFlags)
        {
            var localToTextureSpace = SurfaceUtility.GetLocalToTextureSpaceMatrix(texGen, surface);

            SurfaceDescription description;

            description.smoothingGroup = texGen.SmoothingGroup;
            description.surfaceFlags   = ((texGenFlags & TexGenFlags.WorldSpaceTexture) == 0) ? SurfaceFlags.None : SurfaceFlags.TextureIsInWorldSpace;

            description.UV0.U = localToTextureSpace.GetRow(0);
            description.UV0.V = localToTextureSpace.GetRow(1);

            return(description);
        }
Beispiel #3
0
        /// <summary>Converts a <see cref="RealtimeCSG.Legacy.TexGen"/>/<see cref="RealtimeCSG.Legacy.TexGenFlags"/> pair into a <see cref="RealtimeCSG.Foundation.SurfaceLayers"/>.</summary>
        /// <param name="texGen">A legacy <see cref="RealtimeCSG.Legacy.TexGen"/> that describes what layer parameters will be used for this surface.</param>
        /// <param name="texGenFlags">A legacy <see cref="RealtimeCSG.Legacy.TexGenFlags"/> that describes what layers will be used for this surface</param>
        /// <returns>A new <see cref="RealtimeCSG.Foundation.SurfaceLayers"/></returns>
        public static SurfaceLayers CreateSurfaceLayer(TexGen texGen, TexGenFlags texGenFlags)
        {
            SurfaceLayers layers;

            var renderable     = !((texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender);
            var receiveShadows = !((texGenFlags & TexGenFlags.NoReceiveShadows) == TexGenFlags.NoReceiveShadows);
            var castShadows    = !((texGenFlags & TexGenFlags.NoCastShadows) == TexGenFlags.NoCastShadows);
            var collidable     = !((texGenFlags & TexGenFlags.NoCollision) == TexGenFlags.NoCollision);

            layers.layerUsage = (renderable     ? LayerUsageFlags.Renderable     : LayerUsageFlags.None) |
                                (receiveShadows ? LayerUsageFlags.ReceiveShadows : LayerUsageFlags.None) |
                                (castShadows    ? LayerUsageFlags.CastShadows    : LayerUsageFlags.None) |
                                (collidable     ? LayerUsageFlags.Collidable     : LayerUsageFlags.None);

            layers.layerParameter1 = (texGen.RenderMaterial) ? texGen.RenderMaterial.GetInstanceID()  : 0;
            layers.layerParameter2 = (texGen.PhysicsMaterial) ? texGen.PhysicsMaterial.GetInstanceID() : 0;
            layers.layerParameter3 = 0;

            return(layers);
        }