예제 #1
0
        public static string ManToEnglishChar(ManType manType)
        {
            switch (manType)
            {
            case ManType.Pawn:
                return("");

            case ManType.Knight:
                return("N");

            case ManType.Bishop:
                return("B");

            case ManType.Rook:
                return("R");

            case ManType.Queen:
                return("Q");

            case ManType.King:
                return("K");

            default:
                throw new ConverterException("Unknown man type: " + manType);
            }
        }
        protected Man ParseManTransformation(Player player, string moveString)
        {
            Match match = Regex.Match(moveString, PATTERN_MAN_TRANSFORMATION);

            if (match.Success)
            {
                ManType manType = ManTypeUtility.ManFromGermanChar(match.Groups[1].Value);
                return(new Man(player, manType));
            }

            return(null);
        }
 public static float GetHairScale(ManType manType)
 {
     switch (manType)
     {
         case ManType.Child:
             return 246f;
         case ManType.Male:
         case ManType.Female:
             return 246f;
     }
     return 246f;
 }
예제 #4
0
        public static float GetHeadScale(ManType manType)
        {
            switch (manType)
            {
            case ManType.Child:
                return(ScaleChild);

            case ManType.Male:
            case ManType.Female:
                return(ScaleMan);
            }
            return(1f);
        }
예제 #5
0
        public static float GetHairScale(ManType manType)
        {
            switch (manType)
            {
            case ManType.Child:
                return(246f);

            case ManType.Male:
            case ManType.Female:
                return(246f);
            }
            return(246f);
        }
예제 #6
0
        //private void UpdateFaceRect()
        //{
        //    var indicies = ProgramCore.Project.RenderMainHelper.headController.GetFaceIndexes();
        //    List<MirroredHeadPoint> faceDots;
        //    switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
        //    {
        //        // case Mode.HeadShapedots:
        //        case Mode.HeadLine:
        //        case Mode.HeadShapeFirstTime:
        //        case Mode.HeadShape:
        //            faceDots = ProgramCore.Project.RenderMainHelper.headController.GetSpecialShapedots(indicies);
        //            break;
        //        default:
        //            faceDots = ProgramCore.Project.RenderMainHelper.headController.GetSpecialAutodots(indicies);
        //            break;
        //    }

        //    if (faceDots.Count == 0)
        //        return;
        //    {
        //        var minX1 = faceDots.Min(point => point.ValueMirrored.X);
        //        var maxX1 = faceDots.Max(point => point.ValueMirrored.X);
        //        var minY1 = faceDots.Min(point => point.ValueMirrored.Y);
        //        var maxY1 = faceDots.Max(point => point.ValueMirrored.Y);

        //        var rrr = new RectangleF((float)minX1, (float)minY1, (float)(maxX1 - minX1), (float)(maxY1 - minY1));
        //    }

        //    var minX = faceDots.Min(point => point.ValueMirrored.X) * ImageTemplateWidth + ImageTemplateOffsetX;
        //    var maxX = faceDots.Max(point => point.ValueMirrored.X) * ImageTemplateWidth + ImageTemplateOffsetX;
        //    var minY = faceDots.Min(point => point.ValueMirrored.Y) * ImageTemplateHeight + ImageTemplateOffsetY;
        //    var maxY = faceDots.Max(point => point.ValueMirrored.Y) * ImageTemplateHeight + ImageTemplateOffsetY;

        //    FaceRectTransformed = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));

        //    CentralFacePoint = new Vector2(minX + (maxX - minX) * 0.5f, minY + (maxY - minY) / 3f);
        //}

        //private void RecalcUserCenters()
        //{
        //    MouthTransformed = new Vector2(ProgramCore.Project.MouthUserCenter.X * ImageTemplateWidth + ImageTemplateOffsetX,
        //                                 ProgramCore.Project.MouthUserCenter.Y * ImageTemplateHeight + ImageTemplateOffsetY);
        //    LeftEyeTransformed = new Vector2(ProgramCore.Project.LeftEyeUserCenter.X * ImageTemplateWidth + ImageTemplateOffsetX,
        //                                   ProgramCore.Project.LeftEyeUserCenter.Y * ImageTemplateHeight + ImageTemplateOffsetY);
        //    RightEyeTransformed = new Vector2(ProgramCore.Project.RightEyeUserCenter.X * ImageTemplateWidth + ImageTemplateOffsetX,
        //                                   ProgramCore.Project.RightEyeUserCenter.Y * ImageTemplateHeight + ImageTemplateOffsetY);
        //    NoseTransformed = new Vector2(ProgramCore.Project.NoseUserCenter.X * ImageTemplateWidth + ImageTemplateOffsetX,
        //                       ProgramCore.Project.NoseUserCenter.Y * ImageTemplateHeight + ImageTemplateOffsetY);
        //}

        public void AttachHair(string hairObjPath, string materialPath, ManType manType)
        {
            var objModel = ObjLoader.LoadObjFile(hairObjPath, false);

            if (objModel == null)
            {
                return;
            }

            var temp   = 0;
            var meshes = PickingController.LoadHairMeshes(objModel, null, true, manType, MeshType.Hair, ref temp);

            foreach (var mesh in meshes)
            {
                if (mesh == null || mesh.vertexArray.Length == 0) //ТУТ!
                {
                    continue;
                }
                mesh.Material.DiffuseTextureMap = materialPath;
            }

            var objName = Path.GetFileNameWithoutExtension(hairObjPath);

            if (HairPositions.ContainsKey(objName))
            {
                var meshSize = HairPositions[objName].Item2;

                var s = HairPositions[objName].Item1 * ProgramCore.Project.RenderMainHelper.headMeshesController.RenderMesh.MorphScale;         // домножаем на 8 для веб версии. все на 8 домножаем! любим 8!
                for (var i = 0; i < meshes.Count; i++)
                {
                    var mesh = meshes[i];
                    if (mesh == null || mesh.vertexArray.Length == 0) //ТУТ!
                    {
                        continue;
                    }

                    mesh.Position        += new Vector3(s[0], s[1], s[2]);
                    mesh.Transform[3, 0] += s[0];
                    mesh.Transform[3, 1] += s[1];
                    mesh.Transform[3, 2] += s[2];

                    if (!float.IsNaN(meshSize))
                    {
                        mesh.InterpolateMesh(meshSize);
                    }
                }
            }

            ProgramCore.Project.RenderMainHelper.pickingController.HairMeshes.Clear();
            ProgramCore.Project.RenderMainHelper.pickingController.HairMeshes.AddRange(meshes);
        }
예제 #7
0
        public MeshInfo GetMeshInfo(float scale, ManType manType)
        {
            var worldMatrix = Transform;
            var position    = new Vector3(worldMatrix[3, 0], worldMatrix[3, 1], worldMatrix[3, 2]);

            worldMatrix[3, 0] = 0.0f;
            worldMatrix[3, 1] = 0.0f;
            worldMatrix[3, 2] = 0.0f;
            worldMatrix      *= Matrix4.CreateScale(scale);

            worldMatrix[3, 0] = position.X * scale;
            worldMatrix[3, 1] = position.Y * scale;
            worldMatrix[3, 2] = position.Z * scale;

            return(new MeshInfo(this, vertexArray, worldMatrix, manType));
        }
예제 #8
0
        public static string GetCaption(this ManType manType)
        {
            switch (manType)
            {
            case ManType.Male:
                return("Man");

            case ManType.Female:
                return("Woman");

            case ManType.Child:
                return("Child");

            default:
                return("Custom");
            }
        }
예제 #9
0
        public static string GetObjDirPathSmilePlugin(this ManType manType)
        {
            switch (manType)
            {
            case ManType.Male:
                return("MaleWithSmilePlugin");

            case ManType.Female:
                return("FemWithSmilePlugin");

            case ManType.Child:
                return("ChildWithSmilePlugin");

            default:
                return(string.Empty);
            }
        }
예제 #10
0
        public static string GetObjPathSmilePlugin(this ManType manType)
        {
            switch (manType)
            {
            case ManType.Male:
                return(Path.Combine(manType.GetObjDirPathSmilePlugin(), "Male.obj"));

            case ManType.Female:
                return(Path.Combine(manType.GetObjDirPathSmilePlugin(), "Fem.obj"));

            case ManType.Child:
                return(Path.Combine(manType.GetObjDirPathSmilePlugin(), "Child.obj"));

            default:
                return(string.Empty);
            }
        }
예제 #11
0
파일: Project.cs 프로젝트: wiplug/HeadShop
        public static string GetObjPath(this ManType manType)
        {
            switch (manType)
            {
            case ManType.Male:
                return("Male\\Male.obj");

            case ManType.Female:
                return("Fem\\Fem.obj");

            case ManType.Child:
                return("Child\\Child.obj");

            default:
                return(string.Empty);
            }
        }
예제 #12
0
        public static string GetObjDirPath(this ManType manType, bool isOpenSmile)
        {
            switch (manType)
            {
            case ManType.Male:
                return(isOpenSmile ? "MaleWithSmilePlugin" : "Male");

            case ManType.Female:
                return(isOpenSmile ? "FemWithSmilePlugin" : "Fem");

            case ManType.Child:
                return(isOpenSmile ? "ChildWithSmilePlugin" : "Child");

            default:
                return("Fem");
            }
        }
예제 #13
0
파일: Project.cs 프로젝트: wiplug/HeadShop
        public static string GetObjDirPath(this ManType manType)
        {
            switch (manType)
            {
            case ManType.Male:
                return("Male");

            case ManType.Female:
                return("Fem");

            case ManType.Child:
                return("Child");

            default:
                return(string.Empty);
            }
        }
예제 #14
0
        private void AttachAddon(string addonObjPath, ref string addonMaterialPath, string sessionID, ManType manType, ref ZipOutputStream zipStream)
        {
            if (!string.IsNullOrEmpty(addonObjPath) && FTPHelper.IsFileExists(addonObjPath))
            {
                if (!isAddonMaterialActivated)
                {
                    addonMaterialPath = GetParcedHairAccessoriesLink(addonMaterialPath, "T.jpg").Replace("/Icons/", "/Materials/");;
                    if (!string.IsNullOrEmpty(addonMaterialPath))
                    {
                        var temp     = @"ftp://108.167.164.209/public_html/printahead.online/PrintAhead_models/" + sessionID + "/Textures";
                        var fileName = Path.GetFileNameWithoutExtension(addonMaterialPath) + ".jpg";

                        FTPHelper.CopyFromFtpToFtp(addonMaterialPath, temp, fileName, zipStream, fileName);
                        addonMaterialPath        = @"ftp://108.167.164.209/public_html/printahead.online/PrintAhead_models/" + sessionID + "/Textures/" + fileName;
                        isAddonMaterialActivated = true;
                    }
                }

                ProgramCore.Project.RenderMainHelper.AttachAccessory(addonObjPath, addonMaterialPath, manType);
            }
        }
예제 #15
0
        public MeshInfo(DynamicRenderMesh parent, Vertex[] vertices, Matrix4 transformMatrix, ManType manType)
        {
            Material = parent.Material;
            Title    = parent.Title;
            var positionsMapping = new Dictionary <Vector3, int>(new VectorEqualityComparer());
            var texCoordsMapping = new Dictionary <Vector2, int>(new VectorEqualityComparer());
            var normalsMapping   = new Dictionary <Vector3, int>(new VectorEqualityComparer());

            if (transformMatrix != Matrix4.Zero)
            {
                var scaleCoef = 1f;
                if (parent.meshType == MeshType.Accessory)
                {
                    scaleCoef = 246f;
                }
                else if (parent.meshType == MeshType.Head)
                {
                    scaleCoef = PickingController.GetHeadScale(manType);
                }
                else
                {
                    scaleCoef = PickingController.GetHairScale(manType);
                }
                //ProgramCore.PluginMode &&
                var useExporter = ProgramCore.MainForm.ctrlRenderControl.pickingController.ObjExport != null;
                var invScale    = Matrix4.CreateScale(useExporter ? 1.0f : 1.0f / scaleCoef);
                TempTransform  = transformMatrix;
                TempTransform *= invScale;
                if (useExporter)
                {
                    var d = ProgramCore.MainForm.ctrlRenderControl.pickingController.ObjExport.Delta;
                    d.Y           -= 0.0060975609f;
                    DeltaTransform = d * scaleCoef;
                    TempTransform *=
                        Matrix4.CreateTranslation(d * scaleCoef);
                }
            }
            else
            {
                TempTransform  = Matrix4.Identity;
                DeltaTransform = Vector3.Zero;
            }

            foreach (var vertex in vertices)
            {
                // var index = i * 3;
                var position = vertex.Position;

                var texCoord = vertex.TexCoord;
                texCoord.Y = 1.0f - texCoord.Y;

                var normal = vertex.Normal;

                position = Vector3.Transform(position, TempTransform);
                normal   = Vector3.Transform(normal, TempTransform);

                int id;
                if (!positionsMapping.TryGetValue(position, out id))
                {
                    id = Positions.Count;
                    Positions.Add(position);
                    positionsMapping.Add(position, id);
                }
                IndicesPositions.Add(id);

                if (!normalsMapping.TryGetValue(normal, out id))
                {
                    id = Normals.Count;
                    Normals.Add(normal);
                    normalsMapping.Add(normal, id);
                }
                IndicesNormals.Add(id);

                if (!texCoordsMapping.TryGetValue(texCoord, out id))
                {
                    id = TexCoords.Count;
                    TexCoords.Add(texCoord);
                    texCoordsMapping.Add(texCoord, id);
                }
                IndicesTexCoords.Add(id);
            }
        }
예제 #16
0
 public Man(Player player, ManType manType)
 {
     this.player  = player;
     this.manType = manType;
 }
예제 #17
0
        public static void SaveObjFile(string filePath, DynamicRenderMeshes meshes, MeshType type, float scale, ManType manType, string sessionId, bool saveBrushesToTexture = false, bool isCollada = false)
        {
            var meshInfos = new List <MeshInfo>();

            foreach (var mesh in meshes)
            {
                var meshInfo = mesh.GetMeshInfo(scale, manType);
                meshInfos.Add(meshInfo);
            }
            SaveObjFile(filePath, meshInfos, type, saveBrushesToTexture, isCollada, sessionId);
        }
예제 #18
0
        public void LoadModel(string path, bool needClean, ManType manType, MeshType type)
        {
            if (needClean)
                CleanProjectMeshes();

            pickingController.AddMehes(path, type, false, manType, false);
        }
예제 #19
0
        private List <MeshPartInfo> LoadHeadMeshes(ObjItem objModel, bool fromDragAndDrop, ManType manType, float scale, ref int lastTriangle)
        {
            var result                   = new List <MeshPartInfo>();
            var vertexPositions          = new List <float>();
            var vertexNormals            = new List <float>();
            var vertexTextureCoordinates = new List <float>();
            var vertexBoneIndices        = new List <float>();
            var vertexBoneWeights        = new List <float>();
            var indeces                  = new List <uint>();

            foreach (var modelGroup in objModel.Groups) // one group - one mesh
            {
                //    if (/*!ProgramCore.PluginMode &&*/ ( modelGroup.Key.Name == "Tear" || modelGroup.Key.Name == "Cornea" || modelGroup.Key.Name == "EyeReflection"))     // очень плохие материалы. ИЗ-за них ломаются глазки.
                //       continue;           // если это плагин - то пропуск материалов ВСЕ ломает для экспортера в строчке GetObjFace. Возможно потребуется химичить с индексами

                vertexPositions.Clear();
                vertexNormals.Clear();
                vertexTextureCoordinates.Clear();
                vertexBoneIndices.Clear();
                vertexBoneWeights.Clear();
                indeces.Clear();

                foreach (var face in modelGroup.Value.Faces)          //  combine all meshes in group - to one mesh.
                {
                    GetObjFace(face, objModel, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces, ref lastTriangle);
                }

                var positions = new List <Vector3>();
                var texCoords = new List <Vector2>();
                var index     = 0;
                for (var i = 0; i < vertexPositions.Count / 3; ++i)
                {
                    index = i * 3;
                    positions.Add(new Vector3(vertexPositions[index], vertexPositions[index + 1], vertexPositions[index + 2]));
                    texCoords.Add(new Vector2(vertexTextureCoordinates[i * 2], 1.0f - vertexTextureCoordinates[i * 2 + 1]));
                }

                var meshPartInfo = new MeshPartInfo
                {
                    VertexPositions = GetScaledVertices(positions, scale),
                    TextureCoords   = texCoords,
                    PartName        = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name,
                };

                meshPartInfo.Texture                = modelGroup.Key.Texture;
                meshPartInfo.TransparentTexture     = modelGroup.Key.TransparentTexture;
                meshPartInfo.TextureName            = modelGroup.Key.DiffuseTextureMap;
                meshPartInfo.TransparentTextureName = modelGroup.Key.TransparentTextureMap;
                meshPartInfo.Color =
                    new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y,
                                modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency);
                meshPartInfo.MaterialName = modelGroup.Key.Name;

                result.Add(meshPartInfo);
            }

            return(result);
        }
예제 #20
0
        /// <summary> Создание нового проекта </summary>
        /// <param name="projectName"></param>
        /// <param name="projectPath"></param>
        /// <param name="templateImageName"></param>
        /// <param name="manType"></param>
        /// <param name="headModelPath">Указываем путь до модели головы (в случае если выбрали import OBJ). Иначе - пустая строка</param>
        /// <param name="needCopy"></param>
        public Project(string projectName, string projectPath, string templateImageName, GenesisType genesisType, ManType manType, string headModelPath, bool needCopy, int selectedSize, bool isOpenSmile)
        {
            ProjectName = projectName;
            ProjectPath = projectPath;
            TextureSize = selectedSize;

            ManType     = manType;
            IsOpenSmile = isOpenSmile;
            GenesisType = genesisType;
            switch (manType)
            {
            case ManType.Male:
            case ManType.Female:             // если это обычные модели - копируем их из папки с прогой - в папку с проектом
            case ManType.Child:
                if (!ProgramCore.PluginMode) //тогда хед модел пас оставляем какой был! пиздец важно!
                {                            // я хз почему это важно, но сейчас получается что при загрузке из Даз всегда берется одна модель, независимо от того, что выбрал пользователь (13.02.2018)
#if WEB_APP
                    headModelPath = "ftp://108.167.164.209/public_html/printahead.online/PrintAhead_DefaultModels/" + manType.GetObjPath();
                    headModelPath = headModelPath.Replace(@"\", "/");
#else
                    headModelPath = Path.Combine(Application.StartupPath, "Models", "Model", GenesisType.GetGenesisPath(), manType.GetObjPath(isOpenSmile));
#endif
                }

                break;

            case ManType.Custom:
            {
                BaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetBaseDots(ManType.Female))
                {
                    BaseDots.Add(new HeadPoint(vector));
                }

                ProfileBaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetProfileBaseDots(ManType.Female))
                {
                    ProfileBaseDots.Add(new HeadPoint(vector));
                }
            }
            break;
            }

            if (needCopy)
            {
                try
                {
                    var di = new DirectoryInfo(projectPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }

                    if (!string.IsNullOrEmpty(templateImageName))
                    {
                        var fi = new FileInfo(templateImageName);
                        if (fi.Exists)
                        {
                            var newImagePath = Path.Combine(projectPath, fi.Name);
                            File.Copy(templateImageName, newImagePath, true);
                            FrontImagePath = fi.Name;
                        }
                    }

                    #region Копируем модель

                    var directoryPath = Path.Combine(ProjectPath, "Model");
                    FolderEx.CreateDirectory(directoryPath);
                    var oldFileName = Path.GetFileNameWithoutExtension(headModelPath);
                    var newFileName = oldFileName;
                    var filePath    = Path.Combine(directoryPath, newFileName + ".obj");

                    File.Copy(headModelPath, filePath, true); // сама модель
                    HeadModelPath = filePath;

                    #region Обрабатываем mtl файл и папку с текстурами

                    var mtl = oldFileName + ".mtl";
                    using (var ms = new StreamReader(headModelPath))
                    {
                        for (var i = 0; i < 10; i++)
                        {
                            if (ms.EndOfStream)
                            {
                                break;
                            }
                            var line = ms.ReadLine();
                            if (line.ToLower().Contains("mtllib"))
                            // ищем ссылку в obj файле на mtl файл (у них могут быть разные названия, но всегда в одной папке
                            {
                                var lines = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 1)
                                {
                                    mtl = lines[1];
                                    break;
                                }
                            }
                        }
                    }

                    ObjLoader.CopyMtl(mtl, mtl, Path.GetDirectoryName(headModelPath), "", directoryPath, selectedSize);

                    #endregion

                    #endregion
                }
                catch
                {
                    FrontImagePath = templateImageName;
                    HeadModelPath  = headModelPath;
                }
            }
            else
            {
                FrontImagePath = templateImageName;
                HeadModelPath  = headModelPath;
            }
        }
예제 #21
0
 public static float GetHeadScale(ManType manType)
 {
     switch (manType)
     {
         case ManType.Child:
             return ScaleChild;
         case ManType.Male:
         case ManType.Female:
             return ScaleMan;
     }
     return 1f;
 }
예제 #22
0
        private List<DynamicRenderMesh> LoadHairMeshes(ObjItem objModel, ObjItem objModelNull, bool fromDragAndDrop, ManType manType, MeshType meshType)
        {
            var result = new List<DynamicRenderMesh>();
            var vertexPositions = new List<float>();
            var vertexNormals = new List<float>();
            var vertexTextureCoordinates = new List<float>();
            var vertexBoneIndices = new List<float>();
            var vertexBoneWeights = new List<float>();
            var indeces = new List<uint>();

            var vertexPositionsNull = new List<float>();
            var vertexNormalsNull = new List<float>();
            var vertexTextureCoordinatesNull = new List<float>();
            var vertexBoneIndicesNull = new List<float>();
            var vertexBoneWeightsNull = new List<float>();
            var indecesNull = new List<uint>();

            var groupsNull = objModelNull == null ? new Dictionary<ObjMaterial, ObjGroup>.Enumerator() : objModelNull.Groups.GetEnumerator();
            ObjGroup groupNull;
            foreach (var modelGroup in objModel.Groups)          // one group - one mesh
            {
                vertexPositions.Clear();
                vertexNormals.Clear();
                vertexTextureCoordinates.Clear();
                vertexBoneIndices.Clear();
                vertexBoneWeights.Clear();
                indeces.Clear();

                foreach (var face in modelGroup.Value.Faces)          //  combine all meshes in group - to one mesh.
                    GetObjFace(face, objModel, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);

                var renderMesh = new DynamicRenderMesh(meshType);
                renderMesh.groupName = modelGroup.Value.Name;

                if (!objModel.modelByHeadShop)
                {
                    for (var i = 0; i < vertexPositions.Count / 3; i++)
                        vertexPositions[i * 3 + 1] = vertexPositions[i * 3 + 1] - 0.0060975609f;
                }

                ProgramCore.EchoToLog(String.Format("RenderMesh: {0}", modelGroup.Value.Name), EchoMessageType.Information);
                ProgramCore.EchoToLog(
                    String.Format("renderMesh.Create: {0}, {1}, {2}, {3}, {4}", vertexPositions.Count,
                        vertexTextureCoordinates.Count, vertexBoneIndices.Count, vertexBoneWeights.Count, indeces.Count),
                    EchoMessageType.Information);

                if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty))
                {
                    if (objModelNull != null)
                    {
                        groupsNull.MoveNext();
                        groupNull = groupsNull.Current.Value;
                        vertexPositionsNull.Clear();
                        vertexNormalsNull.Clear();
                        vertexTextureCoordinatesNull.Clear();
                        vertexBoneWeightsNull.Clear();
                        vertexBoneIndicesNull.Clear();
                        indecesNull.Clear();
                        foreach (var face in groupNull.Faces)
                        {
                            GetObjFace(face, objModelNull, ref vertexPositionsNull, ref vertexNormalsNull, ref vertexTextureCoordinatesNull, ref vertexBoneWeightsNull, ref vertexBoneIndicesNull, ref indecesNull);
                        }
                        renderMesh.SetNullPoints(vertexPositionsNull, vertexNormalsNull, vertexTextureCoordinatesNull);
                    }

                    renderMesh.Title = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name;
                    renderMesh.Material = modelGroup.Key;
                    renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency);

                    if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap))
                        renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap;
                    if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap))
                        renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap;

                    var scale = meshType == MeshType.Head ? GetHeadScale(manType) : GetHairScale(manType);                       // перегруз сделан потому, что на этапе загрузки проекта самого проекта еще может не быть. поэтому лучше передавать
                    renderMesh.Transform = Matrix4.CreateScale(scale);

                    var center = Vector3.Zero;
                    var count = vertexPositions.Count / 3;
                    for (var i = 0; i < count; i++)
                    {
                        center.X += vertexPositions[i * 3] * scale;
                        center.Y += vertexPositions[i * 3 + 1] * scale;
                        center.Z += vertexPositions[i * 3 + 2] * scale;
                    }

                    if (fromDragAndDrop)
                    {
                        center /= count;
                        renderMesh.Transform = Matrix4.CreateScale(scale);
                        renderMesh.Transform[3, 0] = -center.X;
                        renderMesh.Transform[3, 1] = -center.Y;
                        renderMesh.Transform[3, 2] = -center.Z;
                        renderMesh.Position = center;
                    }

                    if (vertexTextureCoordinates.Count > 0 && vertexTextureCoordinates.All(x => x == 0))
                        renderMesh.UpdateTextureCoordinates(0, 1);

                    if (renderMesh.vertexArray.Length > 0)
                        result.Add(renderMesh);
                }
            }
            return result;
        }
예제 #23
0
        public List<DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, string animationPath, bool needExporter)
        {
            var result = new List<DynamicRenderMesh>();

            var objModel = ObjLoader.LoadObjFile(path, needExporter);
            if (objModel == null)
            {
                ProgramCore.EchoToLog(string.Format("Can't load obj model '{0}'", path), EchoMessageType.Error);
                return result;
            }

            switch (type)
            {
                case MeshType.Hair:
                    {
                        var fi = new FileInfo(path);
                        var objModelNull = ObjLoader.LoadObjFile(Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, string.Format("_null{0}", fi.Extension))));
                        if (objModelNull != null &&
                            (objModelNull.Groups.Count != objModel.Groups.Count ||
                            objModel.Vertices.Count != objModelNull.Vertices.Count))
                            //  objModel.TextureCoords.Count != objModelNull.TextureCoords.Count))
                            objModelNull = null;

                        result = LoadHairMeshes(objModel, objModelNull, fromDragAndDrop, manType, MeshType.Hair);
                        foreach (var renderMesh in result)
                            HairMeshes.Add(renderMesh);
                        break;
                    }
                case MeshType.Accessory:
                    result.AddRange(objModel.accessoryByHeadShop ? LoadSpecialAccessoryMesh(objModel) : new List<DynamicRenderMesh> { LoadAccessoryMesh(objModel) });
                    break;
                case MeshType.Head:
                    {
                        var tempPluginTexture = string.Empty;
                        if (ProgramCore.PluginMode)
                        {
                            var folderPath = Path.Combine(Application.StartupPath, "Models\\Model", manType.GetObjDirPath());
                            switch (ProgramCore.Project.ManType)
                            {
                                case ManType.Male:
                                    tempPluginTexture = Path.Combine(folderPath, "Maps", "RyNevio_faceB.jpg");
                                    break;
                                case ManType.Female:
                                    tempPluginTexture = Path.Combine(folderPath, "Maps", "RyBelle_face.jpg");
                                    break;
                                case ManType.Child:
                                    tempPluginTexture = Path.Combine(folderPath, "Maps", "AC_KidsRRHBy.jpg");
                                    break;
                                default:
                                    tempPluginTexture = Path.Combine(Application.StartupPath, "Plugin", "fsRndColor.png");
                                    break;
                            }
                        }

                        foreach (var mesh in HeadMeshes)
                            mesh.Destroy();
                        HeadMeshes.Clear();

                        var objModelFull = animationPath == string.Empty ? null : ObjLoader.LoadObjFile(animationPath);
                        if (objModelFull != null &&
                            (objModelFull.Groups.Count != objModel.Groups.Count ||
                            objModel.Vertices.Count != objModelFull.Vertices.Count ||
                            objModel.TextureCoords.Count != objModelFull.TextureCoords.Count))
                            objModelFull = null;
                        LastTriangleIndex = 0;
                        result = LoadHairMeshes(objModel, objModelFull, fromDragAndDrop, manType, MeshType.Head);
                        var meshPartInfos = new List<MeshPartInfo>();
                        var a = new Vector3(99999.0f, 99999.0f, 99999.0f);
                        var b = new Vector3(-99999.0f, -99999.0f, -99999.0f);
                        foreach (var renderMesh in result)
                        {
                            HeadMeshes.Add(renderMesh);

                            if (ProgramCore.PluginMode && ProgramCore.MainForm.PluginUvGroups.Contains(renderMesh.Material.Name))
                            {
                                if (string.IsNullOrEmpty(renderMesh.Material.DiffuseTextureMap))
                                    renderMesh.Material.DiffuseTextureMap = tempPluginTexture;
                                else if (!File.Exists(renderMesh.Material.DiffuseTextureMap))
                                    renderMesh.Material.DiffuseTextureMap = tempPluginTexture;
                            }

                            var meshPartInfo = new MeshPartInfo
                            {
                                VertexPositions = renderMesh.GetVertices(),
                                TextureCoords = renderMesh.GetTexCoords(),
                                PartName = renderMesh.Title,
                                Color = renderMesh.Material.DiffuseColor,
                                Texture = renderMesh.Material.Texture,
                                TransparentTexture = renderMesh.Material.TransparentTexture,
                                TextureName = renderMesh.Material.DiffuseTextureMap,
                                TransparentTextureName = renderMesh.Material.TransparentTextureMap
                            };                  // создаем инфу о голове. для работы с headshop
                            GetAABB(ref a, ref b, meshPartInfo.VertexPositions);
                            meshPartInfos.Add(meshPartInfo);

                        }
                        var dv = Vector3.Zero;
                        foreach (var meshPartInfo in meshPartInfos)
                        {
                            dv = MoveToPosition(ref meshPartInfo.VertexPositions, a, b, Vector3.Zero);
                            ProgramCore.MainForm.ctrlRenderControl.headMeshesController.CreateMeshPart(meshPartInfo);
                        }

                        ObjExport = objModel.ObjExport;
                        if (ObjExport != null)
                            ObjExport.Delta = -dv;
                        ProgramCore.MainForm.ctrlRenderControl.headMeshesController.FinishCreating();

                        // ProgramCore.MainForm.ctrlRenderControl.headMeshesController.InitializeTexturing(HeadController.GetDots(ProgramCore.Project.ManType), HeadController.GetIndices(ProgramCore.Project.ManType));
                        break;
                    }
                default:
                    return result;
            }

            foreach (var item in result)
                item.Path = path;

            return result;
        }
예제 #24
0
 public List<DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, bool needExporter)
 {
     return AddMehes(path, type, fromDragAndDrop, manType, string.Empty, needExporter);
 }
예제 #25
0
 public List <DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, bool needExporter)
 {
     return(AddMehes(path, type, fromDragAndDrop, manType, string.Empty, needExporter));
 }
예제 #26
0
        private List <DynamicRenderMesh> LoadHairMeshes(ObjItem objModel, ObjItem objModelNull, bool fromDragAndDrop, ManType manType, MeshType meshType)
        {
            var result                   = new List <DynamicRenderMesh>();
            var vertexPositions          = new List <float>();
            var vertexNormals            = new List <float>();
            var vertexTextureCoordinates = new List <float>();
            var vertexBoneIndices        = new List <float>();
            var vertexBoneWeights        = new List <float>();
            var indeces                  = new List <uint>();

            var vertexPositionsNull          = new List <float>();
            var vertexNormalsNull            = new List <float>();
            var vertexTextureCoordinatesNull = new List <float>();
            var vertexBoneIndicesNull        = new List <float>();
            var vertexBoneWeightsNull        = new List <float>();
            var indecesNull = new List <uint>();

            var groupsNull = objModelNull == null ? new Dictionary <ObjMaterial, ObjGroup> .Enumerator() : objModelNull.Groups.GetEnumerator();

            ObjGroup groupNull;

            foreach (var modelGroup in objModel.Groups)          // one group - one mesh
            {
                vertexPositions.Clear();
                vertexNormals.Clear();
                vertexTextureCoordinates.Clear();
                vertexBoneIndices.Clear();
                vertexBoneWeights.Clear();
                indeces.Clear();

                foreach (var face in modelGroup.Value.Faces)          //  combine all meshes in group - to one mesh.
                {
                    GetObjFace(face, objModel, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                }

                var renderMesh = new DynamicRenderMesh(meshType);
                renderMesh.groupName = modelGroup.Value.Name;

                if (!objModel.modelByHeadShop)
                {
                    for (var i = 0; i < vertexPositions.Count / 3; i++)
                    {
                        vertexPositions[i * 3 + 1] = vertexPositions[i * 3 + 1] - 0.0060975609f;
                    }
                }

                if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty))
                {
                    if (objModelNull != null)
                    {
                        groupsNull.MoveNext();
                        groupNull = groupsNull.Current.Value;
                        vertexPositionsNull.Clear();
                        vertexNormalsNull.Clear();
                        vertexTextureCoordinatesNull.Clear();
                        vertexBoneWeightsNull.Clear();
                        vertexBoneIndicesNull.Clear();
                        indecesNull.Clear();
                        foreach (var face in groupNull.Faces)
                        {
                            GetObjFace(face, objModelNull, ref vertexPositionsNull, ref vertexNormalsNull, ref vertexTextureCoordinatesNull, ref vertexBoneWeightsNull, ref vertexBoneIndicesNull, ref indecesNull);
                        }
                        renderMesh.SetNullPoints(vertexPositionsNull, vertexNormalsNull, vertexTextureCoordinatesNull);
                    }

                    renderMesh.Title    = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name;
                    renderMesh.Material = modelGroup.Key;
                    renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency);

                    if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap))
                    {
                        renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap;
                    }
                    if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap))
                    {
                        renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap;
                    }

                    var scale = meshType == MeshType.Head ? GetHeadScale(manType) : GetHairScale(manType);                       // перегруз сделан потому, что на этапе загрузки проекта самого проекта еще может не быть. поэтому лучше передавать
                    renderMesh.Transform = Matrix4.CreateScale(scale);

                    var center = Vector3.Zero;
                    var count  = vertexPositions.Count / 3;
                    for (var i = 0; i < count; i++)
                    {
                        center.X += vertexPositions[i * 3] * scale;
                        center.Y += vertexPositions[i * 3 + 1] * scale;
                        center.Z += vertexPositions[i * 3 + 2] * scale;
                    }

                    if (fromDragAndDrop)
                    {
                        center /= count;
                        renderMesh.Transform       = Matrix4.CreateScale(scale);
                        renderMesh.Transform[3, 0] = -center.X;
                        renderMesh.Transform[3, 1] = -center.Y;
                        renderMesh.Transform[3, 2] = -center.Z;
                        renderMesh.Position        = center;
                    }

                    if (vertexTextureCoordinates.Count > 0 && vertexTextureCoordinates.All(x => x == 0))
                    {
                        renderMesh.UpdateTextureCoordinates(0, 1);
                    }

                    if (renderMesh.vertexArray.Length > 0)
                    {
                        result.Add(renderMesh);
                    }
                }
            }
            return(result);
        }
예제 #27
0
        public List <DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, string animationPath, bool needExporter)
        {
            var result = new List <DynamicRenderMesh>();

            var objModel = ObjLoader.LoadObjFile(path, needExporter);

            if (objModel == null)
            {
                ProgramCore.EchoToLog(string.Format("Can't load obj model '{0}'", path), EchoMessageType.Error);
                return(result);
            }

            switch (type)
            {
            case MeshType.Hair:
            {
                var fi           = new FileInfo(path);
                var objModelNull = ObjLoader.LoadObjFile(Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, string.Format("_null{0}", fi.Extension))));
                if (objModelNull != null &&
                    (objModelNull.Groups.Count != objModel.Groups.Count ||
                     objModel.Vertices.Count != objModelNull.Vertices.Count))
                {
                    //  objModel.TextureCoords.Count != objModelNull.TextureCoords.Count))
                    objModelNull = null;
                }

                result = LoadHairMeshes(objModel, objModelNull, fromDragAndDrop, manType, MeshType.Hair);
                foreach (var renderMesh in result)
                {
                    HairMeshes.Add(renderMesh);
                }
                break;
            }

            case MeshType.Accessory:
                return(objModel.accessoryByHeadShop ? LoadSpecialAccessoryMesh(objModel) : new List <DynamicRenderMesh> {
                    LoadAccessoryMesh(objModel)
                });

            case MeshType.Head:
            {
                var tempPluginTexture = string.Empty;
                if (ProgramCore.PluginMode)
                {
                    var folderPath = Path.Combine(Application.StartupPath, "Models\\Model", manType.GetObjDirPath());
                    switch (ProgramCore.Project.ManType)
                    {
                    case ManType.Male:
                        tempPluginTexture = Path.Combine(folderPath, "Maps", "RyNevio_faceB.jpg");
                        break;

                    case ManType.Female:
                        tempPluginTexture = Path.Combine(folderPath, "Maps", "RyBelle_face.jpg");
                        break;

                    case ManType.Child:
                        tempPluginTexture = Path.Combine(folderPath, "Maps", "AC_KidsRRHBy.jpg");
                        break;

                    default:
                        tempPluginTexture = Path.Combine(Application.StartupPath, "Plugin", "fsRndColor.png");
                        break;
                    }
                }

                foreach (var mesh in HeadMeshes)
                {
                    mesh.Destroy();
                }
                HeadMeshes.Clear();

                var objModelFull = animationPath == string.Empty ? null : ObjLoader.LoadObjFile(animationPath);
                if (objModelFull != null &&
                    (objModelFull.Groups.Count != objModel.Groups.Count ||
                     objModel.Vertices.Count != objModelFull.Vertices.Count ||
                     objModel.TextureCoords.Count != objModelFull.TextureCoords.Count))
                {
                    objModelFull = null;
                }
                LastTriangleIndex = 0;
                result            = LoadHairMeshes(objModel, objModelFull, fromDragAndDrop, manType, MeshType.Head);
                var meshPartInfos = new List <MeshPartInfo>();
                var a             = new Vector3(99999.0f, 99999.0f, 99999.0f);
                var b             = new Vector3(-99999.0f, -99999.0f, -99999.0f);
                foreach (var renderMesh in result)
                {
                    HeadMeshes.Add(renderMesh);

                    if (ProgramCore.PluginMode && ProgramCore.MainForm.PluginUvGroups.Contains(renderMesh.Material.Name))
                    {
                        if (string.IsNullOrEmpty(renderMesh.Material.DiffuseTextureMap))
                        {
                            renderMesh.Material.DiffuseTextureMap = tempPluginTexture;
                        }
                        else if (!File.Exists(renderMesh.Material.DiffuseTextureMap))
                        {
                            renderMesh.Material.DiffuseTextureMap = tempPluginTexture;
                        }
                    }

                    var meshPartInfo = new MeshPartInfo
                    {
                        VertexPositions        = renderMesh.GetVertices(),
                        TextureCoords          = renderMesh.GetTexCoords(),
                        PartName               = renderMesh.Title,
                        Color                  = renderMesh.Material.DiffuseColor,
                        Texture                = renderMesh.Material.Texture,
                        TransparentTexture     = renderMesh.Material.TransparentTexture,
                        TextureName            = renderMesh.Material.DiffuseTextureMap,
                        TransparentTextureName = renderMesh.Material.TransparentTextureMap
                    };                          // создаем инфу о голове. для работы с headshop
                    GetAABB(ref a, ref b, meshPartInfo.VertexPositions);
                    meshPartInfos.Add(meshPartInfo);
                }
                Vector3 dv = Vector3.Zero;
                foreach (var meshPartInfo in meshPartInfos)
                {
                    dv = MoveToPosition(ref meshPartInfo.VertexPositions, a, b, Vector3.Zero);
                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.CreateMeshPart(meshPartInfo);
                }

                ObjExport = objModel.ObjExport;
                if (ObjExport != null)
                {
                    ObjExport.Delta = -dv;
                }
                ProgramCore.MainForm.ctrlRenderControl.headMeshesController.FinishCreating();

                // ProgramCore.MainForm.ctrlRenderControl.headMeshesController.InitializeTexturing(HeadController.GetDots(ProgramCore.Project.ManType), HeadController.GetIndices(ProgramCore.Project.ManType));
                break;
            }

            default:
                return(result);
            }
            return(result);
        }
예제 #28
0
        public List <DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, GenesisType genesisType, ManType manType, string animationPath, bool needExporter, bool isOpenSmile)
        {
            var result = new List <DynamicRenderMesh>();

            var objModel = ObjLoader.LoadObjFile(path, needExporter, isOpenSmile);

            if (objModel == null)
            {
                ProgramCore.EchoToLog($"Can't load obj model '{path}'", EchoMessageType.Error);
                return(result);
            }

            var lastTriangle = 0;

            switch (type)
            {
            case MeshType.Hair:
            {
                var fi           = new FileInfo(path);
                var objModelNull = ObjLoader.LoadObjFile(Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, string.Format("_null{0}", fi.Extension))), isOpenSmile);
                if (objModelNull != null &&
                    (objModelNull.Groups.Count != objModel.Groups.Count ||
                     objModel.Vertices.Count != objModelNull.Vertices.Count))
                {
                    //  objModel.TextureCoords.Count != objModelNull.TextureCoords.Count))
                    objModelNull = null;
                }

                result = LoadHairMeshes(objModel, objModelNull, fromDragAndDrop, manType, MeshType.Hair, ref lastTriangle);
                foreach (var renderMesh in result)
                {
                    HairMeshes.Add(renderMesh);
                }
                break;
            }

            case MeshType.Accessory:

                if (objModel.accessoryByHeadShop)
                {
                    result.AddRange(LoadSpecialAccessoryMesh(objModel));
                }
                else
                {
                    var accessories = new List <DynamicRenderMesh> {
                        LoadAccessoryMesh(objModel)
                    };
                    foreach (var accessory in accessories)
                    {
                        AccesoryMeshes.Add(accessory);
                    }

                    result.AddRange(accessories);
                }
                break;

            case MeshType.Head:
            {
                var tempPluginTexture      = string.Empty;
                var topPoint               = 11.98351f;
                int tempPluginTextureIndex = 0;
                if (ProgramCore.PluginMode)
                {
                    var folderPath = Path.Combine(Application.StartupPath, "Models", "Model", genesisType.GetGenesisPath(), manType.GetObjDirPath(isOpenSmile));
                    switch (ProgramCore.Project.ManType)
                    {
                    case ManType.Male:
                        switch (ProgramCore.Project.GenesisType)
                        {
                        case GenesisType.Genesis2:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "RyNevio_faceB.jpg");
                            break;

                        case GenesisType.Genesis3:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "RyEddie_face_1001.jpg");
                            break;

                        case GenesisType.Genesis8:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "G8MBaseFaceMapD01_1001.jpg");
                            break;
                        }
                        break;

                    case ManType.Female:
                        switch (ProgramCore.Project.GenesisType)
                        {
                        case GenesisType.Genesis2:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "V5BreeHeadM.jpg");
                            break;

                        case GenesisType.Genesis3:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "RyJeane_face_1001.jpg");
                            break;

                        case GenesisType.Genesis8:
                            tempPluginTexture = Path.Combine(folderPath, "Maps", "G8FBaseFaceMapD_1001.jpg");
                            break;
                        }
                        break;

                    case ManType.Child:
                        tempPluginTexture = Path.Combine(folderPath, "Maps", "AC_KidsRRHBy.jpg");
                        break;

                    default:
                        tempPluginTexture = Path.Combine(Application.StartupPath, "Plugin", "fsRndColor.png");
                        break;
                    }
                    tempPluginTextureIndex = ProgramCore.MainForm.ctrlRenderControl.GetTexture(tempPluginTexture);
                }


                float scale = 1.0f;
                switch (ProgramCore.Project.ManType)
                {
                case ManType.Male:
                    topPoint = 11.98351f;
                    break;

                case ManType.Female:
                    topPoint = 11.61f;
                    break;

                case ManType.Child:
                    //scale = 0.85f;
                    topPoint = 9.759598f;
                    break;
                }

                var objModelFull = animationPath == string.Empty ? null : ObjLoader.LoadObjFile(animationPath, isOpenSmile);
                if (objModelFull != null &&
                    (objModelFull.Groups.Count != objModel.Groups.Count ||
                     objModel.Vertices.Count != objModelFull.Vertices.Count ||
                     objModel.TextureCoords.Count != objModelFull.TextureCoords.Count))
                {
                    objModelFull = null;
                }

                var meshPartInfos = LoadHeadMeshes(objModel, fromDragAndDrop, manType, scale, ref lastTriangle);
                ObjExport = objModel.ObjExport;

                //if (ProgramCore.PluginMode)
                {
                    ObjExport.DefaultA = new Vector3(99999.0f, 99999.0f, 99999.0f);
                    ObjExport.DefaultB = new Vector3(-99999.0f, -99999.0f, -99999.0f);

                    foreach (var meshPartInfo in meshPartInfos)
                    {
                        GetAABB(ref ObjExport.DefaultA, ref ObjExport.DefaultB, meshPartInfo.VertexPositions);
                    }
                }

                if (ProgramCore.PluginMode && isOpenSmile)
                {
                    PluginMorphToSmile(meshPartInfos, genesisType, manType, scale);
                }

                //result = LoadHairMeshes(objModel, objModelFull, fromDragAndDrop, manType, MeshType.Head);
                //var meshPartInfos = new List<MeshPartInfo>();
                var a = new Vector3(99999.0f, 99999.0f, 99999.0f);
                var b = new Vector3(-99999.0f, -99999.0f, -99999.0f);
                foreach (var meshPartInfo in meshPartInfos)
                {
                    if (ProgramCore.PluginMode && ProgramCore.MainForm.PluginUvGroups.Contains(meshPartInfo.MaterialName))
                    {
                        if (string.IsNullOrEmpty(meshPartInfo.TextureName) || !File.Exists(meshPartInfo.TextureName))
                        {
                            meshPartInfo.TextureName = tempPluginTexture;
                            meshPartInfo.Texture     = tempPluginTextureIndex;
                        }
                    }
                    GetAABB(ref a, ref b, meshPartInfo.VertexPositions);
                }
                var dv = Vector3.Zero;
                foreach (var meshPartInfo in meshPartInfos)
                {                   // ПОТЕНЦИАЛЬНО ОПАСНОЕ МЕСТО! В случае улетания башки - AlignByTOp сделать для всех, кроме плагина. Для него оставить MoveToPosition
#if (WEB_APP)
                    dv = AlignByTop(ref meshPartInfo.VertexPositions, a, b, topPoint);
#else
                    dv = MoveToPosition(ref meshPartInfo.VertexPositions, a, b, Vector3.Zero);
#endif
                    ProgramCore.Project.RenderMainHelper.headMeshesController.CreateMeshPart(ProgramCore.Project.GenesisType, meshPartInfo);
                }

                if (ObjExport != null)
                {
                    ObjExport.Delta = -dv;
                }
                ProgramCore.Project.RenderMainHelper.headMeshesController.FinishCreating();

                return(null);
                // ProgramCore.Project.RenderMainHelper.headMeshesController.InitializeTexturing(HeadController.GetDots(ProgramCore.Project.ManType), HeadController.GetIndices(ProgramCore.Project.ManType));
            }

            default:
                return(result);
            }

            foreach (var item in result)
            {
                item.Path = path;
            }

            return(result);
        }
예제 #29
0
        public void AttachAccessory(string accessoryObjPath, string accessoryMaterialPath, ManType manType)
        {
            var objModel = ObjLoader.LoadObjFile(accessoryObjPath, false);

            if (objModel == null)
            {
                return;
            }

            var mesh = PickingController.LoadAccessoryMesh(objModel);

            if (string.IsNullOrEmpty(accessoryMaterialPath))
            {
                mesh.Material.DiffuseColor = new Vector4(0.5f, 0.4f, 0.3f, 1);
            }
            else
            {
                mesh.Material.DiffuseTextureMap = accessoryMaterialPath;
            }

            var objName = Path.GetFileNameWithoutExtension(accessoryObjPath);

            if (AccessoryPositions.ContainsKey(objName))
            {
                var meshSize = AccessoryPositions[objName].Item2;

                var s = AccessoryPositions[objName].Item1 * ProgramCore.Project.RenderMainHelper.headMeshesController.RenderMesh.MorphScale;         // домножаем на 8 для веб версии. все на 8 домножаем! любим 8!

                mesh.Position        += new Vector3(s[0], s[1], s[2]);
                mesh.Transform[3, 0] += s[0];
                mesh.Transform[3, 1] += s[1];
                mesh.Transform[3, 2] += s[2];

                if (!float.IsNaN(meshSize))
                {
                    mesh.Transform[3, 0] -= s[0]; // применяем изменение размера
                    mesh.Transform[3, 1] -= s[1];
                    mesh.Transform[3, 2] -= s[2];
                    mesh.Transform       *= Matrix4.CreateScale(meshSize / mesh.MeshSize);
                    mesh.Transform[3, 0] += s[0];
                    mesh.Transform[3, 1] += s[1];
                    mesh.Transform[3, 2] += s[2];
                    mesh.IsChanged        = true;
                    mesh.MeshSize         = meshSize;
                }
            }

            ProgramCore.Project.RenderMainHelper.pickingController.AccesoryMeshes.Add(mesh);
        }
예제 #30
0
        private void PluginMorphToSmile(List <MeshPartInfo> meshesInfo, GenesisType genesisType, ManType manType, float scale)
        {
            var lastTriangle = 0;
            var path         = Path.Combine(Application.StartupPath, "Models", "Model", genesisType.GetGenesisPath(), manType.GetObjPathSmilePlugin());
            var objModel     = ObjLoader.LoadObjFile(path, true, true);
            var smileMeshes  = LoadHeadMeshes(objModel, false, manType, scale, ref lastTriangle);

            /*var a0 = new Vector3(99999.0f, 99999.0f, 99999.0f);
             * var b0 = new Vector3(-99999.0f, -99999.0f, -99999.0f);
             * foreach (var meshPartInfo in meshesInfo)
             * {
             *  GetAABB(ref a0, ref b0, meshPartInfo.VertexPositions);
             * }
             * var a1 = new Vector3(99999.0f, 99999.0f, 99999.0f);
             * var b1 = new Vector3(-99999.0f, -99999.0f, -99999.0f);
             * foreach (var meshPartInfo in smileMeshes)
             * {
             *  GetAABB(ref a1, ref b1, meshPartInfo.VertexPositions);
             * }
             * var dist0 = (b0 - a0).Length;
             * var dist1 = (b1 - a1).Length;
             * var center0 = (b0 + a0) * 0.5f;
             * var center1 = (b1 + a1) * 0.5f;*/

            float k = 265.4678407f; //! Вот это нужно подобрать
            //dist1 / dist0;

            float MaxY0 = -99999.0f;
            float MaxY1 = -99999.0f;

            foreach (var meshInfo in meshesInfo)
            {
                for (int i = 0; i < meshInfo.VertexPositions.Count; ++i)
                {
                    MaxY0 = Math.Max(MaxY0, meshInfo.VertexPositions[i].Y);
                }
            }

            foreach (var meshInfo in meshesInfo)
            {
                var mesh = smileMeshes.FirstOrDefault(m => m.PartName == meshInfo.PartName);
                if (mesh.VertexPositions.Count == meshInfo.VertexPositions.Count)
                {
                    for (int i = 0; i < mesh.VertexPositions.Count; ++i)
                    {
                        //meshInfo.VertexPositions[i] = center0 + (mesh.VertexPositions[i] - center1) * k;
                        meshInfo.VertexPositions[i] = mesh.VertexPositions[i] / k;
                        MaxY1 = Math.Max(MaxY1, meshInfo.VertexPositions[i].Y);
                    }
                }
            }

            foreach (var meshInfo in meshesInfo)
            {
                for (int i = 0; i < meshInfo.VertexPositions.Count; ++i)
                {
                    Vector3 v = meshInfo.VertexPositions[i];
                    v.Y += (MaxY0 - MaxY1);
                    meshInfo.VertexPositions[i] = v;
                }
            }
        }
예제 #31
0
파일: Project.cs 프로젝트: wiplug/HeadShop
        /// <summary> Создание нового проекта </summary>
        /// <param name="projectName"></param>
        /// <param name="projectPath"></param>
        /// <param name="templateImageName"></param>
        /// <param name="manType"></param>
        /// <param name="headModelPath">Указываем путь до модели головы (в случае если выбрали import OBJ). Иначе - пустая строка</param>
        /// <param name="needCopy"></param>
        public Project(string projectName, string projectPath, string templateImageName, ManType manType, string headModelPath, bool needCopy)
        {
            ProjectName = projectName;
            ProjectPath = projectPath;

            ManType = manType;
            switch (manType)
            {
            case ManType.Male:
            case ManType.Female:             // если это обычные модели - копируем их из папки с прогой - в папку с проектом
            case ManType.Child:
                if (!ProgramCore.PluginMode) //тогда хед модел пас оставляем какой был! пиздец важно!
                {
                    headModelPath = Path.Combine(Application.StartupPath, "Models\\Model", manType.GetObjPath());
                }
                break;

            case ManType.Custom:
            {
                BaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetBaseDots(ManType.Female))
                {
                    BaseDots.Add(new HeadPoint(vector));
                }

                ProfileBaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetProfileBaseDots(ManType.Female))
                {
                    ProfileBaseDots.Add(new HeadPoint(vector));
                }
            }
            break;
            }

            if (needCopy)
            {
                var di = new DirectoryInfo(projectPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                if (!string.IsNullOrEmpty(templateImageName))
                {
                    var fi = new FileInfo(templateImageName);
                    if (fi.Exists)
                    {
                        var newImagePath = Path.Combine(projectPath, fi.Name);
                        File.Copy(templateImageName, newImagePath, true);
                        FrontImagePath = fi.Name;
                    }
                }

                #region Копируем модель

                var directoryPath = Path.Combine(ProjectPath, "Model");
                FolderEx.CreateDirectory(directoryPath);
                var oldFileName = Path.GetFileNameWithoutExtension(headModelPath);
                var newFileName = oldFileName;
                var filePath    = Path.Combine(directoryPath, newFileName + ".obj");

                File.Copy(headModelPath, filePath, true);           // сама модель
                HeadModelPath = filePath;

                #region Обрабатываем mtl файл и папку с текстурами

                var mtl = oldFileName + ".mtl";
                using (var ms = new StreamReader(headModelPath))
                {
                    for (var i = 0; i < 10; i++)
                    {
                        if (ms.EndOfStream)
                        {
                            break;
                        }
                        var line = ms.ReadLine();
                        if (line.ToLower().Contains("mtllib"))          // ищем ссылку в obj файле на mtl файл (у них могут быть разные названия, но всегда в одной папке
                        {
                            var lines = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                            if (lines.Length > 1)
                            {
                                mtl = lines[1];
                                break;
                            }
                        }
                    }
                }

                ObjLoader.CopyMtl(mtl, mtl, Path.GetDirectoryName(headModelPath), "", directoryPath);

                #endregion

                #endregion
            }
            else
            {
                FrontImagePath = templateImageName;
                HeadModelPath  = headModelPath;
            }

            var modelPath = Path.Combine(projectPath, "OBJ", "hair.obj");
            ProgramCore.MainForm.ctrlRenderControl.LoadModel(modelPath, true, ManType, MeshType.Hair);

            var acDirPath     = Path.GetDirectoryName(modelPath);
            var acName        = Path.GetFileNameWithoutExtension(modelPath) + "_accessory.obj";
            var accessoryPath = Path.Combine(acDirPath, acName);
            if (File.Exists(accessoryPath))
            {
                ProgramCore.MainForm.ctrlRenderControl.LoadModel(accessoryPath, false, ManType, MeshType.Accessory);
            }
        }
예제 #32
0
 public List <DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, GenesisType genesisType, ManType manType, bool needExporter, bool isOpenSmile)
 {
     return(AddMehes(path, type, fromDragAndDrop, genesisType, manType, string.Empty, needExporter, isOpenSmile));
 }