Beispiel #1
0
    public static void ExportMesh()
    {
        Transform[] selection = Selection.GetTransforms(SelectionMode.Unfiltered);

        if (selection.Length == 0)
        {
            EditorUtility.DisplayDialog(WindowTitle, "Please select a transform that contains a SkinnedMeshRenderer you wish to export.", "Ok");
            return;
        }

        Transform           root = selection[0];
        SkinnedMeshRenderer mesh = (SkinnedMeshRenderer)root.GetComponentInChildren(typeof(SkinnedMeshRenderer));

        //Animation anim = (Animation) root.GetComponent(typeof(Animation));

        if (mesh == null)
        {
            EditorUtility.DisplayDialog(WindowTitle, "No SkinnedMeshRenderer found in the currently selected transform!", "Ok");
            return;
        }

        string scriptName = mesh.name + ".py";
        string scriptPath = EditorUtility.SaveFilePanel("Export to Python script", "", scriptName, "py");

        if (scriptPath.Length == 0)
        {
            return;
        }

        StreamWriter w = new StreamWriter(scriptPath, false);

        using (w) {
            Mesh2BPY m2bpy = new Mesh2BPY(mesh, w);
            m2bpy.WriteHeader();
            m2bpy.WriteGeometry();
            m2bpy.WriteTransforms();
            //m2bpy.WriteAnimations(anim);
        }

        EditorUtility.DisplayDialog(WindowTitle, "Finished writing " + scriptName, "Ok");
    }
	public static void ExportMesh() {
		Transform[] selection = Selection.GetTransforms(SelectionMode.Unfiltered);
		
		if (selection.Length == 0) {
			EditorUtility.DisplayDialog(WindowTitle, "Please select a transform that contains a SkinnedMeshRenderer you wish to export.", "Ok");
			return;
		}
		
		Transform root = selection[0];
   		SkinnedMeshRenderer mesh = (SkinnedMeshRenderer) root.GetComponentInChildren(typeof(SkinnedMeshRenderer));
		//Animation anim = (Animation) root.GetComponent(typeof(Animation));

		if (mesh == null) {
			EditorUtility.DisplayDialog(WindowTitle, "No SkinnedMeshRenderer found in the currently selected transform!", "Ok");
			return;
		}

		string scriptName = mesh.name + ".py";
		string scriptPath = EditorUtility.SaveFilePanel("Export to Python script", "", scriptName, "py");
		
		if (scriptPath.Length == 0) {
			return;
		}
		
		StreamWriter w = new StreamWriter(scriptPath, false);
			
		using (w) {
			Mesh2BPY m2bpy = new Mesh2BPY(mesh, w);
			m2bpy.WriteHeader();
			m2bpy.WriteGeometry();
			m2bpy.WriteTransforms();
			//m2bpy.WriteAnimations(anim);
		}
		
		EditorUtility.DisplayDialog(WindowTitle, "Finished writing " + scriptName, "Ok");
	}
    public static void ExportMesh()
    {
        SkinnedMeshRenderer meshRenderer = GetSelectedMesh();

        if (meshRenderer == null) {
            EditorUtility.DisplayDialog("Error", "Please select a skinned mesh renderer you wish to export.", "Ok");
            return;
        }

        string scriptName = meshRenderer.name + ".py";
        string scriptPath = EditorUtility.SaveFilePanel("Export to Blender script", "", scriptName, "py");

        if (scriptPath.Length == 0) {
            return;
        }

        StreamWriter w = new StreamWriter(scriptPath, false);

        using (w) {
            Mesh2BPY m2bpy = new Mesh2BPY(meshRenderer, w);
            m2bpy.WriteHeader();
            m2bpy.WriteMeshBuilder();
            m2bpy.WriteSkeletonBuilder();
            m2bpy.WriteSkinBuilder();
            m2bpy.WriteModelBuilder();
            m2bpy.WriteFooter();
        }

        EditorUtility.DisplayDialog("Mesh2BPY", "Finished writing " + scriptName, "Ok");
    }