UVTexIntegra 310.0.0.3

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

- ファイル一覧

全て クラス ネームスペース 関数 変数 列挙型 プロパティ イベント グループ ページ
CustomControls.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
9 #pragma once
10
11 #include "../UVTexIntegra.hpp"
12
13 namespace UVTexIntegra {
14 namespace CustomControls {
15
16 private ref struct MaterialDrawData {
17 public:
18 bool isCurrent;
19 System::Drawing::RectangleF rect;
20 System::Drawing::Brush^ matBrush;
21 System::Drawing::Pen^ matPen;
22 MaterialDrawData( System::Drawing::RectangleF rc, System::Drawing::Brush^ brush, System::Drawing::Pen^ pen ) :
23 rect(rc), matBrush(brush), matPen(pen) {}
24 ~MaterialDrawData() { this->!MaterialDrawData(); }
25 !MaterialDrawData() {
26 if ( matBrush != nullptr ) { delete matBrush; matBrush = nullptr; }
27 if ( matPen != nullptr ) { delete matPen; matPen = nullptr; }
28 }
29 };
30
31 }
32 }
33
34 #include "TextureSetForm.hpp"
35 #include "VertexColorCustomBakeForm.hpp"
36 #include "MainEditForm.hpp"
37
38 namespace UVTexIntegra
39 {
40 namespace CustomControls
41 {
44
47 struct UVTransformedBuffer
48 {
50 struct TransformFunctor
51 {
53 TransformFunctor( IDocumentFormat^ doc ) : m_doc(doc)
54 {
55 }
56
58 bool operator()( MQCoordinate* const uv_coorinates, DWORD* const colors,
59 const MQObject obj, const int count_of_points, const int face_index, const UINT face_uid ) const
60 {
61 IDocumentFormat^ docData = static_cast<IDocumentFormat^>(m_doc);
62 if ( docData == nullptr ) return false;
63 const MQDocument mqdoc = docData->MQDocument;
64 if ( mqdoc == NULL ) return false;
65
66 const MQMaterial mat = mqdoc->GetMaterial( obj->GetFaceMaterial( face_index ) );
67 EditData^ data = nullptr; if ( mat != NULL ) data = docData->ItemFromID( mat->GetUniqueID() );
68 if ( data == nullptr ) return false;
69
70 const double pad = std::abs(data->Padding);
71 const UVCoordinate vMul((data->ScaleU - pad * 2.0) * 2.0, (data->ScaleV - pad * 2.0) * 2.0 );
72 const UVCoordinate vAdd((data->MoveU + pad) * 2.0 - 1.0, (data->MoveV + pad) * 2.0 - 1.0 );
73 for ( int ct = 0; ct < count_of_points; ct++ )
74 {
75 uv_coorinates[ct].u = float( double(uv_coorinates[ct].u) * vMul.u + vAdd.u );
76 uv_coorinates[ct].v = float( double(uv_coorinates[ct].v) * vMul.v + vAdd.v );
77 }
78 return true;
79 }
80 private:
81 const gcroot<IDocumentFormat^> m_doc;
82 };
83
85 UVTransformedBuffer() : m_uvBuffer(), m_doc(nullptr) {}
86
88 void AddObject(const MQObject obj, bool isRecursive)
89 {
90 IDocumentFormat^ doc = Document();
91 if (doc == nullptr) return;
92 AddObject(obj, isRecursive, TransformFunctor(static_cast<IDocumentFormat^>(m_doc)));
93 }
94
96 void Clear( IDocumentFormat^ doc, const bool isCompact = false )
97 {
98 m_doc = doc;
99 m_uvBuffer.Clear(isCompact);
100 }
101
103 const MQ0x::Polygon::UVFaceBuffer& UVFaceBuffer() const
104 {
105 return m_uvBuffer;
106 }
107
108 protected:
109
112 template <class FUNCTOR> void AddObject(const MQObject obj, bool isRecursive, FUNCTOR& functor)
113 {
114 if (obj != NULL)
115 {
116 if (isRecursive) {
117 IDocumentFormat^ doc = Document();
118 if (doc == nullptr) return;
119 m_uvBuffer.AddObjectRecursive(doc->MQDocument, obj, functor);
120 }
121 else m_uvBuffer.AddObject(obj, functor);
122 }
123 }
124
126 IDocumentFormat^ Document() const
127 {
128 return static_cast<IDocumentFormat^>(m_doc);
129 }
130
131 private:
132 MQ0x::Polygon::UVFaceBuffer m_uvBuffer;
133 //gcroot<MainEditForm::Document^> m_doc;
134 gcroot<IDocumentFormat^> m_doc;
135 };
136
139 struct UVNormalTransformedBuffer : public UVTransformedBuffer
140 {
142 struct TransformFunctor : private UVTransformedBuffer::TransformFunctor
143 {
145 TransformFunctor(UVNormalTransformedBuffer& owner)
146 : UVTransformedBuffer::TransformFunctor(owner.Document()), m_owner(owner)
147 {
148 }
149
152 bool operator()( MQCoordinate* const uv_coorinates, DWORD* const colors,
153 const MQObject obj, const int count_of_points, const int face_index, const UINT face_uid ) const
154 {
155 bool ret = UVTransformedBuffer::TransformFunctor::operator()(uv_coorinates,colors,obj,count_of_points,face_index,face_uid);
156 if (ret)
157 {
158 array<Scripting::ScriptMain::Face::Point^>^ points = gcnew array<Scripting::ScriptMain::Face::Point^>(count_of_points);
159 if (obj != m_owner.m_normal_buffer.MQObject()) m_owner.m_normal_buffer.Clear(obj);
160 int v_index_buffer[4];
161 obj->GetFacePointArray( face_index, v_index_buffer );
162 for ( int ctFacePoint = 0; ctFacePoint < count_of_points; ctFacePoint++ )
163 {
164 const MQPoint& vertexNormal = m_owner.m_normal_buffer.VertexNormal( MQ0x::Polygon::VertexNormalBuffer::size_type(v_index_buffer[ctFacePoint]) );
165 points[ctFacePoint] = gcnew Scripting::ScriptMain::Face::Point(
166 uv_coorinates[ctFacePoint].u, uv_coorinates[ctFacePoint].v,
167 MQCLIEX::FromMQVertexColor( colors[ctFacePoint] ),
168 vertexNormal.x, vertexNormal.y, vertexNormal.z
169 );
170 }
171 const MQPoint& faceNormal = m_owner.m_normal_buffer.FaceNormal( MQ0x::Polygon::FaceNormalBuffer::size_type(face_index) );
172 m_owner.m_faces->Add( gcnew Scripting::ScriptMain::Face( face_uid, faceNormal.x, faceNormal.y, faceNormal.z, points ) );
173 }
174 return ret;
175 }
176
177 /*
179 bool operator()( MQCoordinate* const uv_coorinates, DWORD* const colors,
180 const MQObject obj, const int count_of_points, const int face_index, const UINT face_uid ) const
181 {
182 bool ret = UVTransformedBuffer::TransformFunctor::operator()(uv_coorinates,colors,obj,count_of_points,face_index,face_uid);
183 if (ret)
184 {
185 Scripting::ScriptMain^ scriptMain = static_cast<Scripting::ScriptMain^>(m_owner.m_scriptMain);
186 if (scriptMain != nullptr)
187 {
188 array<OpenTK::Vector2>^ coordinates = gcnew array<OpenTK::Vector2>(count_of_points);
189 array<System::Drawing::Color>^ coordinateColors = gcnew array<System::Drawing::Color>(count_of_points);
190 array<OpenTK::Vector3>^ normals = gcnew array<OpenTK::Vector3>(count_of_points);
191
192 if (obj != m_owner.m_normal_buffer.MQObject()) m_owner.m_normal_buffer.Clear(obj);
193
194 int v_index_buffer[4];
195 obj->GetFacePointArray( face_index, v_index_buffer );
196 for ( int ctFacePoint = 0; ctFacePoint < count_of_points; ctFacePoint++ )
197 {
198 const MQPoint& vertexNormal = m_owner.m_normal_buffer.VertexNormal( MQ0x::Polygon::VertexNormalBuffer::size_type(v_index_buffer[ctFacePoint]) );
199 coordinates[ctFacePoint] = OpenTK::Vector2( uv_coorinates[ctFacePoint].u, uv_coorinates[ctFacePoint].v );
200 coordinateColors[ctFacePoint] = MQCLIEX::FromMQVertexColor( colors[ctFacePoint] );
201 normals[ctFacePoint] = OpenTK::Vector3( vertexNormal.x, vertexNormal.y, vertexNormal.z );
202 }
203 const MQPoint& faceNormal = m_owner.m_normal_buffer.FaceNormal( MQ0x::Polygon::FaceNormalBuffer::size_type(face_index) );
204
205 //if ( scriptMain->CustomUVOperation(coordinates, coordinateColors, OpenTK::Vector3(faceNormal.x, faceNormal.y, faceNormal.z), normals ) )
206 //{
207 // for ( int ctFacePoint = 0; ctFacePoint < count_of_points; ctFacePoint++ )
208 // {
209 // uv_coorinates[ctFacePoint].u = coordinates[ctFacePoint].X;
210 // uv_coorinates[ctFacePoint].v = coordinates[ctFacePoint].Y;
211 // colors[ctFacePoint] = MQCLIEX::ArgbToMQVertexColor(
212 // coordinateColors[ctFacePoint].A,
213 // coordinateColors[ctFacePoint].R,
214 // coordinateColors[ctFacePoint].G,
215 // coordinateColors[ctFacePoint].B );
216 // }
217 //}
218 }
219 }
220 return ret;
221 }
222 */
223 private:
224 UVNormalTransformedBuffer& m_owner;
225 };
226
228 friend struct TransformFunctor;
230
233 void AddObject(const MQObject obj, bool isRecursive)
234 {
235 IDocumentFormat^ doc = Document();
236 if (doc == nullptr) return;
237 UVTransformedBuffer::AddObject(obj, isRecursive, TransformFunctor(*this));
238 }
239
241 void Clear( IDocumentFormat^ doc, Scripting::ScriptMain^ script, const bool isCompact = false )
242 {
243 //m_scriptMain = script;
244 m_normal_buffer.Clear(NULL, isCompact);
245 if (static_cast<System::Collections::Generic::List<Scripting::ScriptMain::Face^>^>(m_faces) != nullptr) m_faces->Clear();
246 else m_faces = gcnew System::Collections::Generic::List<Scripting::ScriptMain::Face^>();
247 UVTransformedBuffer::Clear(doc, isCompact);
248 }
249
253 CustomControls::Drawing::FaceBuffer^ GetUVOperationed( Scripting::ScriptMain^ scriptMain )
254 {
255 if (static_cast<System::Collections::Generic::List<Scripting::ScriptMain::Face^>^>(m_faces) == nullptr) return nullptr;
256 if (scriptMain == nullptr) return nullptr;
257 array<Scripting::ScriptMain::Face^>^ ary = m_faces->ToArray();
258 scriptMain->OnUVOperation(ary);
259 return gcnew CustomControls::Drawing::FaceBuffer(ary);
260 }
261
263 const MQ0x::Polygon::VertexNormalBuffer& VertexNormalBuffer() const { return m_normal_buffer; }
264
265 private:
266 void Clear( IDocumentFormat^ doc, const bool isCompact = false ); // kill
267 MQ0x::Polygon::VertexNormalBuffer m_normal_buffer;
268 //gcroot<Scripting::ScriptMain^> m_scriptMain;
269 gcroot<System::Collections::Generic::List<Scripting::ScriptMain::Face^>^> m_faces;
270 };
271
273 }
274 }