Пример #1
0
        public bool BlendVoxelMaterial(IVoxelVolume volume, int x, int y, int z, VoxelMaterial material, float strength)
        {
            // TODO - May need to optimize this to prevent blends being created excessively
            VoxelMaterial baseMaterial    = GetVoxelMaterial(volume, x, y, z);
            VoxelMaterial blendedMaterial = VoxelMaterial.Lerp(baseMaterial, material, strength);

            return(volume.SetVoxelCell(x, y, z, VoxelMaterialToCell(blendedMaterial)));
        }
Пример #2
0
        public VoxelCell VoxelMaterialToCell(VoxelMaterial mat)
        {
            int index;

            if (!m_MaterialIndexLookup.TryGetValue(mat, out index))
            {
                index = m_MaterialTable.Count;
                m_MaterialTable.Add(mat);

                m_MaterialIndexLookup.Add(mat, index);
            }

            return(new VoxelCell(index + 1));
        }
Пример #3
0
        public static bool ShouldGenerateFaceBetween(VoxelMaterial a, VoxelMaterial b)
        {
            if (a != null && b != null)
            {
                return(a.Properties.IsOpaque != b.Properties.IsOpaque);
            }

            // One of or both are null if here, so assume one is empty
            else if (a != null || b != null)
            {
                return(true);
            }

            return(false);
        }
Пример #4
0
        public VoxelVertexOutput ResolveVoxelVertex(VoxelVertexInput input, VoxelModelGenerationSettings settings)
        {
            VoxelVertexOutput output = new VoxelVertexOutput();

            output.SetDefaults(input, settings);

            VoxelMaterial mat = VoxelCellToMaterial(input.Cell);

            Assert.Message(mat != null, "Invalid material referenced by cell");

            if (mat != null)
            {
                mat.Properties.ApplyToVertex(input, ref output);
            }

            return(output);
        }
Пример #5
0
        public static VoxelMaterial Lerp(VoxelMaterial a, VoxelMaterial b, float t)
        {
            VoxelMaterial output = new VoxelMaterial();

            output.Properties = VoxelMaterialBasic.Lerp(a.Properties, b.Properties, t);

            if (t <= 0.0f)
            {
                output.DressingLookup   = new SerializableDictionary <VoxelFace, int>(a.DressingLookup);
                output.DressingSettings = new List <WeightedCollection <GameObject> >(a.DressingSettings);
            }
            else if (t >= 1.0f)
            {
                output.DressingLookup   = new SerializableDictionary <VoxelFace, int>(b.DressingLookup);
                output.DressingSettings = new List <WeightedCollection <GameObject> >(b.DressingSettings);
            }
            else
            {
                output.DressingLookup   = new SerializableDictionary <VoxelFace, int>();
                output.DressingSettings = new List <WeightedCollection <GameObject> >();


                foreach (VoxelFace face in VoxelFaceHelpers.ToFaceCollection(VoxelFaces.All))
                {
                    if (!a.DressingLookup.TryGetValue(face, out int aIdx))
                    {
                        aIdx = -1;
                    }
                    if (!b.DressingLookup.TryGetValue(face, out int bIdx))
                    {
                        bIdx = -1;
                    }

                    WeightedCollection <GameObject> settings = null;

                    if (aIdx != -1 && bIdx != -1)
                    {
                        // Mix settings
                        settings = new WeightedCollection <GameObject>();
                        settings.Insert(t, a.DressingSettings[aIdx]);
                        settings.Insert(1.0f - t, b.DressingSettings[aIdx]);
                    }
                    else if (aIdx != -1)
                    {
                        settings = a.DressingSettings[aIdx];
                    }
                    else if (bIdx != -1)
                    {
                        settings = b.DressingSettings[bIdx];
                    }

                    if (settings != null)
                    {
                        int index = output.DressingSettings.Count;
                        output.DressingSettings.Add(settings);
                        output.DressingLookup.Add(face, index);
                    }
                }
            }

            return(output);
        }
Пример #6
0
 public bool BlendVoxelMaterial(IVoxelVolume volume, Vector3Int coord, VoxelMaterial material, float strength)
 {
     return(BlendVoxelMaterial(volume, coord.x, coord.y, coord.z, material, strength));
 }
Пример #7
0
 public bool SetVoxelMaterial(IVoxelVolume volume, Vector3Int coord, VoxelMaterial material)
 {
     return(volume.SetVoxelCell(coord, VoxelMaterialToCell(material)));
 }
Пример #8
0
 public bool SetVoxelMaterial(IVoxelVolume volume, int x, int y, int z, VoxelMaterial material)
 {
     return(volume.SetVoxelCell(x, y, z, VoxelMaterialToCell(material)));
 }
Пример #9
0
 public bool ShouldAddFace(Vector3Int fromCoord, VoxelCell fromCell, Vector3Int toCoord, VoxelCell toCell)
 {
     return(VoxelMaterial.ShouldGenerateFaceBetween(VoxelCellToMaterial(fromCell), VoxelCellToMaterial(toCell)));
 }