public static string GetObjPath(this ManType manType, bool isOpenSmile) { switch (manType) { case ManType.Male: return(Path.Combine(manType.GetObjDirPath(isOpenSmile), "Male.obj")); case ManType.Female: return(Path.Combine(manType.GetObjDirPath(isOpenSmile), "Fem.obj")); case ManType.Child: return(Path.Combine(manType.GetObjDirPath(isOpenSmile), "Child.obj")); default: return(string.Empty); } }
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); }
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; }
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); }