Esempio n. 1
0
        public static DivinityMeshExtendedData MakeMeshExtendedData(Mesh mesh, DivinityModelInfoFormat format,
                                                                    DivinityModelFlag modelFlagOverrides)
        {
            var extendedData             = DivinityMeshExtendedData.Make();
            DivinityModelFlag modelFlags = modelFlagOverrides;

            if (mesh.HasDefiniteModelType)
            {
                modelFlags = mesh.ModelType;
            }

            if (mesh.VertexFormat.HasBoneWeights)
            {
                modelFlags |= DivinityModelFlag.Skinned;
            }

            if (mesh.VertexFormat.ColorMaps > 0)
            {
                modelFlags |= DivinityModelFlag.HasColor;
            }
            else
            {
                modelFlags &= ~DivinityModelFlag.Cloth;
            }

            extendedData.UserDefinedProperties =
                DivinityHelpers.ModelFlagsToUserDefinedProperties(modelFlags);

            if (format == DivinityModelInfoFormat.UserDefinedProperties)
            {
                extendedData.LSMVersion         = 0;
                extendedData.UserMeshProperties = null;
            }
            else
            {
                extendedData.UserMeshProperties.MeshFlags = modelFlags;

                if (format == DivinityModelInfoFormat.LSMv3)
                {
                    extendedData.LSMVersion = 3;
                    extendedData.UserMeshProperties.FormatDescs = DivinityFormatDesc.FromVertexFormat(mesh.VertexFormat);
                    extendedData.UserMeshProperties.LodDistance = new float[] { 3.40282347E+38f };
                    extendedData.UserMeshProperties.IsImpostor  = new Int32[] { 0 };
                }
                else if (format == DivinityModelInfoFormat.LSMv1)
                {
                    extendedData.LSMVersion = 1;
                    extendedData.UserMeshProperties.FormatDescs = DivinityFormatDesc.FromVertexFormat(mesh.VertexFormat);
                }
                else
                {
                    extendedData.LSMVersion = 0;
                    extendedData.UserMeshProperties.FormatDescs = new List <DivinityFormatDesc>();
                }
            }

            return(extendedData);
        }
Esempio n. 2
0
        private void UpdateUserDefinedProperties(Root root)
        {
            var modelType = Options.ModelType;

            if (modelType == DivinityModelType.Undefined)
            {
                modelType = DivinityHelpers.DetermineModelType(root);
            }

            var userDefinedProperties = DivinityHelpers.ModelTypeToUserDefinedProperties(modelType);

            if (root.Meshes != null)
            {
                foreach (var mesh in root.Meshes)
                {
                    if (mesh.ExtendedData == null)
                    {
                        mesh.ExtendedData = DivinityMeshExtendedData.Make();
                    }

                    // Only mark model as cloth if it has colored vertices
                    var meshModelType = modelType;
                    if (mesh.VertexFormat.DiffuseColors == 0 &&
                        meshModelType == DivinityModelType.Cloth)
                    {
                        meshModelType = DivinityModelType.Normal;
                    }

                    mesh.ExtendedData.UserDefinedProperties =
                        DivinityHelpers.ModelTypeToUserDefinedProperties(meshModelType);

                    // TODO - LSM info not supported yet
                    mesh.ExtendedData.LSMVersion = 0;
                    mesh.ExtendedData.UserMeshProperties.Flags[0] |= 0x18;
                    switch (meshModelType)
                    {
                    case DivinityModelType.Cloth:
                        mesh.ExtendedData.UserMeshProperties.Flags[0] |= 0x02;
                        break;

                    case DivinityModelType.Rigid:
                        mesh.ExtendedData.UserMeshProperties.Flags[0] |= 0x20;
                        break;
                    }
                }
            }

            if (root.Skeletons != null)
            {
                foreach (var skeleton in root.Skeletons)
                {
                    if (skeleton.Bones != null)
                    {
                        foreach (var bone in skeleton.Bones)
                        {
                            if (bone.ExtendedData == null)
                            {
                                bone.ExtendedData = new DivinityBoneExtendedData();
                            }

                            bone.ExtendedData.UserDefinedProperties = userDefinedProperties;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static DivinityMeshExtendedData MakeMeshExtendedData(Mesh mesh, DivinityModelInfoFormat format,
                                                                    DivinityModelType meshModelType)
        {
            var extendedData = DivinityMeshExtendedData.Make();

            if (mesh.ModelType != DivinityModelType.Undefined)
            {
                meshModelType = mesh.ModelType;
            }

            if (meshModelType == DivinityModelType.Cloth &&
                mesh.VertexFormat.ColorMaps == 0)
            {
                meshModelType = DivinityModelType.Normal;
            }

            if (meshModelType == DivinityModelType.Undefined)
            {
                meshModelType = DivinityHelpers.DetermineModelType(mesh);
            }

            extendedData.UserDefinedProperties =
                DivinityHelpers.ModelTypeToUserDefinedProperties(meshModelType);

            if (format == DivinityModelInfoFormat.UserDefinedProperties)
            {
                extendedData.LSMVersion         = 0;
                extendedData.UserMeshProperties = null;
            }
            else
            {
                DivinityModelFlag flags = 0;

                if (mesh.VertexFormat.HasBoneWeights)
                {
                    flags |= DivinityModelFlag.Skinned;
                }

                if (mesh.VertexFormat.ColorMaps > 0)
                {
                    flags |= DivinityModelFlag.HasColor;
                }

                switch (meshModelType)
                {
                case DivinityModelType.Normal:
                    // No special flag should be set here
                    break;

                case DivinityModelType.Cloth:
                    flags |= DivinityModelFlag.Cloth;
                    break;

                case DivinityModelType.Rigid:
                    flags |= DivinityModelFlag.Rigid;
                    break;

                case DivinityModelType.MeshProxy:
                    flags |= DivinityModelFlag.MeshProxy;
                    break;

                default:
                    throw new NotImplementedException();
                }

                extendedData.UserMeshProperties.MeshFlags = flags;

                if (format == DivinityModelInfoFormat.LSMv1)
                {
                    extendedData.LSMVersion = 1;
                    extendedData.UserMeshProperties.FormatDescs = DivinityFormatDesc.FromVertexFormat(mesh.VertexFormat);
                }
                else
                {
                    extendedData.LSMVersion = 0;
                    extendedData.UserMeshProperties.FormatDescs = new List <DivinityFormatDesc>();
                }
            }

            return(extendedData);
        }