Ejemplo n.º 1
0
        public VoxelVertexOutput ResolveVoxelVertex(VoxelVertexInput input, VoxelModelGenerationSettings settings)
        {
            float[]            channels  = ReadAllChannels(input.Coord);
            VoxelMaterialBasic material  = new VoxelMaterialBasic();
            List <Vector4>     customUVs = new List <Vector4>();

            int c = 0;

            foreach (var layout in m_Settings.TextureLayout)
            {
                switch (layout)
                {
                case CommonVoxelImportSettings.TextureLayoutFormat.Tint:
                    material.Tint = new Vector4(
                        channels[c + 0],
                        channels[c + 1],
                        channels[c + 2],
                        channels[c + 3]
                        );
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Albedo:
                    material.Colour.r = channels[c + 0];
                    material.Colour.g = channels[c + 1];
                    material.Colour.b = channels[c + 2];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Alpha:
                    material.Colour.a = channels[c];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.CustomUV2:
                    customUVs.Add(new Vector4(channels[c + 0], channels[c + 1], 0, 0));
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.CustomUV4:
                    customUVs.Add(new Vector4(channels[c + 0], channels[c + 1], channels[c + 2], channels[c + 3]));
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Specular:
                    material.Specular = channels[c];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Roughness:
                    material.Roughness = channels[c];
                    break;
                }

                int channelSize = CommonVoxelImportSettings.GetChannelCount(layout);
                c += channelSize;
            }

            material.CustomUVs = customUVs.ToArray();

            VoxelVertexOutput output = new VoxelVertexOutput();

            output.SetDefaults(input, settings);

            material.ApplyToVertex(input, ref output);
            return(output);
        }
Ejemplo n.º 2
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);
        }