示例#1
0
        private void SetBooleans(UniformBlock uniformBlock)
        {
            // Use a 16 byte type to avoid alignment issues.
            var customBooleans = new IVec4[20];

            customBooleans[1] = new IVec4 {
                X = 1
            };
            customBooleans[2] = new IVec4 {
                X = 0
            };
            customBooleans[3] = new IVec4 {
                X = 1
            };
            customBooleans[4] = new IVec4 {
                X = 1
            };
            customBooleans[5] = new IVec4 {
                X = 0
            };
            customBooleans[6] = new IVec4 {
                X = 0
            };
            customBooleans[9] = new IVec4 {
                X = 0
            };
            customBooleans[11] = new IVec4 {
                X = 1
            };

            foreach (var param in boolByParamId)
            {
                customBooleans[param.Key.ToBooleanIndex()] = new IVec4 {
                    X = param.Value ? 1 : 0
                };
            }
            uniformBlock.SetValues("CustomBoolean", customBooleans);
        }
示例#2
0
        private List <CustomVertex> CreateVertices(RSkeleton Skeleton, MeshObject meshObject, SSBHVertexAccessor vertexAccessor, uint[] vertexIndices)
        {
            // Read attribute values.
            var positions       = vertexAccessor.ReadAttribute("Position0", 0, meshObject.VertexCount, meshObject);
            var normals         = vertexAccessor.ReadAttribute("Normal0", 0, meshObject.VertexCount, meshObject);
            var tangents        = vertexAccessor.ReadAttribute("Tangent0", 0, meshObject.VertexCount, meshObject);
            var map1Values      = vertexAccessor.ReadAttribute("map1", 0, meshObject.VertexCount, meshObject);
            var bake1Values     = vertexAccessor.ReadAttribute("bake1", 0, meshObject.VertexCount, meshObject);
            var colorSet1Values = vertexAccessor.ReadAttribute("colorSet1", 0, meshObject.VertexCount, meshObject);
            var colorSet5Values = vertexAccessor.ReadAttribute("colorSet5", 0, meshObject.VertexCount, meshObject);


            Vector3[] generatedBitangents = GenerateBitangents(vertexIndices, positions, map1Values);

            var boneIndices = new IVec4[positions.Length];
            var boneWeights = new Vector4[positions.Length];

            var riggingAccessor = new SSBHRiggingAccessor(mesh);

            SSBHVertexInfluence[]    influences      = riggingAccessor.ReadRiggingBuffer(meshObject.Name, (int)meshObject.SubMeshIndex);
            Dictionary <string, int> indexByBoneName = new Dictionary <string, int>();

            if (Skeleton != null)
            {
                for (int i = 0; i < Skeleton.Bones.Count; i++)
                {
                    indexByBoneName.Add(Skeleton.Bones[i].Name, i);
                }
            }

            foreach (SSBHVertexInfluence influence in influences)
            {
                // Some influences refer to bones that don't exist in the skeleton.
                // _eff bones?
                if (!indexByBoneName.ContainsKey(influence.BoneName))
                {
                    continue;
                }

                if (boneWeights[influence.VertexIndex].X == 0)
                {
                    boneIndices[influence.VertexIndex].X = indexByBoneName[influence.BoneName];
                    boneWeights[influence.VertexIndex].X = influence.Weight;
                }
                else if (boneWeights[influence.VertexIndex].Y == 0)
                {
                    boneIndices[influence.VertexIndex].Y = indexByBoneName[influence.BoneName];
                    boneWeights[influence.VertexIndex].Y = influence.Weight;
                }
                else if (boneWeights[influence.VertexIndex].Z == 0)
                {
                    boneIndices[influence.VertexIndex].Z = indexByBoneName[influence.BoneName];
                    boneWeights[influence.VertexIndex].Z = influence.Weight;
                }
                else if (boneWeights[influence.VertexIndex].W == 0)
                {
                    boneIndices[influence.VertexIndex].W = indexByBoneName[influence.BoneName];
                    boneWeights[influence.VertexIndex].W = influence.Weight;
                }
            }

            var vertices = new List <CustomVertex>();

            for (int i = 0; i < positions.Length; i++)
            {
                var position = GetVector4(positions[i]).Xyz;

                var normal    = GetVector4(normals[i]).Xyz;
                var tangent   = GetVector4(tangents[i]).Xyz;
                var bitangent = GetBitangent(generatedBitangents, i, normal);

                var map1 = GetVector4(map1Values[i]).Xy;

                var bones   = boneIndices[i];
                var weights = boneWeights[i];

                // Accessors return length 0 when the attribute isn't present.
                var bake1 = new Vector2(0);
                if (bake1Values.Length != 0)
                {
                    bake1 = GetVector4(bake1Values[i]).Xy;
                }

                // The values are read as float, so we can't use OpenGL to convert.
                // Convert the range [0, 128] to [0, 255].
                var colorSet1 = new Vector4(1);
                if (colorSet1Values.Length != 0)
                {
                    colorSet1 = GetVector4(colorSet1Values[i]) / 128.0f;
                }

                var colorSet5 = new Vector4(1);
                if (colorSet5Values.Length != 0)
                {
                    colorSet5 = GetVector4(colorSet5Values[i]) / 128.0f;
                }

                vertices.Add(new CustomVertex(position, normal, tangent, bitangent, map1, bones, weights, bake1, colorSet1, colorSet5));
            }

            return(vertices);
        }
示例#3
0
 public bool Equals(IVec4 other)
 {
     return(X == other.X && Y == other.Y && Z == other.Z && W == other.W);
 }
示例#4
0
 public int NeighborsAt(IVec4 cell) => cell
 .MooreNeighborhood()
 .Count(n => ActiveCells.Contains(n));