Beispiel #1
0
        private DivinityModelFlag DetermineSkeletonModelFlagsFromModels(Root root, Skeleton skeleton, DivinityModelFlag modelFlagOverrides)
        {
            DivinityModelFlag accumulatedFlags = 0;

            if (root.Meshes != null)
            {
                foreach (var model in root.Models)
                {
                    if (model.Skeleton == skeleton)
                    {
                        if (model.MeshBindings != null)
                        {
                            foreach (var meshBinding in model.MeshBindings)
                            {
                                var mesh = meshBinding.Mesh;
                                if (mesh.HasDefiniteModelType)
                                {
                                    accumulatedFlags |= mesh.ModelType;
                                }
                                else
                                {
                                    accumulatedFlags |= modelFlagOverrides;
                                }
                            }
                        }
                    }
                }
            }

            return(accumulatedFlags);
        }
        public static DivinityModelFlag UserDefinedPropertiesToModelType(string userDefinedProperties)
        {
            // The D:OS 2 editor uses the ExtendedData attribute to determine whether a model can be
            // bound to a character.
            // The "Rigid = true" user defined property is checked for rigid bodies (e.g. weapons), the "Cloth=true"
            // user defined property is checked for clothes.
            DivinityModelFlag flags = 0;

            if (userDefinedProperties.Contains("Rigid"))
            {
                flags |= DivinityModelFlag.Rigid;
            }

            if (userDefinedProperties.Contains("Cloth"))
            {
                flags |= DivinityModelFlag.Cloth;
            }

            if (userDefinedProperties.Contains("MeshProxy"))
            {
                flags |= DivinityModelFlag.MeshProxy | DivinityModelFlag.HasProxyGeometry;
            }

            return(flags);
        }
Beispiel #3
0
        private void UpdateInputState()
        {
            bool skinned        = _root.Skeletons != null && _root.Skeletons.Count > 0;
            bool animationsOnly = !skinned && (_root.Models == null || _root.Models.Count == 0) && _root.Animations != null && _root.Animations.Count > 0;

            if (skinned)
            {
                conformToOriginal.Enabled  = true;
                conformToOriginal.Text     = "Conform to original GR2:";
                buildDummySkeleton.Enabled = false;
                buildDummySkeleton.Checked = false;
            }
            else if (animationsOnly)
            {
                conformToOriginal.Enabled  = true;
                conformToOriginal.Text     = "Copy skeleton from:";
                buildDummySkeleton.Enabled = false;
                buildDummySkeleton.Checked = false;
            }
            else
            {
                conformToOriginal.Enabled    = false;
                conformToOriginal.Checked    = false;
                conformCopySkeletons.Enabled = false;
                buildDummySkeleton.Enabled   = true;
                buildDummySkeleton.Checked   = true;
            }

            bool hasUndeterminedModelTypes          = false;
            DivinityModelFlag accumulatedModelFlags = 0;

            if (_root.Meshes != null)
            {
                foreach (var mesh in _root.Meshes)
                {
                    if (!mesh.HasDefiniteModelType)
                    {
                        hasUndeterminedModelTypes = true;
                    }

                    accumulatedModelFlags |= mesh.ModelType;
                }
            }

            // If the type of all models are known, either via LSMv1 ExtendedData
            // or via Collada <extra> properties, there is nothing to override.
            meshRigid.Enabled = hasUndeterminedModelTypes;
            meshCloth.Enabled = hasUndeterminedModelTypes;
            meshProxy.Enabled = hasUndeterminedModelTypes;

            meshRigid.Checked = accumulatedModelFlags.IsRigid();
            meshCloth.Checked = accumulatedModelFlags.IsCloth();
            meshProxy.Checked = accumulatedModelFlags.IsMeshProxy();

            UpdateExportableObjects();
            UpdateResourceFormats();

            saveOutputBtn.Enabled = true;
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private void UpdateUserDefinedProperties(Root root)
        {
            if (Options.ModelInfoFormat == DivinityModelInfoFormat.None)
            {
                return;
            }

            var modelFlagOverrides = Options.ModelType;

            if (root.Meshes != null)
            {
                foreach (var mesh in root.Meshes)
                {
                    DivinityModelFlag modelFlags = modelFlagOverrides;
                    if (mesh.HasDefiniteModelType)
                    {
                        modelFlags = mesh.ModelType;
                    }

                    var userDefinedProperties = DivinityHelpers.ModelFlagsToUserDefinedProperties(modelFlags);
                    mesh.ExtendedData = DivinityHelpers.MakeMeshExtendedData(mesh, Options.ModelInfoFormat, Options.ModelType);
                }
            }

            if (root.Skeletons != null)
            {
                foreach (var skeleton in root.Skeletons)
                {
                    if (skeleton.Bones != null)
                    {
                        if (Options.ModelInfoFormat == DivinityModelInfoFormat.None || Options.ModelInfoFormat == DivinityModelInfoFormat.LSMv3)
                        {
                            foreach (var bone in skeleton.Bones)
                            {
                                bone.ExtendedData = null;
                            }
                        }
                        else
                        {
                            var accumulatedFlags = DetermineSkeletonModelFlagsFromModels(root, skeleton, modelFlagOverrides);

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

                                var userDefinedProperties = DivinityHelpers.ModelFlagsToUserDefinedProperties(accumulatedFlags);
                                bone.ExtendedData.UserDefinedProperties = userDefinedProperties;
                                bone.ExtendedData.IsRigid = (accumulatedFlags.IsRigid()) ? 1 : 0;
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public void PostLoad()
        {
            if (PrimaryVertexData.Vertices.Count > 0)
            {
                VertexFormat = PrimaryVertexData.Vertices[0].Format;
            }

            if (HasDefiniteModelType == false)
            {
                ModelType = DivinityHelpers.DetermineModelFlags(this, out HasDefiniteModelType);
            }
        }
Beispiel #7
0
        public static DivinityModelType UserMeshFlagsToModelType(DivinityModelFlag flags)
        {
            if ((flags & DivinityModelFlag.Rigid) == DivinityModelFlag.Rigid)
            {
                return(DivinityModelType.Rigid);
            }

            if ((flags & DivinityModelFlag.MeshProxy) == DivinityModelFlag.MeshProxy)
            {
                return(DivinityModelType.MeshProxy);
            }

            if ((flags & DivinityModelFlag.Cloth) == DivinityModelFlag.Cloth)
            {
                return(DivinityModelType.Cloth);
            }

            return(DivinityModelType.Normal);
        }
        public static string ModelFlagsToUserDefinedProperties(DivinityModelFlag modelFlags)
        {
            List <string> properties = new List <string>();

            if (modelFlags.IsRigid())
            {
                properties.Add(UserDefinedProperties_Rigid);
            }

            if (modelFlags.IsCloth())
            {
                properties.Add(UserDefinedProperties_Cloth);
            }

            if (modelFlags.IsMeshProxy())
            {
                properties.Add(UserDefinedProperties_MeshProxy);
            }

            return(String.Join("\n", properties));
        }
        public static DivinityModelFlag DetermineModelFlags(Mesh mesh, out bool hasDefiniteModelType)
        {
            DivinityModelFlag flags = 0;

            if (mesh.HasDefiniteModelType)
            {
                flags = mesh.ModelType;
                hasDefiniteModelType = true;
            }
            else if (mesh.ExtendedData != null &&
                     mesh.ExtendedData.LSMVersion >= 1 &&
                     mesh.ExtendedData.UserMeshProperties != null)
            {
                flags = mesh.ExtendedData.UserMeshProperties.MeshFlags;
                hasDefiniteModelType = true;
            }
            else if (mesh.ExtendedData != null &&
                     mesh.ExtendedData.UserDefinedProperties != null)
            {
                flags = UserDefinedPropertiesToModelType(mesh.ExtendedData.UserDefinedProperties);
                hasDefiniteModelType = true;
            }
            else
            {
                // Only mark model as cloth if it has colored vertices
                if (mesh.VertexFormat.ColorMaps > 0)
                {
                    flags |= DivinityModelFlag.Cloth;
                }

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

                hasDefiniteModelType = false;
            }

            return(flags);
        }
Beispiel #10
0
        private DivinityModelFlag FindDivModelType(mesh mesh)
        {
            DivinityModelFlag flags = 0;

            var technique = FindExporterExtraData(mesh.extra);

            if (technique != null)
            {
                if (technique.Any != null)
                {
                    foreach (var setting in technique.Any)
                    {
                        if (setting.LocalName == "DivModelType")
                        {
                            switch (setting.InnerText.Trim())
                            {
                            // Compatibility flag, not used anymore
                            case "Normal": break;

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

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

                            case "MeshProxy": flags |= DivinityModelFlag.MeshProxy | DivinityModelFlag.HasProxyGeometry; break;

                            default:
                                Utils.Warn($"Unrecognized model type in <DivModelType> tag: {setting.Value}");
                                break;
                            }
                        }
                    }
                }
            }

            return(flags);
        }
 public static bool IsRigid(this DivinityModelFlag flag)
 {
     return((flag & DivinityModelFlag.Rigid) == DivinityModelFlag.Rigid);
 }
 public static bool IsCloth(this DivinityModelFlag flag)
 {
     return((flag & DivinityModelFlag.Cloth) == DivinityModelFlag.Cloth);
 }
 public static bool IsMeshProxy(this DivinityModelFlag flag)
 {
     return((flag & DivinityModelFlag.MeshProxy) == DivinityModelFlag.MeshProxy);
 }
Beispiel #14
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);
        }