Ejemplo n.º 1
0
        public static void LoadT()
        {
            CleanAssetDatabase();
            string path = EditorUtility.OpenFilePanel("Overwrite with png", "", "*");

            Debug.Log(path);
            var model_agent = new ModelAgent(path);

            MMD.PMX.PMXFormat pmx_format;
            try
            {
                //PMX読み込みを試みる
                pmx_format = PMXLoaderScript.Import(model_agent.file_path_);
            }
            catch
            {
                //PMXとして読み込めなかったら
                //PMDとして読み込む
                MMD.PMD.PMDFormat pmd_format = PMDLoaderScript.Import(model_agent.file_path_);
                pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
            }

            var fbxGameObject = MMD.PMXConverter.CreateGameObject(pmx_format, false, MMD.PMXConverter.AnimationType.LegacyAnimation, false, 1f);

            fbxGameObject.transform.SetParent(GameObject.Find("Parent").transform);
            fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Create pmx from pmx list
        /// </summary>
        private void CreatePmx()
        {
            var       model_agent = new ModelAgent(Statement.PmxFiles[Statement.CurrentPmx]);
            PMXFormat pmx_format;

            try
            {
                //PMX読み込みを試みる
                pmx_format = PMXLoaderScript.Import(model_agent.file_path_);
            }
            catch
            {
                //PMXとして読み込めなかったら
                //PMDとして読み込む
                var pmd_format = PMDLoaderScript.Import(model_agent.file_path_);
                pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
            }

            fbxGameObject = PMXConverter.CreateGameObject(pmx_format, false, PMXConverter.AnimationType.LegacyAnimation,
                                                          false, 1f);

            fbxGameObject.transform.SetParent(GameObject.Find("Parent").transform);
            fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// プレファブを作成する
        /// </summary>
        /// <param name='shader_type'>シェーダーの種類</param>
        /// <param name='use_rigidbody'>剛体を使用するか</param>
        /// <param name='animation_type'>アニメーションタイプ</param>
        /// <param name='use_ik'>IKを使用するか</param>
        /// <param name='scale'>スケール</param>
        /// <param name='is_pmx_base_import'>PMX Baseでインポートするか</param>
        public void CreatePrefab(PMDConverter.ShaderType shader_type, bool use_rigidbody, PMXConverter.AnimationType animation_type, bool use_ik, float scale, bool is_pmx_base_import)
        {
            GameObject game_object;
            string     prefab_path;

            if (is_pmx_base_import)
            {
                //PMX Baseでインポートする
                //PMXファイルのインポート
                PMX.PMXFormat pmx_format = null;
                try {
                    //PMX読み込みを試みる
                    pmx_format = PMXLoaderScript.Import(file_path_);
                } catch (System.FormatException) {
                    //PMXとして読み込めなかったら
                    //PMDとして読み込む
                    PMD.PMDFormat pmd_format = PMDLoaderScript.Import(file_path_);
                    pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
                }
                header_ = pmx_format.header;
                //ゲームオブジェクトの作成
                game_object = PMXConverter.CreateGameObject(pmx_format, use_rigidbody, animation_type, use_ik, scale);

                // プレファブパスの設定
                prefab_path = pmx_format.meta_header.folder + "/" + pmx_format.meta_header.name + ".prefab";
            }
            else
            {
                //PMXエクスポーターを使用しない
                //PMDファイルのインポート
                PMD.PMDFormat pmd_format = null;
                try {
                    //PMX読み込みを試みる
                    PMX.PMXFormat pmx_format = PMXLoaderScript.Import(file_path_);
                    pmd_format = PMXLoaderScript.PMX2PMD(pmx_format);
                } catch (System.FormatException) {
                    //PMXとして読み込めなかったら
                    //PMDとして読み込む
                    pmd_format = PMDLoaderScript.Import(file_path_);
                }
                header_ = PMXLoaderScript.PMD2PMX(pmd_format.head);

                //ゲームオブジェクトの作成
                bool use_mecanim = PMXConverter.AnimationType.LegacyAnimation == animation_type;
                game_object = PMDConverter.CreateGameObject(pmd_format, shader_type, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブパスの設定
                prefab_path = pmd_format.folder + "/" + pmd_format.name + ".prefab";
            }
            // プレファブ化
            PrefabUtility.CreatePrefab(prefab_path, game_object, ReplacePrefabOptions.ConnectToPrefab);

            // アセットリストの更新
            AssetDatabase.Refresh();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// プレファブを作成する
        /// </summary>
        /// <param name='shader_type'>シェーダーの種類</param>
        /// <param name='use_rigidbody'>剛体を使用するか</param>
        /// <param name='use_mecanim'>Mecanimを使用するか</param>
        /// <param name='use_ik'>IKを使用するか</param>
        /// <param name='scale'>スケール</param>
        /// <param name='is_pmx_base_import'>PMX Baseでインポートするか</param>
        public void CreatePrefab(PMD.PMDConverter.ShaderType shader_type, bool use_rigidbody, bool use_mecanim, bool use_ik, float scale, bool is_pmx_base_import)
        {
            GameObject game_object;
            Object     prefab;

            if (is_pmx_base_import)
            {
                //PMX Baseでインポートする
                //PMXファイルのインポート
                PMX.PMXFormat format = PMXLoaderScript.Import(file_path_);
                //ゲームオブジェクトの作成
                game_object = PMXConverter.CreateGameObject(format, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブに登録
                prefab = PrefabUtility.CreateEmptyPrefab(format.meta_header.folder + "/" + format.meta_header.name + ".prefab");
            }
            else
            {
                //V2エクスポーターを使用しない
                //PMDファイルのインポート
                if (null == format_)
                {
                    //まだ読み込んでいないなら読むこむ
                    try {
                        //PMX読み込みを試みる
                        format_ = PMXLoaderScript.PmdImport(file_path_);
                    } catch (System.FormatException) {
                        //PMXとして読み込めなかったら
                        //PMDとして読み込む
                        format_ = PMDLoaderScript.Import(file_path_);
                    }
                    header_ = format_.head;
                }

                //ゲームオブジェクトの作成
                game_object = PMDConverter.CreateGameObject(format_, shader_type, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブに登録
                prefab = PrefabUtility.CreateEmptyPrefab(format_.folder + "/" + format_.name + ".prefab");
            }
            PrefabUtility.ReplacePrefab(game_object, prefab);

            // アセットリストの更新
            AssetDatabase.Refresh();

            // 一度,表示されているモデルを削除して新しくPrefabのインスタンスを作る
            GameObject.DestroyImmediate(game_object);
            PrefabUtility.InstantiatePrefab(prefab);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name='file'>読み込むファイルパス</param>
 public ModelAgent(string file_path)
 {
     if (string.IsNullOrEmpty(file_path))
     {
         throw new System.ArgumentException();
     }
     file_path_ = file_path;
     header_    = null;
     try {
         //PMX読み込みを試みる
         header_ = PMXLoaderScript.GetPmdHeader(file_path_);
     } catch (System.FormatException) {
         //PMXとして読み込めなかったら
         //PMDとして読み込む
         header_ = PMDLoaderScript.GetHeader(file_path_);
     }
     format_ = null;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Create pmx from pmx list
        /// </summary>
        private void CreatePmx()
        {
            var       modelAgent = new ModelAgent(CurrentMmdObject.FilePath);
            PMXFormat pmxFormat;

            try
            {
                pmxFormat = PMXLoaderScript.Import(modelAgent.file_path_);
            }
            catch
            {
                var pmdFormat = PMDLoaderScript.Import(modelAgent.file_path_);
                pmxFormat = PMXLoaderScript.PMD2PMX(pmdFormat);
            }

            _fbxGameObject = PMXConverter.CreateGameObject(pmxFormat, false, PMXConverter.AnimationType.LegacyAnimation,
                                                           false, 1f);

            _fbxGameObject.transform.SetParent(parent.transform);
            _fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            _fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Ejemplo n.º 7
0
	/// <summary>
	/// PMXファイルのインポート
	/// </summary>
	/// <param name='file_path'>PMDファイルのパス</param>
	/// <returns>内部形式データ</returns>
	public static PMXFormat Import(string file_path) {
		PMXLoaderScript loader = new PMXLoaderScript();
		return loader.Import_(file_path);
	}
Ejemplo n.º 8
0
	/// <summary>
	/// PMXファイルのヘッダー取得
	/// </summary>
	/// <param name='file_path'>PMDファイルのパス</param>
	/// <returns>ヘッダー</returns>
	public static PMXFormat.Header GetHeader(string file_path) {
		PMXLoaderScript loader = new PMXLoaderScript();
		return loader.GetHeader_(file_path);
	}
 public static PMXFormat LoadPmxMaterials(string path)
 {
     return(PMXLoaderScript.Import(path));
 }
Ejemplo n.º 10
0
    /// <summary>
    /// PMXファイルのインポート
    /// </summary>
    /// <param name='file_path'>PMDファイルのパス</param>
    /// <returns>内部形式データ</returns>
    public static PMXFormat Import(string file_path)
    {
        PMXLoaderScript loader = new PMXLoaderScript();

        return(loader.Import_(file_path));
    }
Ejemplo n.º 11
0
    /// <summary>
    /// PMXファイルのヘッダー取得
    /// </summary>
    /// <param name='file_path'>PMDファイルのパス</param>
    /// <returns>ヘッダー</returns>
    public static PMXFormat.Header GetHeader(string file_path)
    {
        PMXLoaderScript loader = new PMXLoaderScript();

        return(loader.GetHeader_(file_path));
    }
        /// <summary>
        /// Gets the thumbnail image
        /// </summary>
        /// <param name="width">The width of the image that should be returned.</param>
        /// <returns>
        /// The image for the thumbnail
        /// </returns>
        protected override Bitmap GetThumbnailImage(uint width)
        {
            //  Attempt to open the stream with a reader
            var pmx = PMXLoaderScript.Import(SelectedItemPath);

            MeshCreationInfo creation_info = CreateMeshCreationInfoSingle(pmx);

            var diffuseMat = MaterialHelper.CreateMaterial(Colors.Gray);

            var models = new Model3DGroup();

            for (int i = 0, i_max = creation_info.value.Length; i < i_max; ++i)
            {
                int[] indices = creation_info.value[i].plane_indices.Select(x => (int)creation_info.reassign_dictionary[x])
                                .ToArray();
                var mesh = new MeshGeometry3D
                {
                    Positions = new Point3DCollection(pmx.vertex_list.vertex.Select(x => x.pos)),

                    TextureCoordinates = new PointCollection(pmx.vertex_list.vertex.Select(x => new System.Windows.Point(x.uv.X, x.uv.Y)))
                };



                indices.ToList()
                .ForEach(x => mesh.TriangleIndices.Add(x));
                var textureIndex = pmx.material_list.material[creation_info.value[i].material_index].usually_texture_index;
                var texturePath  = pmx.texture_list.texture_file.ElementAtOrDefault((int)textureIndex);

                var material = diffuseMat;
                if (!string.IsNullOrWhiteSpace(texturePath))
                {
                    texturePath = Path.Combine(Path.GetDirectoryName(SelectedItemPath), texturePath);
                    //Log($"Texture found: {texturePath}");

                    if (!string.IsNullOrWhiteSpace(texturePath) && File.Exists(texturePath))
                    {
                        //  dds and tga
                        if (new string[] { ".dds", ".tga" }.Any(x => x.Equals(Path.GetExtension(texturePath))))
                        {
                            var bitmap = PFimToBitmap(texturePath);
                            material = MaterialHelper.CreateImageMaterial(Bitmap2BitmapImage(bitmap), 1);
                        }
                        else
                        {
                            material = MaterialHelper.CreateImageMaterial(BitmapImageFromFile(texturePath), 1);
                        }
                    }
                }

                models.Children.Add(new GeometryModel3D(mesh, material));
            }

            var sorting = new SortingVisual3D()
            {
                Content = models
            };

            var view = new HelixViewport3D();

            view.Children.Add(sorting);
            view.Camera.Position      = new Point3D(0, 15, -30);
            view.Camera.LookDirection = new Vector3D(0, -5, 30);

            view.Background = System.Windows.Media.Brushes.Transparent;

            view.Children.Add(new SunLight()
            {
                Altitude = 260
            });

            view.Children.Add(new DefaultLights());

            try
            {
                var bitmap = view.Viewport.RenderBitmap(width, width, new SolidColorBrush(Colors.Transparent));
                view.Children.Clear();
                view    = null;
                sorting = null;
                models  = null;
                GC.Collect();
                return(BitmapFromSource(bitmap));
            }
            catch (Exception exception)
            {
                view.Children.Clear();
                view    = null;
                sorting = null;
                models  = null;
                GC.Collect();
                LogError("An exception occurred Rendering bitmap.", exception);
                //MessageBox.Show(exception.Message);
                //MessageBox.Show(exception.StackTrace);
                return(null);
            }
        }