2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
33 using System.ComponentModel;
35 using System.Drawing.Imaging;
37 #if (COGBOT_LIBOMV || USE_STHREADS)
39 using Thread = ThreadPoolUtil.Thread;
40 using ThreadPool = ThreadPoolUtil.ThreadPool;
41 using Monitor = ThreadPoolUtil.Monitor;
43 using System.Threading;
44 using System.Windows.Forms;
47 using OpenMetaverse.StructuredData;
48 using OpenMetaverse.Assets;
49 using OpenMetaverse.Imaging;
53 public partial class ExportCollada : RadegastTabControl
55 #region Private Variables
60 public ExportCollada(RadegastInstance instance, Primitive prim)
63 InitializeComponent();
64 Exporter = new DAEExport(instance, prim);
65 Exporter.Progress += new EventHandler<DAEStatutsEventArgs>(Exporter_Progress);
67 cbImageType.Text = "TGA";
71 #region Private Methods
72 void LogMessage(string format, params object[] args)
76 if (IsHandleCreated || !instance.MonoRuntime)
77 BeginInvoke(new MethodInvoker(() => LogMessage(format, args)));
80 txtLog.AppendText(String.Format(format + "\r\n",args));
81 txtLog.SelectionStart = txtLog.TextLength;
82 txtLog.ScrollToCaret();
87 Primitive root = Exporter.Prims[0];
88 if (root.Properties != null)
90 objectName.Text = root.Properties.Name;
94 objectName.Text = "Object";
96 objectUUID.Text = root.ID.ToString();
97 primCount.Text = Exporter.Prims.Count.ToString();
98 exportablePrims.Text = Exporter.ExportablePrims.ToString();
99 textureCount.Text = Exporter.Textures.Count.ToString();
100 exportableTextures.Text = Exporter.ExportableTextures.ToString();
101 texturesPanel.Controls.Clear();
102 foreach (UUID textureID in Exporter.Textures)
104 var img = new SLImageHandler(instance, textureID, string.Empty);
107 img.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
108 texturesPanel.Controls.Add(img);
112 void ValidatePath(string fname)
114 string path = Path.GetDirectoryName(fname);
115 if (Directory.Exists(path))
116 btnExport.Enabled = true;
118 btnExport.Enabled = false;
122 #region Event Handlers
123 void TxtFileNameTextChanged(object sender, EventArgs e)
125 ValidatePath(txtFileName.Text);
128 void BtnBrowseClick(object sender, EventArgs e)
130 SaveFileDialog dlg = new SaveFileDialog();
131 dlg.Title = "Export Collada File";
132 dlg.Filter = "Collada (*.dae)|*.dae|All Files (*.*)|*.*";
133 if (txtFileName.Text.Trim() == string.Empty)
135 dlg.FileName = RadegastInstance.SafeFileName(objectName.Text);
139 dlg.FileName = Path.GetFileName(txtFileName.Text);
142 DialogResult res = dlg.ShowDialog();
144 if (res == DialogResult.OK)
146 txtFileName.Text = dlg.FileName;
147 ValidatePath(dlg.FileName);
151 void BtnExportClick(object sender, EventArgs e)
153 Exporter.ImageFormat = cbImageType.Text;
156 Exporter.Export(txtFileName.Text);
160 LogMessage("Export failed: {0}", ex.ToString());
164 private void cbExportTextures_CheckedChanged(object sender, EventArgs e)
166 Exporter.ExportTextures = cbImageType.Enabled = cbExportTextures.Checked;
169 void Exporter_Progress(object sender, DAEStatutsEventArgs e)
171 LogMessage(e.Message);