UVTexIntegra 310.0.0.3

- メインページ
- 関連ページ
- モジュール
- ネームスペース
- クラス
- ファイル

- ファイル一覧

全て クラス ネームスペース 関数 変数 列挙型 プロパティ イベント グループ ページ
K:/Dancer_iMac/UVTexa/UVTexIntegra/UVTexIntegra.hpp
1 // == LICENSE INFORMATION ==
2 /*
3 * First author tiritomato 2013.
4 * This program is distributed under the GNU General Public License(GPL).
5 * support blog (Japanese only) http://d.hatena.ne.jp/tiri_tomato/
6 */
7 // == LICENSE INFORMATION ==
8
15 #pragma once
16
17 #using "mscorlib.dll"
18 #using "windowsbase.dll"
19
20 #include "MQCLI.hpp"
21 #include "msclr/marshal.h"
22 #include "msclr/marshal_windows.h"
23 #include "msclr/marshal_cppstd.h"
24
25 #include <bitset>
26 #include <gcroot.h>
27
28 #define MAKER_NAME "tiritomato"
29 #define PLUGIN_NAME "UV and Texture Integration Tool"
30 #define PLUGIN_STRING "UVTexIntegra"
31 #define PLUGIN_SETTING_KEY "UVTI_ParamsKey"
32 #define PILOT_SWITCH_STRING_CLEAR "UV統合情報をクリア"
33 #define PILOT_SWITCH_STRING_CREATE "UV統合情報を作成"
34 #define CUSTOMBAKE_CONFIG_FILENAME "CustomBake.dat"
35
36 namespace UVTexIntegra {
37
40
42 public enum class CanvasMode {
43 Normal,
44 VertexColorPreview
45 };
46
48 public ref class CustomAssemblyResolver {
49 public:
50 static CustomAssemblyResolver^ Singleton() { if ( m_instance == nullptr ) m_instance = gcnew CustomAssemblyResolver(); return m_instance; }
51 private:
52 static CustomAssemblyResolver^ m_instance = nullptr;
53 initonly System::String^ DllLoadDirectory;
54 CustomAssemblyResolver();
55 System::Reflection::Assembly^ CustomAssemblyResolve(System::Object^ sender, System::ResolveEventArgs^ args);
56 };
57
59 public interface class IDisplayName {
60 property System::String^ DisplayName { System::String^ get(); }
61 };
62
64 struct UVCoordinate {
65 double u, v;
66 UVCoordinate() { u = v = 0.0; }
67 UVCoordinate( const double u_, const double v_ ) { u = u_; v = v_; }
68 UVCoordinate( const MQCoordinate& src ) { u = src.u; v = src.v; }
69 UVCoordinate operator - () { return UVCoordinate(-u, -v); }
70 void Add( const double src ) { u += src; v += src; }
71 void Add( const double u_, const double v_ ) { u += u_; v += v_; }
72 void Add( const UVCoordinate& src ) { u += src.u; v += src.v; }
73 void CopyTo( MQCoordinate &dest ) { dest.u = (float)u; dest.v = (float)v; }
74 double Magnitude() const { const double sqmag = SqrMagnitude(); if ( 0.0 < sqmag ) return std::sqrt( sqmag ); return 0.0; }
75 void Magnitude( const double setMagnitude ) { const double mag = Magnitude(); if ( 0.0 < mag ) Mul( setMagnitude / mag ); }
76 void Mul( const double src ) { u *= src; v *= src; }
77 void Mul( const double u_, const double v_ ) { u *= u_; v *= v_; }
78 void Mul( const UVCoordinate& src ) { u *= src.u; v *= src.v; }
79 void Normalize() { const double mag = Magnitude(); if ( 0.0 < mag ) Mul( 1.0 / mag ); }
80 void Rotate(const double angle_degree, const UVCoordinate& o) {
81 const double cos = System::Math::Cos(angle_degree);
82 const double sin = System::Math::Sin(angle_degree);
83 const UVCoordinate dist( u - o.u, v - o.v );
84 u = dist.u * cos - dist.v * sin + o.u;
85 v = dist.u * sin - dist.v * cos + o.v;
86 }
87 void Rotate(const double angle_degree) { Rotate( angle_degree, UVCoordinate() ); }
88 double SqrMagnitude() const { return u*u+v*v; }
89 };
90
91 // @}
92 }
93
94 #include "MQCLIExtention.hpp"
95
96 namespace UVTexIntegra {
97
100
104 [System::Serializable]
105 public ref class Config {
106 public:
107 int Width;
108 int Height;
109 int SplitterW;
110 int CanvasRestoreW;
111 int GridResolution;
112 int TexSetFormW, TexSetFormH;
113 UVTexIntegra::CanvasMode CanvasMode;
114 System::Int32 BakeTexBaseColor;
115 int BakeTexImgW, BakeTexImgH;
116 float BakeTexBorder;
117 int BuildResultFormW, BuildResultFormH;
118 System::String^ ScriptLoadDir;
119 int BitFlags32;
120
121 [System::Xml::Serialization::XmlIgnoreAttribute]
122 property bool IsDisplayTransparent {
123 bool get() { return std::bitset<32>(BitFlags32)[0]; }
124 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[0] = value; BitFlags32 = int(bits.to_ulong()); }
125 }
126 [System::Xml::Serialization::XmlIgnoreAttribute]
127 property bool IsDisplayGrid {
128 bool get() { return std::bitset<32>(BitFlags32)[1]; }
129 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[1] = value; BitFlags32 = int(bits.to_ulong()); }
130 }
131 [System::Xml::Serialization::XmlIgnoreAttribute]
132 property bool IsDisplayFill {
133 bool get() { return std::bitset<32>(BitFlags32)[2]; }
134 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[2] = value; BitFlags32 = int(bits.to_ulong()); }
135 }
136 [System::Xml::Serialization::XmlIgnoreAttribute]
137 property bool IsDisplayBorder {
138 bool get() { return std::bitset<32>(BitFlags32)[3]; }
139 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[3] = value; BitFlags32 = int(bits.to_ulong()); }
140 }
141 [System::Xml::Serialization::XmlIgnoreAttribute]
142 property bool IsDisplayPoly {
143 bool get() { return std::bitset<32>(BitFlags32)[4]; }
144 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[4] = value; BitFlags32 = int(bits.to_ulong()); }
145 }
146 [System::Xml::Serialization::XmlIgnoreAttribute]
147 property bool IsDisplayObjcetTransMenu {
148 bool get() { return std::bitset<32>(BitFlags32)[5]; }
149 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[5] = value; BitFlags32 = int(bits.to_ulong()); }
150 }
151 [System::Xml::Serialization::XmlIgnoreAttribute]
152 property bool IsDisplayCmbTexMenu {
153 bool get() { return std::bitset<32>(BitFlags32)[6]; }
154 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[6] = value; BitFlags32 = int(bits.to_ulong()); }
155 }
156 [System::Xml::Serialization::XmlIgnoreAttribute]
157 property bool IsDisplayBakeTexMenu {
158 bool get() { return std::bitset<32>(BitFlags32)[7]; }
159 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[7] = value; BitFlags32 = int(bits.to_ulong()); }
160 }
161 [System::Xml::Serialization::XmlIgnoreAttribute]
162 property bool IsDisplaySelectedObjectMenu {
163 bool get() { return std::bitset<32>(BitFlags32)[8]; }
164 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[8] = value; BitFlags32 = int(bits.to_ulong()); }
165 }
166 [System::Xml::Serialization::XmlIgnoreAttribute]
167 property bool IsDisplayMaterialEditMenu {
168 bool get() { return std::bitset<32>(BitFlags32)[9]; }
169 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[9] = value; BitFlags32 = int(bits.to_ulong()); }
170 }
171
172 Config^ Clone() { return static_cast<Config^>(MemberwiseClone()); }
173
174 Config() {
175 Width = -1;
176 Height = -1;
177 SplitterW = -1;
178 CanvasRestoreW = -1;
179 BitFlags32 = 0;
180 IsDisplayTransparent = true;
181 IsDisplayGrid = true;
182 IsDisplayFill = true;
183 IsDisplayBorder = true;
184 IsDisplayPoly = false;
185 IsDisplayObjcetTransMenu = true;
186 IsDisplayCmbTexMenu = true;
187 IsDisplayBakeTexMenu = true;
188 IsDisplaySelectedObjectMenu = true;
189 IsDisplayMaterialEditMenu = true;
190 TexSetFormW = 0;
191 TexSetFormH = 0;
192 CanvasMode = CanvasMode::Normal;
193 BakeTexBaseColor = 0xFFFFFFFF;
194 BakeTexImgW = BakeTexImgH = 1024;
195 BakeTexBorder = 0.0f;
196 ScriptLoadDir = nullptr;
197 }
198 };
199
202 public ref class EditData : System::ICloneable {
203 public:
206 ref class SelectedCollection : System::Collections::IEnumerable, System::Collections::Generic::IEnumerable<EditData^> {
207 public:
208 property bool^ IsTransExecute {
209 bool^ get() {
210 if ( (m_src==nullptr) || (m_src->Count<=0) ) return nullptr;
211 const bool ret = m_src[0]->IsTransExecute;
212 for each ( EditData^ data in m_src ) if ( ret != data->IsTransExecute ) return nullptr;
213 return ret;
214 }
215 void set( bool^ value ){ if ((m_src!=nullptr)&&(value!=nullptr)) for each ( EditData^ data in m_src ) data->IsTransExecute = *value; }
216 }
217 property UINT ToMaterialID {
218 UINT get() {
219 if ( (m_src==nullptr) || (m_src->Count<=0) ) return -1;
220 const UINT ret = m_src[0]->ToMaterialID;
221 for each ( EditData^ data in m_src ) if ( ret != data->ToMaterialID ) return -1;
222 return ret;
223 }
224 void set( UINT value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->ToMaterialID = value; }
225 }
226 property System::String^ ToMaterialName {
227 System::String^ get() {
228 if ( (m_src==nullptr) || (m_src->Count<=0) ) return nullptr;
229 System::String^ ret = m_src[0]->ToMaterialName;
230 for each ( EditData^ data in m_src ) if ( System::String::Compare(ret,data->ToMaterialName) != 0 ) return nullptr;
231 return ret;
232 }
233 void set( System::String^ value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->ToMaterialName = value; }
234 }
235 property float MoveU {
236 float get() {
237 if ( (m_src==nullptr) || (m_src->Count<=0) ) return float::NaN;
238 const float ret = m_src[0]->MoveU;
239 for each ( EditData^ data in m_src ) if ( ret != data->MoveU ) return float::NaN;
240 return ret;
241 }
242 void set( float value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->MoveU = value; }
243 }
244 property float MoveV {
245 float get() {
246 if ( (m_src==nullptr) || (m_src->Count<=0) ) return float::NaN;
247 const float ret = m_src[0]->MoveV;
248 for each ( EditData^ data in m_src ) if ( ret != data->MoveV ) return float::NaN;
249 return ret;
250 }
251 void set( float value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->MoveV = value; }
252 }
253 property float ScaleU {
254 float get() {
255 if ( (m_src==nullptr) || (m_src->Count<=0) ) return float::NaN;
256 const float ret = m_src[0]->ScaleU;
257 for each ( EditData^ data in m_src ) if ( ret != data->ScaleU ) return float::NaN;
258 return ret;
259 }
260 void set( float value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->ScaleU = value; }
261 }
262 property float ScaleV {
263 float get() {
264 if ( (m_src==nullptr) || (m_src->Count<=0) ) return float::NaN;
265 const float ret = m_src[0]->ScaleV;
266 for each ( EditData^ data in m_src ) if ( ret != data->ScaleV ) return float::NaN;
267 return ret;
268 }
269 void set( float value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->ScaleV = value; }
270 }
271 property float Padding {
272 float get() {
273 if ( (m_src==nullptr) || (m_src->Count<=0) ) return float::NaN;
274 const float ret = m_src[0]->Padding;
275 for each ( EditData^ data in m_src ) if ( ret != data->Padding ) return float::NaN;
276 return ret;
277 }
278 void set( float value ){ if ( m_src != nullptr ) for each ( EditData^ data in m_src ) data->Padding = value; }
279 }
280 property EditData^ default[int] {
281 EditData^ get(int index) { if ( (m_src!=nullptr) && (0<=index) && (index<m_src->Count) ) return m_src[index]; return nullptr; }
282 };
283 virtual property int Count { int get(){ if (m_src!=nullptr) return m_src->Count; return 0; } }
284 SelectedCollection( System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ src ) : m_src(src) {}
285 virtual System::Collections::IEnumerator^ GetEnumerator() = System::Collections::IEnumerable::GetEnumerator
286 {
287 if ( m_src != nullptr ) return m_src->GetEnumerator(); return nullptr;
288 }
289 virtual System::Collections::Generic::IEnumerator<EditData^>^ GetGenericEnumerator() = System::Collections::Generic::IEnumerable<EditData^>::GetEnumerator
290 {
291 if ( m_src != nullptr ) return m_src->GetEnumerator(); return nullptr;
292 }
293 private:
294 System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ m_src;
295 };
296 UINT UniqueID;
297 System::String^ MaterialName;
298 bool IsTransExecute;
299 UINT ToMaterialID;
300 System::String^ ToMaterialName;
301 float ScaleU, ScaleV;
302 float MoveU, MoveV;
303 float Padding;
304 property bool IsTransExecutableStatus {
305 bool get(){
306 return ((float::IsNaN(ScaleU)||float::IsNaN(ScaleV)||float::IsNaN(MoveU)||float::IsNaN(MoveV)||float::IsInfinity(ScaleU)||float::IsInfinity(ScaleV)||float::IsInfinity(MoveU)||float::IsInfinity(MoveV))==false) &&
307 IsTransExecute&&(ScaleU!=0.0f)&&(ScaleV!=0.0f);
308 }
309 }
311 EditData() { Clear(-1,nullptr); }
313 EditData( const UINT uid_, System::String^ name ) { Clear(uid_,name); }
315 EditData^ Clone() { return static_cast<EditData^>(MemberwiseClone()); }
317 virtual System::Object^ InterfaceClone() = System::ICloneable::Clone { return MemberwiseClone(); }
319 void Reset() {
320 IsTransExecute = false;
321 MaterialName = nullptr;
322 ToMaterialID = -1;
323 ToMaterialName = nullptr;
324 ScaleU = 0.0f;
325 ScaleV = 0.0f;
326 MoveU = 0.0f;
327 MoveV = 0.0f;
328 Padding = 0.0f;
329 }
330 private:
331 void Clear(const UINT uid_, System::String^ name ) {
332 Reset();
333 UniqueID = uid_;
334 MaterialName = name;
335 IsTransExecute = true;
336 }
337 };
338
341 public interface class IDocumentFormat {
342 property System::Int32 AlphaClearColor { System::Int32 get(); }
343 property System::Int32 BumpClearColor { System::Int32 get(); }
344 property System::Int32 TextureClearColor { System::Int32 get(); }
345 property System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ EditDataItems {
346 System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ get();
347 }
348 property bool IsCloneTrans { bool get(); }
349 property bool IsRecursiveTrans { bool get(); }
350 property bool IsIntegrateTexture { bool get(); }
351 property bool IsClrTextureOnIntegrate { bool get(); }
352 property bool IsIntegrateAlpha { bool get(); }
353 property bool IsClrAlphaOnIntegrate { bool get(); }
354 property bool IsIntegrateBump { bool get(); }
355 property bool IsClrBumpOnIntegrate { bool get(); }
356 property ::MQDocument MQDocument { ::MQDocument get(); }
358 EditData^ ItemFromID( const UINT UniqueID );
360 EditData^ ItemFromName( System::String^ matName );
362 EditData^ ItemFromIndex( const int index );
364 int ItemIndexFromID( const UINT UniqueID );
367 EditData::SelectedCollection^ ItemsOnSelected();
372 EditData::SelectedCollection^ ItemsOnSelected(const int index);
373 };
374
376 public ref class DocumentFormat : IDocumentFormat, System::ICloneable {
377 public:
379 int BitFlags32;
382 property System::Collections::Generic::List<EditData^>^ EditDataItems {
383 System::Collections::Generic::List<EditData^>^ get() {
384 if ( m_editDataItems == nullptr ) m_editDataItems = gcnew System::Collections::Generic::List<EditData^>();
385 return m_editDataItems;
386 }
387 void set(System::Collections::Generic::List<EditData^>^ value) {
388 if (value == nullptr) value = gcnew System::Collections::Generic::List<EditData^>();
389 m_editDataItems = value;
390 }
391 }
392 [System::Xml::Serialization::XmlIgnoreAttribute]
393 virtual property System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ ReadonlyEditDataItems {
394 System::Collections::ObjectModel::ReadOnlyCollection<EditData^>^ get() = IDocumentFormat::EditDataItems::get {
395 if (m_editDataItems != nullptr) m_editDataItems->AsReadOnly();
396 return System::Array::AsReadOnly(gcnew array<EditData^>{});
397 }
398 }
399 virtual property System::Int32 AlphaClearColor {
400 System::Int32 get() { return m_alphaClearColor; }
401 void set(System::Int32 value) { m_alphaClearColor = value; }
402 }
403 virtual property System::Int32 BumpClearColor {
404 System::Int32 get() { return m_bumpClearColor; }
405 void set(System::Int32 value) { m_bumpClearColor = value; }
406 }
407 virtual property System::Int32 TextureClearColor {
408 System::Int32 get() { return m_textureClearColor; }
409 void set(System::Int32 value) { m_textureClearColor = value; }
410 }
411 [System::Xml::Serialization::XmlIgnoreAttribute]
412 virtual property bool IsCloneTrans {
413 bool get() { return std::bitset<32>(BitFlags32)[0]; }
414 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[0] = value; BitFlags32 = int(bits.to_ulong()); }
415 }
416 [System::Xml::Serialization::XmlIgnoreAttribute]
417 virtual property bool IsRecursiveTrans {
418 bool get() { return std::bitset<32>(BitFlags32)[1]; }
419 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[1] = value; BitFlags32 = int(bits.to_ulong()); }
420 }
421 [System::Xml::Serialization::XmlIgnoreAttribute]
422 virtual property bool IsIntegrateTexture {
423 bool get() { return std::bitset<32>(BitFlags32)[2]; }
424 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[2] = value; BitFlags32 = int(bits.to_ulong()); }
425 }
426 [System::Xml::Serialization::XmlIgnoreAttribute]
427 virtual property bool IsClrTextureOnIntegrate {
428 bool get() { return std::bitset<32>(BitFlags32)[3]; }
429 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[3] = value; BitFlags32 = int(bits.to_ulong()); }
430 }
431 [System::Xml::Serialization::XmlIgnoreAttribute]
432 virtual property bool IsIntegrateAlpha {
433 bool get() { return std::bitset<32>(BitFlags32)[4]; }
434 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[4] = value; BitFlags32 = int(bits.to_ulong()); }
435 }
436 [System::Xml::Serialization::XmlIgnoreAttribute]
437 virtual property bool IsClrAlphaOnIntegrate {
438 bool get() { return std::bitset<32>(BitFlags32)[5]; }
439 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[5] = value; BitFlags32 = int(bits.to_ulong()); }
440 }
441 [System::Xml::Serialization::XmlIgnoreAttribute]
442 virtual property bool IsIntegrateBump {
443 bool get() { return std::bitset<32>(BitFlags32)[6]; }
444 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[6] = value; BitFlags32 = int(bits.to_ulong()); }
445 }
446 [System::Xml::Serialization::XmlIgnoreAttribute]
447 virtual property bool IsClrBumpOnIntegrate {
448 bool get() { return std::bitset<32>(BitFlags32)[7]; }
449 void set(bool value) { std::bitset<32> bits(BitFlags32); bits[7] = value; BitFlags32 = int(bits.to_ulong()); }
450 }
451 [System::Xml::Serialization::XmlIgnoreAttribute]
452 virtual property ::MQDocument MQDocument {
453 ::MQDocument get() { return m_doc; }
454 void set( ::MQDocument value ) { m_doc = value; }
455 }
456
458 DocumentFormat();
460 DocumentFormat( DocumentFormat^ src );
463 DocumentFormat^ Clone() { return gcnew DocumentFormat(this); }
465 virtual System::Object^ InterfaceClone() = System::ICloneable::Clone { return Clone(); }
467 virtual EditData^ ItemFromID( const UINT UniqueID );
469 virtual EditData^ ItemFromName( System::String^ matName );
471 virtual EditData^ ItemFromIndex( const int index );
473 virtual int ItemIndexFromID( const UINT UniqueID );
476 virtual EditData::SelectedCollection^ ItemsOnSelected() { return ItemsOnSelected(-1); }
481 virtual EditData::SelectedCollection^ ItemsOnSelected(const int index);
482 private:
483 System::Int32 m_textureClearColor;
484 System::Int32 m_alphaClearColor;
485 System::Int32 m_bumpClearColor;
486 ::MQDocument m_doc;
487 System::Collections::Generic::List<EditData^>^ m_editDataItems;
488 };
489
490 inline System::String^ GetCustomBakeConfigPath()
491 {
492 System::Reflection::Assembly^ assembly = System::Reflection::Assembly::GetExecutingAssembly();
493 System::IO::FileInfo^ fileInfo = gcnew System::IO::FileInfo(assembly->Location);
494 return fileInfo->Directory + "\\" + System::IO::Path::GetFileNameWithoutExtension(fileInfo->Name) + "\\" + CUSTOMBAKE_CONFIG_FILENAME;
495 }
496
498 }
499
500 #include "UVTexIntegra.IConfig.hpp"