コード例 #1
0
ファイル: ModelWindow.cs プロジェクト: icynare/ModelEditor
    private void Init()
    {
        parentObj = GameObject.Find("Parent");
        camera    = GameObject.Find("Main Camera").transform;
        pillar    = GameObject.Find("Pillar").transform;

        ball      = GameObject.Find("Ball");
        ballScale = ball.transform.localScale.x;
        newScale  = ballScale.ToString();

        newSpeed    = PlayerPrefs.GetFloat(PrefConstans.RORATE_SPEED, PrefConstans.DEFAULT_SPEED).ToString();
        newWidth    = PlayerPrefs.GetFloat(PrefConstans.GAMEOBJECT_WIDTH, PrefConstans.DEFAULT_WIDTH).ToString();
        newGravity  = PlayerPrefs.GetFloat(PrefConstans.GRAVITY, PrefConstans.DEFAULT_GRAVITY).ToString();
        newUpSpeed  = PlayerPrefs.GetFloat(PrefConstans.UP_SPEED, PrefConstans.DEFAULT_UP_SPEED).ToString();
        newUpHeight = PlayerPrefs.GetFloat(PrefConstans.UP_DISTANCE, PrefConstans.DEFAULT_UP_DISTANCE).ToString();
        newGap      = PlayerPrefs.GetFloat(PrefConstans.GAMEOBJECT_GAP, PrefConstans.DEFAULT_GAP).ToString();
        newUpSingle = PlayerPrefs.GetFloat(PrefConstans.UP_SINGLE, PrefConstans.DEFAULT_UP_SINGLE).ToString();

        objSaver = new ObjSaver();
        objSaver.Init();
        objData = objSaver.Load();
        SetArrData();

        cubePrefab     = Resources.Load <GameObject>("Models/Cube");
        cylinderPrefab = Resources.Load <GameObject>("Models/Cylinder");

        objCreater = new CreateObj();

        objList = new List <GameObject>();
        InitSavedObj();
        //for (int i = 0; i < parentObj.transform.childCount; i++)
        //{
        //    objList.Add(parentObj.transform.GetChild(i).gameObject);
        //}
    }
コード例 #2
0
        public void ExecuteOption(int option)
        {
            switch (option)
            {
            case 1:
                MenuController.GoToPizzaSelectMenu(currentOrder);
                break;

            case 2:
                currentOrder.CalculateOrderTotal();
                if (currentOrder.OrderTotal > 250 || currentOrder.PizzasOnOrder.Count > 50)
                {
                    Messenger.OrderError();
                }
                else
                {
                    ObjSaver.SaveOrder(currentOrder);
                    Messenger.OrderPlacedMessage();
                    MenuController.GoToMainMenu(currentOrder.customer);
                }
                break;

            case 3:
                MenuController.GoToRemoveItemMenu(currentOrder);
                break;
            }
        }
コード例 #3
0
    /// <summary>
    /// Update method performs actions each frame.
    /// </summary>
    void Update()
    {
        if (buildMinimap)
        {
            buildMinimap = false;
            yUp          = true;

            foreach (Transform child in mapObject.transform)
            {
                Transform miniChild = Instantiate(child, miniMapObject.transform);
                miniChild.gameObject.AddComponent <BoxCollider>();
            }
        }

        if (manipulationModeCountdown >= 1)
        {
            manipulationModeCountdown--;
            if (manipulationModeCountdown == 0)
            {
                enterManipulate();
            }
        }

        if (save)
        {
            save = false;

            ObjSaver.Save(SpatialMappingManager.Instance.GetMeshFilters(), saveStream);
            spatialMappingObject.SetActive(SpatialMappingActive);
            txt.text = "Spatial mapping saved to " + saveFileDisplayName;
        }

        if (load)
        {
            load = false;

            miniMapObject.transform.localScale = initialMiniMapScale;

            // empty map and mini map
            foreach (Transform child in mapObject.transform)
            {
                Destroy(child.gameObject);
            }
            foreach (Transform child in miniMapObject.transform)
            {
                Destroy(child.gameObject);
            }

            Material material = Resources.Load("defaultMat", typeof(Material)) as Material;

            ObjLoader.LoadOBJFile(loadFileDisplayName, material, loadStream, mapObject);

            buildMinimap = true;
            leaveManipulate();
            enterModelOverlay();
            rdd.enabled = false;
            txt.text    = "Mesh \"" + loadFileDisplayName + "\" loaded.";
        }
    }
コード例 #4
0
        static void Main(string[] args)
        {
            Messenger.WelcomeMessage();

            var newCustomer = Login.GetCustomer();

            DataAccessor.PersistCustomer(ObjSaver.SendCustomerToMapper(newCustomer));

            MenuController.GoToMainMenu(newCustomer);
        }
コード例 #5
0
        //private void DrawToTexture(int oldTextureId, int textureId)
        //{
        //    var parts = headMeshesController.RenderMesh.Parts.Where(p => p.Texture == textureId);
        //    foreach (var part in parts)
        //    {
        //        foreach(var v in part.Vertices)
        //    }
        //}

        /*
         * public void DrawToTexture(IEnumerable<RenderMeshPart> parts)
         * {
         #if (WEB_APP)
         #else
         *  GL.Color3(1.0f, 1.0f, 1.0f);
         *  GL.EnableClientState(ArrayCap.VertexArray);
         *  GL.EnableClientState(ArrayCap.NormalArray);
         *  GL.EnableClientState(ArrayCap.TextureCoordArray);
         *
         *  foreach (var part in parts)
         *  {
         *      GL.BindBuffer(BufferTarget.ArrayBuffer, part.VertexBuffer);
         *      GL.BindBuffer(BufferTarget.ElementArrayBuffer, part.IndexBuffer);
         *
         *      GL.VertexPointer(2, VertexPointerType.Float, Vertex3d.Stride, new IntPtr(2 * Vector3.SizeInBytes)); //Как позицию используем основные текстурные координаты
         *      GL.NormalPointer(NormalPointerType.Float, Vertex3d.Stride, new IntPtr(0));//Как нормаль используем позиции (координата Z потребуется для вычисления смешивания
         *      GL.TexCoordPointer(3, TexCoordPointerType.Float, Vertex3d.Stride, new IntPtr(2 * Vector3.SizeInBytes + Vector2.SizeInBytes + Vector4.SizeInBytes));//Как текстурные координаты берем дополнительные текстурные координаты
         *
         *      GL.DrawRangeElements(PrimitiveType.Triangles, 0, part.CountIndices, part.CountIndices, DrawElementsType.UnsignedInt, new IntPtr(0));
         *  }
         *
         *  GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
         *  GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
         *  GL.DisableClientState(ArrayCap.VertexArray);
         *  GL.DisableClientState(ArrayCap.NormalArray);
         *  GL.DisableClientState(ArrayCap.TextureCoordArray);
         #endif
         * }
         */

        //private bool DrawToTexture(ShaderController shader, int oldTextureId, int textureId)
        //{
        //    //GL.BindTexture(TextureTarget.Texture2D, oldTextureId);
        //    DrawQuad(ProgramCore.Project.FaceColor.X, ProgramCore.Project.FaceColor.Y, ProgramCore.Project.FaceColor.Z, 1f);
        //    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
        //    GL.Enable(EnableCap.Blend);

        //    shader.Begin();

        //    GL.ActiveTexture(TextureUnit.Texture0);
        //    GL.BindTexture(TextureTarget.Texture2D, HeadTextureId);
        //    shader.UpdateUniform("u_Texture", 0);
        //    shader.UpdateUniform("u_BlendStartDepth", -0.5f);
        //    shader.UpdateUniform("u_BlendDepth", 4f);

        //    headMeshesController.RenderMesh.DrawToTexture(headMeshesController.RenderMesh.Parts.Where(p => p.Texture == textureId));

        //    shader.End();
        //    GL.Disable(EnableCap.Blend);
        //    return true;
        //}

        //public Bitmap RenderToTexture(int oldTextureId, int textureId, int textureWidth, int textureHeight, ShaderController shader,
        //    Func<ShaderController, int, int, bool> renderFunc, bool useAlpha = false)
        //{
        //    graphicsContext.MakeCurrent(windowInfo);
        //    renderPanel.Size = new Size(textureWidth, textureHeight);
        //    GL.Viewport(0, 0, textureWidth, textureHeight);

        //    GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        //    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

        //    GL.MatrixMode(MatrixMode.Projection);
        //    GL.PushMatrix();
        //    GL.LoadIdentity();
        //    GL.MatrixMode(MatrixMode.Modelview);
        //    GL.LoadIdentity();

        //    GL.Enable(EnableCap.Texture2D);
        //    GL.DepthMask(false);

        //    renderFunc(shader, oldTextureId, textureId);

        //    GL.DepthMask(true);
        //    GL.BindTexture(TextureTarget.Texture2D, 0);
        //    GL.MatrixMode(MatrixMode.Projection);
        //    GL.PopMatrix();

        //    var result = GrabScreenshot(String.Empty, textureWidth, textureHeight, useAlpha);
        //    glControl.Context.MakeCurrent(glControl.WindowInfo);
        //    SetupViewport(glControl);
        //    return result;
        //}

        //public Bitmap GrabScreenshot(string filePath, int width, int height, bool useAlpha = false)
        //{
        //    var bmp = new Bitmap(width, height);
        //    var rect = new Rectangle(0, 0, width, height);
        //    var data = bmp.LockBits(rect, ImageLockMode.WriteOnly, useAlpha ? PixelFormat.Format32bppArgb : PixelFormat.Format24bppRgb);
        //    GL.ReadPixels(0, 0, width, height, useAlpha ? OpenTK.Graphics.OpenGL.PixelFormat.Bgra : OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0);
        //    GL.Finish();
        //    bmp.UnlockBits(data);
        //    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

        //    if (!string.IsNullOrEmpty(filePath))
        //        bmp.Save(filePath, ImageFormat.Jpeg);
        //    return bmp;
        //}


        public void SaveHead(string path, bool saveBrushesToTexture = false)
        {
            try
            {
                /*if (ProgramCore.Project.AutodotsUsed)
                 *  SaveBlendingTextures();*/

                ObjSaver.SaveObjFile(path, headMeshesController.RenderMesh, MeshType.Hair, pickingController.ObjExport, ProgramCore.Project.ProjectName, saveBrushesToTexture);
            }
            finally
            {
                //SaveSmoothedTextures();
            }
        }
コード例 #6
0
ファイル: ModelWindow.cs プロジェクト: icynare/ModelEditor
    public static void ClearData()
    {
        if (EditorUtility.DisplayDialog("清空", "是否清空当前所有模型", "清空", "取消"))
        {
            //PlayerPrefs.DeleteAll();

            Transform parent = GameObject.Find("Parent").transform;
            Transform camera = GameObject.Find("Main Camera").transform;
            Transform pillar = GameObject.Find("Pillar").transform;
            for (int i = parent.childCount - 1; i >= 0; i--)
            {
                DestroyImmediate(parent.GetChild(i).gameObject);
            }
            ObjSaver.DeleteData();
            camera.transform.localPosition = new Vector3(0, Ball.CAMERA_INIT_HEIGHT, camera.transform.localPosition.z);
            pillar.transform.localPosition = new Vector3(0, Ball.PILLAR_INIT_HEIGHT, 0);
        }
    }
コード例 #7
0
        public void SaveMergedHead(string path, ZipOutputStream zipStream, int size)
        {
            //var importer = new AssimpImporter(); // assimp doesn't work
            //importer.ConvertFromFileToFile(Path.Combine(@"C:\elance\github\test\1\optsplvukfnc3tovb5pwdlq0_1\optsplvukfnc3tovb5pwdlq0.obj"), Path.Combine(@"C:\elance\github\test\1\1.dae"), "collada");

            var meshInfos = new List <MeshInfo>();

            foreach (var part in headMeshesController.RenderMesh.Parts)
            {
                meshInfos.Add(new MeshInfo(part, headMeshesController.RenderMesh.MorphScale));
            }

            var realScale = GetRealScale(size, pickingController.HairMeshes, pickingController.AccesoryMeshes, meshInfos);

            var isCollada = zipStream != null;

            ObjSaver.ExportMergedModel(path, pickingController.HairMeshes, pickingController.AccesoryMeshes, meshInfos, realScale, ProgramCore.Project.ProjectName, isCollada, isCollada, zipStream);
        }
コード例 #8
0
        private void SaveObj(string fiName)
        {
            var haPath    = Path.GetFileNameWithoutExtension(fiName) + "hair.obj";
            var hairPath  = Path.Combine(ProgramCore.Project.ProjectPath, haPath);
            var realScale = ProgramCore.PluginMode ? 1.0f : ProgramCore.Project.RenderMainHelper.headMeshesController.RenderMesh.RealScale;

            ObjSaver.SaveObjFile(hairPath, pickingController.HairMeshes, MeshType.Hair, realScale, ProgramCore.Project.ManType, ProgramCore.Project.ProjectName, true);

            if (pickingController.AccesoryMeshes.Count > 0)            // save accessories to separate file
            {
                var acName = Path.GetFileNameWithoutExtension(fiName) + "_accessory.obj";

                var accessoryPath = Path.Combine(ProgramCore.Project.ProjectPath, acName);
                ObjSaver.SaveObjFile(accessoryPath, pickingController.AccesoryMeshes, MeshType.Accessory, realScale, ProgramCore.Project.ManType, ProgramCore.Project.ProjectName, true);
            }

            SaveHead(fiName, true);
        }
コード例 #9
0
        /// <summary> Save current project to file </summary>
        public void ToStream()
        {
            try
            {
                if (ProgramCore.Project.AutodotsUsed)
                {
                    ProgramCore.MainForm.ctrlRenderControl.SaveSmoothedTextures(false);
                    ProgramCore.MainForm.ctrlRenderControl.SaveBrushTextures();
                }

                var path = Path.Combine(ProjectPath, string.Format("{0}.hds", ProjectName));
                using (var bw = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)))
                {
                    bw.Write(ProjectName);
                    bw.Write(FrontImagePath);

                    bw.Write(HeadModelPath);

                    bw.Write((int)GenesisType);
                    bw.Write((int)ManType);
                    bw.Write((int)TextureFlip);
                    bw.Write((int)ShapeFlip);

                    bw.Write(IsOpenSmile);

                    var fiName = Path.Combine(ProjectPath, "OBJ", "hair.obj");
                    FolderEx.CreateDirectory(Path.GetDirectoryName(fiName));
                    if (ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes.Count > 0) // save hair file
                    {
                        ObjSaver.SaveObjFile(fiName, ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes,
                                             MeshType.Hair, 1.0f, ManType, ProgramCore.Project.ProjectName);
                    }
                    else
                    {
                        FolderEx.DeleteSafety(fiName);      // если раньше были волосы , а сейчас удалили - надо их грохнуть из папки тоже
                    }
                    var acDirPath     = Path.GetDirectoryName(fiName);
                    var acName        = Path.GetFileNameWithoutExtension(fiName) + "_accessory.obj";
                    var accessoryPath = Path.Combine(acDirPath, acName);
                    if (ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes.Count > 0)
                    {
                        // save accessory file
                        ObjSaver.SaveObjFile(accessoryPath,
                                             ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes, MeshType.Accessory, 1.0f, ManType, ProgramCore.Project.ProjectName);
                    }
                    else
                    {
                        FolderEx.DeleteSafety(accessoryPath);
                    }

                    var partsLibraryPath = Path.Combine(ProjectPath, "Parts Library");
                    FolderEx.CreateDirectory(partsLibraryPath);

                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.Count(x => x.Value.Count > 0)); // save list of meshes to part's library
                    foreach (var part in ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes)
                    {
                        if (part.Value.Count == 0)
                        {
                            continue;
                        }

                        bw.Write(part.Key);
                        bw.Write(part.Value[0].meshType == MeshType.Accessory);
                        bw.Write(part.Value[0].IsVisible);
                        bw.Write(part.Value[0].Path);

                        bw.Write(part.Value.Count);
                        foreach (var selMesh in part.Value)
                        {
                            bw.Write(selMesh.Title);
                        }

                        var fileName = part.Key + ".obj";
                        ObjSaver.SaveObjFile(Path.Combine(partsLibraryPath, fileName), part.Value, part.Value[0].meshType, 1.0f, ManType, ProgramCore.Project.ProjectName);
                    }

                    bw.Write(AutodotsUsed);

                    bw.Write(RotatedAngle);

                    // сохраняем прямоугольник лица
                    bw.Write(FaceRectRelative.X);
                    bw.Write(FaceRectRelative.Y);
                    bw.Write(FaceRectRelative.Width);
                    bw.Write(FaceRectRelative.Height);

                    // сохраняем центры рта и глаз распознаные
                    bw.Write(MouthCenter.X);
                    bw.Write(MouthCenter.Y);

                    bw.Write(LeftEyeCenter.X);
                    bw.Write(LeftEyeCenter.Y);
                    bw.Write(RightEyeCenter.X);
                    bw.Write(RightEyeCenter.Y);

                    // сохраняем центры рта и глаз пользовательские (после таскания и прочего)
                    bw.Write(NoseUserCenter.X);
                    bw.Write(NoseUserCenter.Y);
                    bw.Write(MouthUserCenter.X);
                    bw.Write(MouthUserCenter.Y);

                    bw.Write(LeftEyeUserCenter.X);
                    bw.Write(LeftEyeUserCenter.Y);
                    bw.Write(RightEyeUserCenter.X);
                    bw.Write(RightEyeUserCenter.Y);

                    bw.Write(AgeCoefficient);
                    bw.Write(FatCoefficient);

                    //Сохраняем цвет головы
                    bw.Write(FaceColor.X);
                    bw.Write(FaceColor.Y);
                    bw.Write(FaceColor.Z);

                    #region Информация о модели головы

                    var rmPath = Path.Combine(ProjectPath, "Model", "MeshParts.rm");

                    #region Сохранение RenderMesh

                    if (ManType != ManType.Custom)
                    {
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.OldMorphing) // перед сохранением сбрасываем морфинги на 0.
                        {
                            m.Value.Delta = 0;
                        }
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.FatMorphing)
                        {
                            m.Value.Delta = 0;
                        }
                        //     ProgramCore.MainForm.ctrlRenderControl.DoMorth();
                    }

                    ProgramCore.Project.RenderMainHelper.headMeshesController.RenderMesh.Save(rmPath);

                    if (ManType != ManType.Custom)
                    {
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.OldMorphing) // перед сохранением сбрасываем морфинги на 0.
                        {
                            m.Value.Delta = AgeCoefficient;
                        }
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.FatMorphing)
                        {
                            m.Value.Delta = FatCoefficient;
                        }
                        //   ProgramCore.MainForm.ctrlRenderControl.DoMorth();
                    }

                    #endregion

                    if (BaseDots != null)
                    {
                        bw.Write(BaseDots.Count);
                        foreach (var point in BaseDots)
                        {
                            point.ToStream(bw);
                        }
                    }
                    else
                    {
                        bw.Write(0);
                    }

                    if (ProfileBaseDots != null)
                    {
                        bw.Write(ProfileBaseDots.Count);
                        foreach (var point in ProfileBaseDots)
                        {
                            point.ToStream(bw);
                        }
                    }
                    else
                    {
                        bw.Write(0);
                    }

                    RenderMainHelper.autodotsShapeHelper.ShapeInfo.ToStream(bw);
                    RenderMainHelper.autodotsShapeHelper.ShapeProfileInfo.ToStream(bw);

                    ProgramCore.Project.RenderMainHelper.headMeshesController.TexturingInfo.ToStream(bw);


                    bw.Write(ProgramCore.Project.RenderMainHelper.headController.ShapeDots.Count);
                    foreach (var dot in ProgramCore.Project.RenderMainHelper.headController.ShapeDots)
                    {
                        dot.ToStreamM(bw);
                    }
                    bw.Write(ProgramCore.Project.RenderMainHelper.headController.AutoDotsv2.Count);
                    foreach (var dot in ProgramCore.Project.RenderMainHelper.headController.AutoDotsv2)
                    {
                        dot.ToStream(bw);
                    }

                    bw.Write(CustomHeadNeedProfileSetup);

                    #endregion

                    bw.Write(ProfileEyeLocation.X);
                    bw.Write(ProfileEyeLocation.Y);
                    bw.Write(ProfileMouthLocation.X);
                    bw.Write(ProfileMouthLocation.Y);

                    if (!string.IsNullOrEmpty(ProgramCore.MainForm.ctrlRenderControl.BackgroundTexture))
                    {
                        bw.Write(true);
                        bw.Write(ProgramCore.MainForm.ctrlRenderControl.BackgroundTexture);
                    }
                    else
                    {
                        bw.Write(false);
                    }
                    bw.Write(ProgramCore.MainForm.activePanel);

                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.camera.Scale);
                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.camera.beta);
                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.camera._dy);

                    bw.Write(MorphingScale);

                    bw.Write(TextureSize);
                }
            }
            catch (Exception e)
            {
                ProgramCore.EchoToLog(e, true);
            }
        }