From b6efabb3fd9a22f78a8118e1648896a342d03229 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Fri, 4 Dec 2015 07:14:32 +0500 Subject: [PATCH] ECore: fixed includes and formatted code --- src/editors/ECore/Editor/ArbitraryList.h | 297 ++- src/editors/ECore/Editor/BoneEditor.cpp | 381 +-- src/editors/ECore/Editor/ColorPicker.cpp | 77 +- src/editors/ECore/Editor/ColorPicker.h | 6 +- src/editors/ECore/Editor/D3DUtils.cpp | 2129 ++++++++++------- src/editors/ECore/Editor/D3DUtils.h | 273 ++- src/editors/ECore/Editor/D3DX_Wrapper.h | 391 +-- src/editors/ECore/Editor/DeviceScreenshot.cpp | 73 +- src/editors/ECore/Editor/DrawUtils.h | 1 + src/editors/ECore/Editor/EDetailModel.cpp | 309 +-- src/editors/ECore/Editor/EDetailModel.h | 115 +- src/editors/ECore/Editor/ELog.cpp | 46 +- src/editors/ECore/Editor/ELog.h | 17 +- src/editors/ECore/Editor/EStats.cpp | 241 +- src/editors/ECore/Editor/EStats.h | 82 +- src/editors/ECore/Editor/ETextureParams.cpp | 1 + src/editors/ECore/Editor/ETextureParams.h | 1 + src/editors/ECore/Editor/EThumbnail.cpp | 69 +- src/editors/ECore/Editor/EThumbnail.h | 278 ++- src/editors/ECore/Editor/EThumbnailGroup.cpp | 144 +- src/editors/ECore/Editor/EThumbnailObject.cpp | 134 +- src/editors/ECore/Editor/EThumbnailSound.cpp | 245 +- .../ECore/Editor/EThumbnailTexture.cpp | 319 +-- src/editors/ECore/Editor/EditMesh.cpp | 670 +++--- src/editors/ECore/Editor/EditMesh.h | 513 ++-- src/editors/ECore/Editor/EditMeshIO.cpp | 298 +-- src/editors/ECore/Editor/EditMeshModify.cpp | 553 +++-- src/editors/ECore/Editor/EditMeshPick.cpp | 157 +- src/editors/ECore/Editor/EditMeshRender.cpp | 524 ++-- src/editors/ECore/Editor/EditObject.cpp | 314 +-- src/editors/ECore/Editor/EditObject.h | 711 +++--- src/editors/ECore/Editor/EditObjectEditor.cpp | 422 ++-- src/editors/ECore/Editor/EditObjectIO.cpp | 237 +- src/editors/ECore/Editor/EditObjectImport.cpp | 42 +- .../ECore/Editor/EditObjectMotions.cpp | 684 +++--- src/editors/ECore/Editor/EditObjectProps.cpp | 174 +- src/editors/ECore/Editor/EditObjectSkin.cpp | 672 +++--- .../ECore/Editor/EditorPreferences.cpp | 504 ++-- src/editors/ECore/Editor/EditorPreferences.h | 133 +- src/editors/ECore/Editor/Engine.cpp | 56 +- src/editors/ECore/Editor/ExportObjectOGF.cpp | 797 +++--- src/editors/ECore/Editor/ExportObjectOGF.h | 275 ++- .../Editor/ExportObjectOGFCalculateTB.cpp | 8 +- src/editors/ECore/Editor/ExportSkeleton.cpp | 1541 ++++++------ src/editors/ECore/Editor/ExportSkeleton.h | 276 ++- .../Editor/ExportSkeletonCalculateTB.cpp | 12 +- .../ECore/Editor/GeometryCollector.cpp | 149 +- src/editors/ECore/Editor/GeometryCollector.h | 86 +- src/editors/ECore/Editor/ImageEditor.cpp | 526 ++-- src/editors/ECore/Editor/ImageEditor.h | 196 +- src/editors/ECore/Editor/ImageManager.cpp | 958 ++++---- src/editors/ECore/Editor/ImageManager.h | 127 +- src/editors/ECore/Editor/ImageManagerDO.cpp | 416 ++-- src/editors/ECore/Editor/ImageManagerLOD.cpp | 628 ++--- src/editors/ECore/Editor/LW_ShaderDef.h | 18 +- src/editors/ECore/Editor/Library.cpp | 323 +-- src/editors/ECore/Editor/Library.h | 52 +- src/editors/ECore/Editor/LogForm.cpp | 175 +- src/editors/ECore/Editor/LogForm.h | 88 +- src/editors/ECore/Editor/MinimapEditor.cpp | 312 +-- src/editors/ECore/Editor/MinimapEditor.h | 42 +- .../ECore/Editor/ParticleEffectActions.cpp | 2 +- .../ECore/Editor/ParticleEffectActions.h | 493 ++-- .../Editor/PhysicsShellHolderEditorBase.cpp | 5 +- .../Editor/PhysicsShellHolderEditorBase.h | 2 +- src/editors/ECore/Editor/PropSlimTools.h | 1 + src/editors/ECore/Editor/SkeletonFace.h | 62 +- src/editors/ECore/Editor/SkeletonVert.h | 89 +- src/editors/ECore/Editor/SoundEditor.cpp | 541 +++-- src/editors/ECore/Editor/SoundEditor.h | 169 +- src/editors/ECore/Editor/SoundManager.cpp | 451 ++-- src/editors/ECore/Editor/SoundManager.h | 51 +- src/editors/ECore/Editor/TLSPRITE.CPP | 331 +-- src/editors/ECore/Editor/TLSPRITE.h | 255 +- src/editors/ECore/Editor/UI_Camera.cpp | 420 ++-- src/editors/ECore/Editor/UI_Camera.h | 124 +- src/editors/ECore/Editor/UI_MainCommand.cpp | 1096 +++++---- src/editors/ECore/Editor/UI_MainCommand.h | 204 +- src/editors/ECore/Editor/UI_MainMail.cpp | 167 +- src/editors/ECore/Editor/UI_ToolsCustom.cpp | 505 ++-- src/editors/ECore/Editor/UI_ToolsCustom.h | 364 +-- src/editors/ECore/Editor/c_dinput.cpp | 964 ++++---- src/editors/ECore/Editor/device.cpp | 526 ++-- src/editors/ECore/Editor/device.h | 305 +-- src/editors/ECore/Editor/du_box.cpp | 58 +- src/editors/ECore/Editor/du_box.h | 1 + src/editors/ECore/Editor/du_cone.cpp | 133 +- src/editors/ECore/Editor/du_cone.h | 1 + src/editors/ECore/Editor/du_cylinder.cpp | 232 +- src/editors/ECore/Editor/du_cylinder.h | 1 + src/editors/ECore/Editor/du_sphere.cpp | 794 +++--- src/editors/ECore/Editor/du_sphere.h | 1 + src/editors/ECore/Editor/du_sphere_part.cpp | 1 + src/editors/ECore/Editor/du_sphere_part.h | 1 + src/editors/ECore/Editor/engine.h | 22 +- .../ECore/Editor/itterate_adjacents_dynamic.h | 2 +- src/editors/ECore/Editor/lwo2.h | 1 + src/editors/ECore/Editor/pDomain.cpp | 1150 +++++---- src/editors/ECore/Editor/pick_definition.h | 1 + src/editors/ECore/Editor/render.cpp | 360 +-- src/editors/ECore/Editor/render.h | 245 +- src/editors/ECore/Editor/ui_main.cpp | 738 +++--- src/editors/ECore/Editor/ui_main.h | 351 +-- src/editors/ECore/Editor/xrLoadSurface.cpp | 187 +- src/editors/ECore/Engine/GameMtlLib.cpp | 1 + src/editors/ECore/Engine/GameMtlLib.h | 1 + .../ECore/Engine/GameMtlLib_Engine.cpp | 1 + src/editors/ECore/Engine/Image.cpp | 377 +-- src/editors/ECore/Engine/Image.h | 46 +- src/editors/ECore/Engine/NVMeshMender.cpp | 1262 +++++----- src/editors/ECore/Engine/NVMeshMender.h | 197 +- src/editors/ECore/Engine/Texture.h | 4 +- src/editors/ECore/Engine/ai_sounds.cpp | 47 +- src/editors/ECore/Engine/ai_sounds.h | 134 +- src/editors/ECore/Engine/bone.cpp | 1 + src/editors/ECore/Engine/cl_collector.cpp | 2 + src/editors/ECore/Engine/cl_collector.h | 2 + src/editors/ECore/Engine/cl_intersect.h | 1 + src/editors/ECore/Engine/guid_generator.cpp | 13 +- src/editors/ECore/Engine/guid_generator.h | 2 + src/editors/ECore/Engine/nv_algebra.cpp | 1175 ++++----- src/editors/ECore/Engine/nv_algebra.h | 908 ++++--- src/editors/ECore/Engine/nv_math.h | 9 +- src/editors/ECore/Engine/nv_mathdecl.h | 18 +- src/editors/ECore/stdafx.h | 100 +- 125 files changed, 19000 insertions(+), 16006 deletions(-) create mode 100644 src/editors/ECore/Editor/DrawUtils.h create mode 100644 src/editors/ECore/Editor/ETextureParams.cpp create mode 100644 src/editors/ECore/Editor/ETextureParams.h create mode 100644 src/editors/ECore/Editor/PropSlimTools.h create mode 100644 src/editors/ECore/Editor/du_sphere_part.cpp create mode 100644 src/editors/ECore/Editor/du_sphere_part.h create mode 100644 src/editors/ECore/Editor/lwo2.h create mode 100644 src/editors/ECore/Editor/pick_definition.h create mode 100644 src/editors/ECore/Engine/GameMtlLib.cpp create mode 100644 src/editors/ECore/Engine/GameMtlLib.h create mode 100644 src/editors/ECore/Engine/GameMtlLib_Engine.cpp create mode 100644 src/editors/ECore/Engine/bone.cpp create mode 100644 src/editors/ECore/Engine/cl_intersect.h diff --git a/src/editors/ECore/Editor/ArbitraryList.h b/src/editors/ECore/Editor/ArbitraryList.h index f06f4c12bcc..d58512486d2 100644 --- a/src/editors/ECore/Editor/ArbitraryList.h +++ b/src/editors/ECore/Editor/ArbitraryList.h @@ -18,134 +18,183 @@ // Designed to hold _unsorted_ data, but only RemoveItem() // actually disturbs the order, so you can use it for general arrays // if you don't use that function. -template +template class ArbitraryList { - T *pT; // The list. - u32 iSize; // The current size of the list. - u32 iReservedSize; // The current reserved size of the list. + T *pT; // The list. + u32 iSize; // The current size of the list. + u32 iReservedSize; // The current reserved size of the list. public: - // Constructor, with optional initial size setting. - ArbitraryList ( u32 iInitialSize = 0 ) - { - pT = NULL; - iSize = 0; - iReservedSize = 0; - if ( iInitialSize > 0 ) - resize( iInitialSize ); - } - // Destructor. - ~ArbitraryList ( void ) - { - if ( pT == NULL ){ - VERIFY ( iReservedSize == 0 ); - VERIFY ( iSize == 0 ); - }else{ - VERIFY ( iReservedSize > 0 ); - VERIFY ( iSize > 0 ); - delete[] pT; - pT = NULL; - } - } - // Returns the pointer to the given item. - IC T* item (u32 iItem) - { - VERIFY ( iItem < iSize ); - return ( &pT[iItem] ); - } - // Returns the pointer to the first item. - IC T* ptr ( ) { return (pT);} - // Returns the size of the list - IC u32 size ( ) const { return iSize; } - // Grows or shrinks the list to this number of items. - // Preserves existing items. - // Items that fall off the end of a shrink may vanish. - // Returns the pointer to the first item. - IC T* resize (u32 iNum) - { - VERIFY ( iNum >= 0 ); - iSize = iNum; - if ( iNum <= iReservedSize ){ - if ( iNum == 0 ){ - // Shrunk to 0 - bin the memory. - delete[] pT; - pT = NULL; - iReservedSize = 0; - }else{ - VERIFY ( pT != NULL ); - } - return ( pT ); - }else{ - // Need to grow. Grow by 50% more than - // needed to avoid constant regrows. - u32 iNewSize = ( iNum * 3 ) >> 1; - if ( pT == NULL ){ - VERIFY ( iReservedSize == 0 ); - pT = new T [iNewSize]; - }else{ - VERIFY ( iReservedSize != 0 ); - - T *pOldT = pT; - pT = new T[iNewSize]; - for ( u32 i = 0; i < iReservedSize; i++ ){ - pT[i] = pOldT[i]; - } - delete[] pOldT; - } - VERIFY ( pT != NULL ); - iReservedSize = iNewSize; - return ( pT ); - } - } - // Adds one item to the list and returns a pointer to that new item. - IC T* append ( ) - { - resize ( iSize + 1 ); - return ( &pT[iSize-1] ); - } - // Adds one item to the list and returns a pointer to that new item. - IC void push_back (T& val) - { - resize ( iSize + 1 ); - pT[iSize-1] = val; - } - // Removes the given item number by copying the last item - // to that position and shrinking the list. - IC void erase_fast (u32 iItemNumber) - { - VERIFY ( iItemNumber < iSize ); - pT[iItemNumber] = pT[iSize-1]; - resize ( iSize - 1 ); - } - // Copy the specified data into the list. - IC void insert (u32 iFirstItem, T *p, u32 iNumItems) - { - for ( u32 i = 0; i < iNumItems; i++ ) - *(Item ( i + iFirstItem ) ) = p[i]; - } - // A copy from another arbitrary list of the same type. - IC void insert ( u32 iFirstItem, ArbitraryList &other, u32 iFirstOtherItem, u32 iNumItems ) - { - for ( u32 i = 0; i < iNumItems; i++ ) - *(item ( i + iFirstItem ) ) = *(other.item ( i + iFirstOtherItem ) ); - } - IC T& operator[] (u32 id) { VERIFY(id &other ) - { - u32 iNumItems = other.size(); - - pT = NULL; - iSize = 0; - iReservedSize = 0; - if ( iNumItems > 0 ) - resize ( iNumItems ); - for ( u32 i = 0; i < iNumItems; i++ ) - *(item(i) ) = other[i]; - } + // Constructor, with optional initial size setting. + ArbitraryList(u32 iInitialSize = 0) + { + pT = NULL; + iSize = 0; + iReservedSize = 0; + if (iInitialSize>0) + resize(iInitialSize); + } + + // Destructor. + ~ArbitraryList(void) + { + if (pT==NULL) + { + VERIFY(iReservedSize==0); + VERIFY(iSize==0); + } + else + { + VERIFY(iReservedSize>0); + VERIFY(iSize>0); + delete[] pT; + pT = NULL; + } + } + + // Returns the pointer to the given item. + IC T*item(u32 iItem) + { + VERIFY(iItem=0); + iSize = iNum; + if (iNum<=iReservedSize) + { + if (iNum==0) + { + // Shrunk to 0 - bin the memory. + delete[] pT; + pT = NULL; + iReservedSize = 0; + } + else + { + VERIFY(pT!=NULL); + } + return (pT); + } + else + { + // Need to grow. Grow by 50% more than + // needed to avoid constant regrows. + u32 iNewSize = (iNum*3)>>1; + if (pT==NULL) + { + VERIFY(iReservedSize==0); + pT = new T [iNewSize]; + } + else + { + VERIFY(iReservedSize!=0); + + T *pOldT = pT; + pT = new T[iNewSize]; + for (u32 i = 0; i &other, u32 iFirstOtherItem, u32 iNumItems) + { + for (u32 i = 0; i &other) + { + u32 iNumItems = other.size(); + + pT = NULL; + iSize = 0; + iReservedSize = 0; + if (iNumItems>0) + resize(iNumItems); + for (u32 i = 0; iGetSettings(etfCSParent)) _IT.transform_dir(amount); - shape.box.m_halfsize.add(amount); - if (shape.box.m_halfsize.xGetSettings(etfCSParent)) _IT.transform_dir(amount); + shape.box.m_halfsize.add(amount); + if (shape.box.m_halfsize.xGetSettings(etfCSParent)) _IT.transform_dir(amount); - switch (shape.type){ - case SBoneShape::stBox:{ - Fmatrix R; - R.setXYZi(amount.x,amount.y,amount.z); - shape.box.transform(shape.box,R); - }break; - case SBoneShape::stSphere: break; - case SBoneShape::stCylinder:{ - Fmatrix R; - R.setXYZi(amount.x,amount.y,amount.z); - R.transform_dir(shape.cylinder.m_direction); - }break; + Fvector amount = _amount; + Fmatrix _IT; + _IT.invert(_LTransform()); + if (Tools->GetSettings(etfCSParent)) + _IT.transform_dir(amount); + switch (shape.type) + { + case SBoneShape::stBox: + { + Fmatrix R; + R.setXYZi(amount.x, amount.y, amount.z); + shape.box.transform(shape.box, R); + } + break; + case SBoneShape::stSphere: break; + case SBoneShape::stCylinder: + { + Fmatrix R; + R.setXYZi(amount.x, amount.y, amount.z); + R.transform_dir(shape.cylinder.m_direction); + } + break; } } -void CBone::ShapeMove(const Fvector& _amount) +void CBone::ShapeMove(const Fvector &_amount) { - Fvector amount=_amount; - Fmatrix _IT;_IT.invert(_LTransform()); - if (Tools->GetSettings(etfCSParent)) _IT.transform_dir(amount); - switch (shape.type){ - case SBoneShape::stBox: - shape.box.m_translate.add(amount); - break; - case SBoneShape::stSphere: - shape.sphere.P.add(amount); - break; - case SBoneShape::stCylinder:{ - shape.cylinder.m_center.add(amount); - }break; + Fvector amount = _amount; + Fmatrix _IT; + _IT.invert(_LTransform()); + if (Tools->GetSettings(etfCSParent)) + _IT.transform_dir(amount); + switch (shape.type) + { + case SBoneShape::stBox: + shape.box.m_translate.add(amount); + break; + case SBoneShape::stSphere: + shape.sphere.P.add(amount); + break; + case SBoneShape::stCylinder: + { + shape.cylinder.m_center.add(amount); + } + break; } } -void CBone::BindRotate(const Fvector& _amount) +void CBone::BindRotate(const Fvector &_amount) { - rest_rotate.add(_amount); + rest_rotate.add(_amount); } -void CBone::BindMove(const Fvector& _amount) +void CBone::BindMove(const Fvector &_amount) { - rest_offset.add(_amount); + rest_offset.add(_amount); } -bool CBone::Pick(float& dist, const Fvector& S, const Fvector& D, const Fmatrix& parent) +bool CBone::Pick(float &dist, const Fvector &S, const Fvector &D, const Fmatrix &parent) { - Fvector start, dir; - Fmatrix M; M.mul_43(parent,_LTransform()); + Fvector start, dir; + Fmatrix M; + M.mul_43(parent, _LTransform()); M.invert(); - M.transform_tiny(start,S); - M.transform_dir(dir,D); - switch (shape.type){ - case SBoneShape::stBox: return shape.box.intersect (start,dir,dist); - case SBoneShape::stSphere: return shape.sphere.intersect (start,dir,dist); - case SBoneShape::stCylinder:return shape.cylinder.intersect (start,dir,dist); - default: - Fsphere S; - S.P.set(0,0,0); - S.R=0.025f; - return S.intersect(start,dir,dist); + M.transform_tiny(start, S); + M.transform_dir(dir, D); + switch (shape.type) + { + case SBoneShape::stBox: return shape.box.intersect(start, dir, dist); + case SBoneShape::stSphere: return shape.sphere.intersect(start, dir, dist); + case SBoneShape::stCylinder: return shape.cylinder.intersect(start, dir, dist); + default: + Fsphere S; + S.P.set(0, 0, 0); + S.R = 0.025f; + return S.intersect(start, dir, dist); } } -void CBone::BoneRotate(const Fvector& _axis, float angle) +void CBone::BoneRotate(const Fvector &_axis, float angle) { - if (!fis_zero(angle)){ - if (Tools->GetSettings(etfCSParent)){ - // bind pose CS - mot_rotate.x += _axis.x*angle; + if (!fis_zero(angle)) + { + if (Tools->GetSettings(etfCSParent)) + { + // bind pose CS + mot_rotate.x += _axis.x*angle; mot_rotate.y += _axis.y*angle; mot_rotate.z += _axis.z*angle; - - ClampByLimits (); -/* - Fmatrix mBind,mBindI,mLocal,mRotate,mLocalBP; - mBind.setXYZi (rest_rotate); - mBindI.invert (mBind); - mLocal.setXYZi (mot_rotate); - Fvector axis; - mBind.transform (axis,_axis); - mRotate.rotation (axis,angle); - mLocal.mulA (mRotate); - - mLocalBP.mul (mBindI,mLocal); - Fvector mot; - mLocalBP.getXYZi (mot); - - IK_data.clamp_by_limits(mot); - mLocalBP.setXYZi (mot); - mLocal.mul (mBind,mLocalBP); - mLocal.getXYZi (mot_rotate); -*/ - }else{ - // local CS - Fmatrix mBind,mBindI,mRotate,mLocal,mLocalBP; - mBind.setXYZi (rest_rotate); - mBindI.invert (mBind); + ClampByLimits(); + /* + Fmatrix mBind,mBindI,mLocal,mRotate,mLocalBP; + mBind.setXYZi (rest_rotate); + mBindI.invert (mBind); + mLocal.setXYZi (mot_rotate); + Fvector axis; + mBind.transform (axis,_axis); + mRotate.rotation (axis,angle); + mLocal.mulA (mRotate); + + mLocalBP.mul (mBindI,mLocal); + Fvector mot; + mLocalBP.getXYZi (mot); + + IK_data.clamp_by_limits(mot); + + mLocalBP.setXYZi (mot); + mLocal.mul (mBind,mLocalBP); + mLocal.getXYZi (mot_rotate); + */ + } + else + { + // local CS + Fmatrix mBind, mBindI, mRotate, mLocal, mLocalBP; + mBind.setXYZi(rest_rotate); + mBindI.invert(mBind); Fvector axis; - _MTransform().transform_dir(axis,_axis); - + _MTransform().transform_dir(axis, _axis); + // rotation - mRotate.rotation (axis, angle); - mLocal.mul (mRotate,_MTransform()); - mLocal.getXYZi (mot_rotate); + mRotate.rotation(axis, angle); + mLocal.mul(mRotate, _MTransform()); + mLocal.getXYZi(mot_rotate); // local clamp - Fvector mot; - mLocalBP.mul (mBindI,mLocal); - mLocalBP.getXYZi (mot); + Fvector mot; + mLocalBP.mul(mBindI, mLocal); + mLocalBP.getXYZi(mot); - IK_data.clamp_by_limits(mot); + IK_data.clamp_by_limits(mot); - mLocalBP.setXYZi (mot); - mLocal.mul (mBind,mLocalBP); - mLocal.getXYZi (mot_rotate); + mLocalBP.setXYZi(mot); + mLocal.mul(mBind, mLocalBP); + mLocal.getXYZi(mot_rotate); } } } -void CBone::BoneMove(const Fvector& _amount) + +void CBone::BoneMove(const Fvector &_amount) { - Fvector amount=_amount; - switch (IK_data.type){ - case jtSlider: - amount.x = 0.f; - amount.y = 0.f; - rest_i_transform.transform (mot_offset); - mot_offset.add (amount); - clamp (mot_offset.z,rest_offset.z+IK_data.limits[0].limit.x,rest_offset.z+IK_data.limits[0].limit.y); - rest_transform.transform (mot_offset); - break; + Fvector amount = _amount; + switch (IK_data.type) + { + case jtSlider: + amount.x = 0.f; + amount.y = 0.f; + rest_i_transform.transform(mot_offset); + mot_offset.add(amount); + clamp(mot_offset.z, rest_offset.z+IK_data.limits[0].limit.x, rest_offset.z+IK_data.limits[0].limit.y); + rest_transform.transform(mot_offset); + break; } } void CBone::ClampByLimits() { - Fmatrix mBind,mBindI,mLocal,mLocalBP; - mBind.setXYZi (rest_rotate); - mBindI.invert (mBind); + Fmatrix mBind, mBindI, mLocal, mLocalBP; + mBind.setXYZi(rest_rotate); + mBindI.invert(mBind); - mLocal.setXYZi (mot_rotate); - mLocalBP.mul (mBindI,mLocal); + mLocal.setXYZi(mot_rotate); + mLocalBP.mul(mBindI, mLocal); Fvector mot; - mLocalBP.getXYZi (mot); + mLocalBP.getXYZi(mot); IK_data.clamp_by_limits(mot); - mLocalBP.setXYZi (mot); - mLocal.mul (mBind,mLocalBP); - mLocal.getXYZi (mot_rotate); -} \ No newline at end of file + mLocalBP.setXYZi(mot); + mLocal.mul(mBind, mLocalBP); + mLocal.getXYZi(mot_rotate); +} + diff --git a/src/editors/ECore/Editor/ColorPicker.cpp b/src/editors/ECore/Editor/ColorPicker.cpp index 89334c903af..5ce427c2026 100644 --- a/src/editors/ECore/Editor/ColorPicker.cpp +++ b/src/editors/ECore/Editor/ColorPicker.cpp @@ -4,56 +4,75 @@ #include "ColorPicker.h" -class CTCD{ +class CTCD +{ public: - TColorDialog* cdColor; + TColorDialog *cdColor; public: - CTCD(){ - cdColor = xr_new((TComponent*)0); + CTCD() + { + cdColor = xr_new((TComponent*)0); cdColor->Options = TColorDialogOptions()<Color = TColor(rgb2bgr(*currentcolor)); - if (TCD.cdColor->Execute()){ - *currentcolor = bgr2rgb(TCD.cdColor->Color); - return true; + if (TCD.cdColor->Execute()) + { + *currentcolor = bgr2rgb(TCD.cdColor->Color); + return true; } return false; - }else{ - u32 clr=*currentcolor; - if (FSColorPickerExecute(&clr, 0, 0)){ - *currentcolor = clr; - return true; + } + else + { + u32 clr = *currentcolor; + if (FSColorPickerExecute(&clr, 0, 0)) + { + *currentcolor = clr; + return true; } return false; } } -bool SelectColorWin(u32* currentcolor, bool bDefaultPicker){ - VERIFY(currentcolor); - if (bDefaultPicker){ +bool SelectColorWin(u32 *currentcolor, bool bDefaultPicker) +{ + VERIFY(currentcolor); + if (bDefaultPicker) + { TCD.cdColor->Color = TColor(*currentcolor); - if (TCD.cdColor->Execute()){ - *currentcolor = TCD.cdColor->Color; - return true; + if (TCD.cdColor->Execute()) + { + *currentcolor = TCD.cdColor->Color; + return true; } return false; - }else{ + } + else + { u32 cur = bgr2rgb(*currentcolor); - if (FSColorPickerExecute(&cur, 0, 0)){ - *currentcolor = rgb2bgr(cur); - return true; + if (FSColorPickerExecute(&cur, 0, 0)) + { + *currentcolor = rgb2bgr(cur); + return true; } - return false; + return false; } } diff --git a/src/editors/ECore/Editor/ColorPicker.h b/src/editors/ECore/Editor/ColorPicker.h index 288beaa7f0c..a1563110076 100644 --- a/src/editors/ECore/Editor/ColorPicker.h +++ b/src/editors/ECore/Editor/ColorPicker.h @@ -2,7 +2,9 @@ #ifndef ColorPickerH #define ColorPickerH -bool ECORE_API SelectColor(u32* currentcolor, bool bDefaultPicker=false); -bool ECORE_API SelectColorWin(u32* currentcolor, bool bDefaultPicker=false); +bool ECORE_API SelectColor(u32 *currentcolor, bool bDefaultPicker = false); +bool ECORE_API SelectColorWin(u32 *currentcolor, bool bDefaultPicker = false); #endif //ColorPicker + + diff --git a/src/editors/ECore/Editor/D3DUtils.cpp b/src/editors/ECore/Editor/D3DUtils.cpp index 731a229be54..c02000cd8da 100644 --- a/src/editors/ECore/Editor/D3DUtils.cpp +++ b/src/editors/ECore/Editor/D3DUtils.cpp @@ -3,8 +3,8 @@ #include "stdafx.h" #pragma hdrstop -#include "gamefont.h" -#include "d3dutils.h" +#include "xrEngine/GameFont.h" +#include "D3DUtils.h" #include "du_box.h" #include "du_sphere.h" #include "du_sphere_part.h" @@ -23,61 +23,61 @@ CDrawUtilities DU_impl; #define LINE_DIVISION 32 // не меньше 6!!!!! // for drawing sphere -static Fvector circledef1[LINE_DIVISION]; -static Fvector circledef2[LINE_DIVISION]; -static Fvector circledef3[LINE_DIVISION]; +static Fvector circledef1[LINE_DIVISION ]; +static Fvector circledef2[LINE_DIVISION ]; +static Fvector circledef3[LINE_DIVISION ]; -const u32 boxcolor = D3DCOLOR_RGBA(255,255,255,0); +const u32 boxcolor = D3DCOLOR_RGBA(255, 255, 255, 0); static const int boxvertcount = 48; static Fvector boxvert[boxvertcount]; #ifdef _EDITOR -# define DU_DRAW_RS EDevice.SetRS -# define DU_DRAW_SH_C(a,c){EDevice.SetShader(a);EDevice.SetRS(D3DRS_TEXTUREFACTOR,c);} -# define DU_DRAW_SH(a){EDevice.SetShader(a);EDevice.SetRS(D3DRS_TEXTUREFACTOR,0xFFFFFFFF);} +#define DU_DRAW_RS EDevice.SetRS +#define DU_DRAW_SH_C(a,c){EDevice.SetShader(a);EDevice.SetRS(D3DRS_TEXTUREFACTOR,c);} +#define DU_DRAW_SH(a){EDevice.SetShader(a);EDevice.SetRS(D3DRS_TEXTUREFACTOR,0xFFFFFFFF);} #else -# define DU_DRAW_RS RCache.dbg_SetRS -# define DU_DRAW_SH_C(sh,c){RCache.set_Shader(sh); RCache.set_c ("tfactor",float(color_get_R(c))/255.f,float(color_get_G(c))/255.f,float(color_get_B(c))/255.f,float(color_get_A(c))/255.f);} -# define DU_DRAW_SH(sh){RCache.set_Shader(sh); RCache.set_c ("tfactor",1,1,1,1);} +#define DU_DRAW_RS RCache.dbg_SetRS +#define DU_DRAW_SH_C(sh,c){RCache.set_Shader(sh); RCache.set_c ("tfactor",float(color_get_R(c))/255.f,float(color_get_G(c))/255.f,float(color_get_B(c))/255.f,float(color_get_A(c))/255.f);} +#define DU_DRAW_SH(sh){RCache.set_Shader(sh); RCache.set_c ("tfactor",1,1,1,1);} #endif #ifdef _EDITOR -# define FILL_MODE EDevice.dwFillMode -# define SHADE_MODE EDevice.dwShadeMode -# define SCREEN_QUALITY EDevice.m_ScreenQuality +#define FILL_MODE EDevice.dwFillMode +#define SHADE_MODE EDevice.dwShadeMode +#define SCREEN_QUALITY EDevice.m_ScreenQuality #else -# define FILL_MODE D3DFILL_SOLID -# define SHADE_MODE D3DSHADE_GOURAUD -# define SCREEN_QUALITY 1.f +#define FILL_MODE D3DFILL_SOLID +#define SHADE_MODE D3DSHADE_GOURAUD +#define SCREEN_QUALITY 1.f #endif // identity box -const u32 identboxcolor = D3DCOLOR_RGBA(255,255,255,0); +const u32 identboxcolor = D3DCOLOR_RGBA(255, 255, 255, 0); static const int identboxwirecount = 24; static Fvector identboxwire[identboxwirecount] = { - {-0.5f, -0.5f, -0.5f}, {-0.5f, +0.5f, -0.5f}, {-0.5f, +0.5f, -0.5f}, {+0.5f, +0.5f, -0.5f}, - {+0.5f, +0.5f, -0.5f}, {+0.5f, -0.5f, -0.5f}, {+0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, -0.5f}, - {-0.5f, +0.5f, +0.5f}, {+0.5f, +0.5f, +0.5f}, {+0.5f, +0.5f, +0.5f}, {+0.5f, -0.5f, +0.5f}, - {+0.5f, -0.5f, +0.5f}, {-0.5f, -0.5f, +0.5f}, {-0.5f, -0.5f, +0.5f}, {-0.5f, +0.5f, +0.5f}, - {-0.5f, +0.5f, -0.5f}, {-0.5f, +0.5f, +0.5f}, {+0.5f, +0.5f, -0.5f}, {+0.5f, +0.5f, +0.5f}, - {+0.5f, -0.5f, -0.5f}, {+0.5f, -0.5f, +0.5f}, {-0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, +0.5f} + {-0.5f, -0.5f, -0.5f},{-0.5f, +0.5f, -0.5f},{-0.5f, +0.5f, -0.5f},{+0.5f, +0.5f, -0.5f}, + {+0.5f, +0.5f, -0.5f},{+0.5f, -0.5f, -0.5f},{+0.5f, -0.5f, -0.5f},{-0.5f, -0.5f, -0.5f}, + {-0.5f, +0.5f, +0.5f},{+0.5f, +0.5f, +0.5f},{+0.5f, +0.5f, +0.5f},{+0.5f, -0.5f, +0.5f}, + {+0.5f, -0.5f, +0.5f},{-0.5f, -0.5f, +0.5f},{-0.5f, -0.5f, +0.5f},{-0.5f, +0.5f, +0.5f}, + {-0.5f, +0.5f, -0.5f},{-0.5f, +0.5f, +0.5f},{+0.5f, +0.5f, -0.5f},{+0.5f, +0.5f, +0.5f}, + {+0.5f, -0.5f, -0.5f},{+0.5f, -0.5f, +0.5f},{-0.5f, -0.5f, -0.5f},{-0.5f, -0.5f, +0.5f} }; /* static const int identboxindexcount = 36; static const WORD identboxindices[identboxindexcount] = { - 0, 1, 2, 2, 3, 0, - 3, 2, 6, 6, 7, 3, - 6, 4, 5, 6, 5, 7, + 0, 1, 2, 2, 3, 0, + 3, 2, 6, 6, 7, 3, + 6, 4, 5, 6, 5, 7, 4, 1, 5, 1, 0, 5, 3, 5, 0, 3, 7, 5, 1, 4, 6, 1, 6, 2}; static const int identboxindexwirecount = 24; static const WORD identboxindiceswire[identboxindexwirecount] = { - 0, 1, 1, 2, - 2, 3, 3, 0, - 4, 6, 6, 7, + 0, 1, 1, 2, + 2, 3, 3, 0, + 4, 6, 6, 7, 7, 5, 5, 4, 1, 4, 2, 6, 3, 7, 0, 5}; @@ -85,483 +85,591 @@ static const WORD identboxindiceswire[identboxindexwirecount] = { #define SIGN(x) ((x<0)?-1:1) -DEFINE_VECTOR(FVF::L,FLvertexVec,FLvertexIt) +DEFINE_VECTOR(FVF::L, FLvertexVec, FLvertexIt) -static FLvertexVec m_GridPoints; +static FLvertexVec m_GridPoints; -u32 m_ColorAxis = 0xff000000; -u32 m_ColorGrid = 0xff909090; +u32 m_ColorAxis = 0xff000000; +u32 m_ColorGrid = 0xff909090; u32 m_ColorGridTh = 0xffb4b4b4; -u32 m_SelectionRect=D3DCOLOR_RGBA(127,255,127,64); +u32 m_SelectionRect = D3DCOLOR_RGBA(127, 255, 127, 64); u32 m_ColorSafeRect = 0xffB040B0; -void SPrimitiveBuffer::CreateFromData(D3DPRIMITIVETYPE _pt, u32 _p_cnt, u32 FVF, LPVOID vertices, u32 _v_cnt, u16* indices, u32 _i_cnt) +void SPrimitiveBuffer::CreateFromData(D3DPRIMITIVETYPE _pt, u32 _p_cnt, u32 FVF, LPVOID vertices, u32 _v_cnt, u16 *indices, u32 _i_cnt) { - IDirect3DVertexBuffer9* pVB=0; - IDirect3DIndexBuffer9* pIB=0; - p_cnt = _p_cnt; - p_type = _pt; - v_cnt = _v_cnt; - i_cnt = _i_cnt; - u32 stride = D3DXGetFVFVertexSize(FVF); - R_CHK(HW.pDevice->CreateVertexBuffer(v_cnt*stride, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &pVB, 0)); - u8* bytes; - R_CHK (pVB->Lock(0,0,(LPVOID*)&bytes,0)); - FLvertexVec verts (v_cnt); - for (u32 k=0; kUnlock()); - if (i_cnt){ - R_CHK(HW.pDevice->CreateIndexBuffer(i_cnt*sizeof(u16),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pIB,NULL)); - R_CHK (pIB->Lock(0,0,(LPVOID*)&bytes,0)); - Memory.mem_copy (bytes,indices,i_cnt*sizeof(u16)); - R_CHK (pIB->Unlock()); - OnRender.bind (this,&SPrimitiveBuffer::RenderDIP); - }else{ - OnRender.bind (this,&SPrimitiveBuffer::RenderDP); - } - pGeom.create (FVF,pVB,pIB); + IDirect3DVertexBuffer9 *pVB = 0; + IDirect3DIndexBuffer9 *pIB = 0; + p_cnt = _p_cnt; + p_type = _pt; + v_cnt = _v_cnt; + i_cnt = _i_cnt; + u32 stride = D3DXGetFVFVertexSize(FVF); + R_CHK(HW.pDevice->CreateVertexBuffer(v_cnt*stride, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &pVB, 0)); + u8 *bytes; + R_CHK(pVB->Lock(0, 0, (LPVOID*)&bytes, 0)); + FLvertexVec verts(v_cnt); + for (u32 k = 0; kUnlock()); + if (i_cnt) + { + R_CHK(HW.pDevice->CreateIndexBuffer(i_cnt*sizeof(u16), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &pIB, NULL)); + R_CHK(pIB->Lock(0, 0, (LPVOID*)&bytes, 0)); + Memory.mem_copy(bytes, indices, i_cnt*sizeof(u16)); + R_CHK(pIB->Unlock()); + OnRender.bind(this, &SPrimitiveBuffer::RenderDIP); + } + else + { + OnRender.bind(this, &SPrimitiveBuffer::RenderDP); + } + pGeom.create(FVF, pVB, pIB); } + void SPrimitiveBuffer::Destroy() -{ - if (pGeom){ - _RELEASE (pGeom->vb); - _RELEASE (pGeom->ib); - pGeom.destroy (); - } +{ + if (pGeom) + { + _RELEASE(pGeom->vb); + _RELEASE(pGeom->ib); + pGeom.destroy(); + } } -void CDrawUtilities::UpdateGrid(int number_of_cell, float square_size, int subdiv){ - m_GridPoints.clear(); -// grid - int m_GridSubDiv[2]; - int m_GridCounts[2]; +void CDrawUtilities::UpdateGrid(int number_of_cell, float square_size, int subdiv) +{ + m_GridPoints.clear(); + // grid + int m_GridSubDiv[2]; + int m_GridCounts[2]; Fvector2 m_GridStep; - m_GridStep.set(square_size,square_size); - m_GridSubDiv[0] = subdiv; - m_GridSubDiv[1] = subdiv; - m_GridCounts[0] = number_of_cell;//iFloor(size/step)*subdiv; - m_GridCounts[1] = number_of_cell;//iFloor(size/step)*subdiv; - - FVF::L left,right; - left.p.y = right.p.y = 0; - - for(int thin=0; thin<2; thin++){ - for(int i=-m_GridCounts[0]; i<=m_GridCounts[0]; i++){ - if( (!!thin) != !!(i%m_GridSubDiv[0]) ){ - left.p.z = -m_GridCounts[1]*m_GridStep.y; - right.p.z = m_GridCounts[1]*m_GridStep.y; - left.p.x = i*m_GridStep.x; - right.p.x = left.p.x; - left.color = (i%m_GridSubDiv[0]) ? m_ColorGrid : m_ColorGridTh; - right.color = left.color; - m_GridPoints.push_back( left ); - m_GridPoints.push_back( right ); - } - } - for(i=-m_GridCounts[1]; i<=m_GridCounts[1]; i++){ - if( (!!thin) != !!(i%m_GridSubDiv[1]) ){ - left.p.x = -m_GridCounts[0]*m_GridStep.x; - right.p.x = m_GridCounts[0]*m_GridStep.x; - left.p.z = i*m_GridStep.y; - right.p.z = left.p.z; - left.color = (i%m_GridSubDiv[1]) ? m_ColorGrid : m_ColorGridTh; - right.color = left.color; - m_GridPoints.push_back( left ); - m_GridPoints.push_back( right ); - } - } - } + m_GridStep.set(square_size, square_size); + m_GridSubDiv[0] = subdiv; + m_GridSubDiv[1] = subdiv; + m_GridCounts[0] = number_of_cell;//iFloor(size/step)*subdiv; + m_GridCounts[1] = number_of_cell;//iFloor(size/step)*subdiv; + + FVF::L left, right; + left.p.y = right.p.y = 0; + + for (int thin = 0; thin<2; thin++) + { + for (int i = -m_GridCounts[0]; i<=m_GridCounts[0]; i++) + { + if ((!!thin)!=!!(i%m_GridSubDiv[0])) + { + left.p.z = -m_GridCounts[1]*m_GridStep.y; + right.p.z = m_GridCounts[1]*m_GridStep.y; + left.p.x = i*m_GridStep.x; + right.p.x = left.p.x; + left.color = (i%m_GridSubDiv[0]) ? m_ColorGrid : m_ColorGridTh; + right.color = left.color; + m_GridPoints.push_back(left); + m_GridPoints.push_back(right); + } + } + for (i = -m_GridCounts[1]; i<=m_GridCounts[1]; i++) + { + if ((!!thin)!=!!(i%m_GridSubDiv[1])) + { + left.p.x = -m_GridCounts[0]*m_GridStep.x; + right.p.x = m_GridCounts[0]*m_GridStep.x; + left.p.z = i*m_GridStep.y; + right.p.z = left.p.z; + left.color = (i%m_GridSubDiv[1]) ? m_ColorGrid : m_ColorGridTh; + right.color = left.color; + m_GridPoints.push_back(left); + m_GridPoints.push_back(right); + } + } + } } void CDrawUtilities::OnDeviceCreate() { - EDevice.seqRender.Add (this,REG_PRIORITY_LOW-1000); - - m_SolidBox.CreateFromData (D3DPT_TRIANGLELIST,DU_BOX_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices, DU_BOX_NUMVERTEX, du_box_faces, DU_BOX_NUMFACES*3); - m_SolidCone.CreateFromData (D3DPT_TRIANGLELIST,DU_CONE_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices, DU_CONE_NUMVERTEX, du_cone_faces, DU_CONE_NUMFACES*3); - m_SolidSphere.CreateFromData (D3DPT_TRIANGLELIST,DU_SPHERE_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_vertices, DU_SPHERE_NUMVERTEX, du_sphere_faces, DU_SPHERE_NUMFACES*3); - m_SolidSpherePart.CreateFromData(D3DPT_TRIANGLELIST,DU_SPHERE_PART_NUMFACES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices, DU_SPHERE_PART_NUMVERTEX, du_sphere_part_faces, DU_SPHERE_PART_NUMFACES*3); - m_SolidCylinder.CreateFromData (D3DPT_TRIANGLELIST,DU_CYLINDER_NUMFACES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices, DU_CYLINDER_NUMVERTEX, du_cylinder_faces, DU_CYLINDER_NUMFACES*3); - m_WireBox.CreateFromData (D3DPT_LINELIST, DU_BOX_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices, DU_BOX_NUMVERTEX, du_box_lines, DU_BOX_NUMLINES*2); - m_WireCone.CreateFromData (D3DPT_LINELIST, DU_CONE_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices, DU_CONE_NUMVERTEX, du_cone_lines, DU_CONE_NUMLINES*2); - m_WireSphere.CreateFromData (D3DPT_LINELIST, DU_SPHERE_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_verticesl, DU_SPHERE_NUMVERTEXL, du_sphere_lines, DU_SPHERE_NUMLINES*2); - m_WireSpherePart.CreateFromData (D3DPT_LINELIST, DU_SPHERE_PART_NUMLINES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices, DU_SPHERE_PART_NUMVERTEX, du_sphere_part_lines, DU_SPHERE_PART_NUMLINES*2); - m_WireCylinder.CreateFromData (D3DPT_LINELIST, DU_CYLINDER_NUMLINES, D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices, DU_CYLINDER_NUMVERTEX, du_cylinder_lines, DU_CYLINDER_NUMLINES*2); - - for(int i=0;i("hud_font_small"); + m_Font = xr_new("hud_font_small"); m_axis_object = NULL; } void CDrawUtilities::OnDeviceDestroy() { - EDevice.seqRender.Remove (this); - xr_delete (m_Font); - m_SolidBox.Destroy (); - m_SolidCone.Destroy (); - m_SolidSphere.Destroy (); - m_SolidSpherePart.Destroy (); - m_SolidCylinder.Destroy (); - m_WireBox.Destroy (); - m_WireCone.Destroy (); - m_WireSphere.Destroy (); - m_WireSpherePart.Destroy (); - m_WireCylinder.Destroy (); - - vs_L.destroy (); - vs_TL.destroy (); - vs_LIT.destroy (); - Lib.RemoveEditObject(m_axis_object); + EDevice.seqRender.Remove(this); + xr_delete(m_Font); + m_SolidBox.Destroy(); + m_SolidCone.Destroy(); + m_SolidSphere.Destroy(); + m_SolidSpherePart.Destroy(); + m_SolidCylinder.Destroy(); + m_WireBox.Destroy(); + m_WireCone.Destroy(); + m_WireSphere.Destroy(); + m_WireSpherePart.Destroy(); + m_WireCylinder.Destroy(); + + vs_L.destroy(); + vs_TL.destroy(); + vs_LIT.destroy(); + Lib.RemoveEditObject(m_axis_object); } + //---------------- -void CDrawUtilities::DrawSpotLight(const Fvector& p, const Fvector& d, float range, float phi, u32 clr) +void CDrawUtilities::DrawSpotLight(const Fvector &p, const Fvector &d, float range, float phi, u32 clr) { Fmatrix T; - Fvector p1; - float H,P; - float da = PI_MUL_2/LINE_DIVISION; - float b = range*_cos(PI_DIV_2-phi/2); - float a = range*_sin(PI_DIV_2-phi/2); - d.getHP (H,P); - T.setHPB (H,P,0); + Fvector p1; + float H, P; + float da = PI_MUL_2/LINE_DIVISION; + float b = range*_cos(PI_DIV_2-phi/2); + float a = range*_sin(PI_DIV_2-phi/2); + d.getHP(H, P); + T.setHPB(H, P, 0); T.translate_over(p); - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(LINE_DIVISION*2+2,vs_L->vb_stride,vBase); - for (float angle=0; angleLock(LINE_DIVISION*2+2, vs_L->vb_stride, vBase); + for (float angle = 0; angleset (p,clr); pv++; - pv->set (p1,clr); pv++; + pv->set(p, clr); + pv++; + pv->set(p1, clr); + pv++; } - p1.mad (p,d,range); - pv->set (p,clr); pv++; - pv->set (p1,clr); pv++; - Stream->Unlock (LINE_DIVISION*2+2,vs_L->vb_stride); + p1.mad(p, d, range); + pv->set(p, clr); + pv++; + pv->set(p1, clr); + pv++; + Stream->Unlock(LINE_DIVISION*2+2, vs_L->vb_stride); // and Render it as triangle list - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,LINE_DIVISION+1); + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase,LINE_DIVISION+1); } -void CDrawUtilities::DrawDirectionalLight(const Fvector& p, const Fvector& d, float radius, float range, u32 c) +void CDrawUtilities::DrawDirectionalLight(const Fvector &p, const Fvector &d, float radius, float range, u32 c) { - float r=radius*0.71f; - Fvector R,N,D; D.normalize(d); - Fmatrix rot; - - N.set (0,1,0); - if (_abs(D.y)>0.99f) N.set(1,0,0); - R.crossproduct(N,D); R.normalize(); - N.crossproduct(D,R); N.normalize(); - rot.set(R,N,D,p); - float sz=radius+range; - - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - pv->set (0,0,r, c); rot.transform_tiny(pv->p); pv++; - pv->set (0,0,sz, c); rot.transform_tiny(pv->p); pv++; - pv->set (-r,0,r, c); rot.transform_tiny(pv->p); pv++; - pv->set (-r,0,sz, c); rot.transform_tiny(pv->p); pv++; - pv->set (r,0,r, c); rot.transform_tiny(pv->p); pv++; - pv->set (r,0,sz, c); rot.transform_tiny(pv->p); pv++; - Stream->Unlock (6,vs_L->vb_stride); - - // and Render it as triangle list - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,3); + float r = radius*0.71f; + Fvector R, N, D; + D.normalize(d); + Fmatrix rot; + + N.set(0, 1, 0); + if (_abs(D.y)>0.99f) + N.set(1, 0, 0); + R.crossproduct(N, D); + R.normalize(); + N.crossproduct(D, R); + N.normalize(); + rot.set(R, N, D, p); + float sz = radius+range; + + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + pv->set(0, 0, r, c); + rot.transform_tiny(pv->p); + pv++; + pv->set(0, 0, sz, c); + rot.transform_tiny(pv->p); + pv++; + pv->set(-r, 0, r, c); + rot.transform_tiny(pv->p); + pv++; + pv->set(-r, 0, sz, c); + rot.transform_tiny(pv->p); + pv++; + pv->set(r, 0, r, c); + rot.transform_tiny(pv->p); + pv++; + pv->set(r, 0, sz, c); + rot.transform_tiny(pv->p); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + + // and Render it as triangle list + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, 3); Fbox b; - b.min.set(-r,-r,-r); - b.max.set(r,r,r); + b.min.set(-r, -r, -r); + b.max.set(r, r, r); - DrawLineSphere ( p, radius, c, true ); + DrawLineSphere(p, radius, c, true); } -void CDrawUtilities::DrawPointLight(const Fvector& p, float radius, u32 c) +void CDrawUtilities::DrawPointLight(const Fvector &p, float radius, u32 c) { - RCache.set_xform_world(Fidentity); - DrawCross(p, radius,radius,radius, radius,radius,radius, c, true); + RCache.set_xform_world(Fidentity); + DrawCross(p, radius, radius, radius, radius, radius, radius, c, true); } void CDrawUtilities::DrawEntity(u32 clr, ref_shader s) { - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (0.f,0.f,0.f,clr); pv++; - pv->set (0.f,1.f,0.f,clr); pv++; - pv->set (0.f,1.f,.5f,clr); pv++; - pv->set (0.f,.5f,.5f,clr); pv++; - pv->set (0.f,.5f,0.f,clr); pv++; - Stream->Unlock (5,vs_L->vb_stride); - // render flagshtok - DU_DRAW_SH (EDevice.m_WireShader); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,4); - - if (s) DU_DRAW_SH(s); + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(0.f, 0.f, 0.f, clr); + pv++; + pv->set(0.f, 1.f, 0.f, clr); + pv++; + pv->set(0.f, 1.f, .5f, clr); + pv++; + pv->set(0.f, .5f, .5f, clr); + pv++; + pv->set(0.f, .5f, 0.f, clr); + pv++; + Stream->Unlock(5, vs_L->vb_stride); + // render flagshtok + DU_DRAW_SH (EDevice.m_WireShader); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase, 4); + + if (s) + DU_DRAW_SH(s); { // fill VB - FVF::LIT* pv = (FVF::LIT*)Stream->Lock(6,vs_LIT->vb_stride,vBase); - pv->set (0.f,1.f,0.f,clr,0.f,0.f); pv++; - pv->set (0.f,1.f,.5f,clr,1.f,0.f); pv++; - pv->set (0.f,.5f,.5f,clr,1.f,1.f); pv++; - pv->set (0.f,.5f,0.f,clr,0.f,1.f); pv++; - pv->set (0.f,.5f,.5f,clr,1.f,1.f); pv++; - pv->set (0.f,1.f,.5f,clr,1.f,0.f); pv++; - Stream->Unlock (6,vs_LIT->vb_stride); + FVF::LIT*pv = (FVF::LIT*)Stream->Lock(6, vs_LIT->vb_stride, vBase); + pv->set(0.f, 1.f, 0.f, clr, 0.f, 0.f); + pv++; + pv->set(0.f, 1.f, .5f, clr, 1.f, 0.f); + pv++; + pv->set(0.f, .5f, .5f, clr, 1.f, 1.f); + pv++; + pv->set(0.f, .5f, 0.f, clr, 0.f, 1.f); + pv++; + pv->set(0.f, .5f, .5f, clr, 1.f, 1.f); + pv++; + pv->set(0.f, 1.f, .5f, clr, 1.f, 0.f); + pv++; + Stream->Unlock(6, vs_LIT->vb_stride); // and Render it as line list - DU_DRAW_DP (D3DPT_TRIANGLEFAN,vs_LIT,vBase,4); + DU_DRAW_DP(D3DPT_TRIANGLEFAN, vs_LIT, vBase, 4); } } -void CDrawUtilities::DrawFlag(const Fvector& p, float heading, float height, float sz, float sz_fl, u32 clr, BOOL bDrawEntity){ - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(2,vs_L->vb_stride,vBase); - pv->set (p,clr); pv++; - pv->set (p.x,p.y+height,p.z,clr); pv++; - Stream->Unlock (2,vs_L->vb_stride); - // and Render it as triangle list - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,1); - - if (bDrawEntity){ - // fill VB - float rx = _sin(heading); - float rz = _cos(heading); - FVF::L* pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - sz *= 0.8f; - pv->set (p.x,p.y+height,p.z,clr); pv++; - pv->set (p.x+rx*sz,p.y+height,p.z+rz*sz,clr); pv++; - sz *= 0.5f; - pv->set (p.x,p.y+height*(1.f-sz_fl*.5f),p.z,clr); pv++; - pv->set (p.x+rx*sz*0.6f,p.y+height*(1.f-sz_fl*.5f),p.z+rz*sz*0.75f,clr); pv++; - pv->set (p.x,p.y+height*(1.f-sz_fl),p.z,clr); pv++; - pv->set (p.x+rx*sz,p.y+height*(1.f-sz_fl),p.z+rz*sz,clr); pv++; - Stream->Unlock (6,vs_L->vb_stride); - // and Render it as line list - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,3); - }else{ - // fill VB - FVF::L* pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - pv->set (p.x,p.y+height*(1.f-sz_fl),p.z,clr); pv++; - pv->set (p.x,p.y+height,p.z,clr); pv++; - pv->set (p.x+_sin(heading)*sz,((pv-2)->p.y+(pv-1)->p.y)/2,p.z+_cos(heading)*sz,clr); pv++; - pv->set (*(pv-3)); pv++; - pv->set (*(pv-2)); pv++; - pv->set (*(pv-4)); pv++; - Stream->Unlock (6,vs_L->vb_stride); - // and Render it as triangle list - DU_DRAW_DP (D3DPT_TRIANGLELIST,vs_L,vBase,2); +void CDrawUtilities::DrawFlag(const Fvector &p, float heading, float height, float sz, float sz_fl, u32 clr, BOOL bDrawEntity) +{ + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(2, vs_L->vb_stride, vBase); + pv->set(p, clr); + pv++; + pv->set(p.x, p.y+height, p.z, clr); + pv++; + Stream->Unlock(2, vs_L->vb_stride); + // and Render it as triangle list + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, 1); + + if (bDrawEntity) + { + // fill VB + float rx = _sin(heading); + float rz = _cos(heading); + FVF::L*pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + sz *= 0.8f; + pv->set(p.x, p.y+height, p.z, clr); + pv++; + pv->set(p.x+rx*sz, p.y+height, p.z+rz*sz, clr); + pv++; + sz *= 0.5f; + pv->set(p.x, p.y+height*(1.f-sz_fl*.5f), p.z, clr); + pv++; + pv->set(p.x+rx*sz*0.6f, p.y+height*(1.f-sz_fl*.5f), p.z+rz*sz*0.75f, clr); + pv++; + pv->set(p.x, p.y+height*(1.f-sz_fl), p.z, clr); + pv++; + pv->set(p.x+rx*sz, p.y+height*(1.f-sz_fl), p.z+rz*sz, clr); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + // and Render it as line list + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, 3); + } + else + { + // fill VB + FVF::L*pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + pv->set(p.x, p.y+height*(1.f-sz_fl), p.z, clr); + pv++; + pv->set(p.x, p.y+height, p.z, clr); + pv++; + pv->set(p.x+_sin(heading)*sz, ((pv-2)->p.y+(pv-1)->p.y)/2, p.z+_cos(heading)*sz, clr); + pv++; + pv->set(*(pv-3)); + pv++; + pv->set(*(pv-2)); + pv++; + pv->set(*(pv-4)); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + // and Render it as triangle list + DU_DRAW_DP(D3DPT_TRIANGLELIST, vs_L, vBase, 2); } } //------------------------------------------------------------------------------ -void CDrawUtilities::DrawRomboid(const Fvector& p, float r, u32 c) +void CDrawUtilities::DrawRomboid(const Fvector &p, float r, u32 c) { -static const u32 IL[24]={0,2, 2,5, 0,5, 3,5, 3,0, 4,3, 4,0, 4,2, 1,2, 1,5, 1,3, 1,4}; -static const u32 IT[24]={2,4,0, 4,3,0, 3,5,0, 5,2,0, 4,2,1, 2,5,1, 5,3,1, 3,4,1}; -static Fvector PT [6] = { - {0.0f, 1.0f, 0.0f}, - {0.0f, -1.0f, 0.0f}, - {0.0f, 0.0f, -1.0f}, - {0.0f, 0.0f, 1.0f}, - {-1.0f, 0.0f, 0.0f}, - {1.0f, 0.0f, 0.0f}, -}; + static const u32 IL[24] = {0,2, 2,5, 0,5, 3,5, 3,0, 4,3, 4,0, 4,2, 1,2, 1,5, 1,3, 1,4}; + static const u32 IT[24] = {2,4,0, 4,3,0, 3,5,0, 5,2,0, 4,2,1, 2,5,1, 5,3,1, 3,4,1}; + static Fvector PT [6] = { + {0.0f, 1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.0f, 0.0f, -1.0f}, + {0.0f, 0.0f, 1.0f}, + {-1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + }; Fcolor C; - C.set (c); - C.mul_rgb (0.75); - u32 c1 = C.get(); + C.set(c); + C.mul_rgb(0.75); + u32 c1 = C.get(); - DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 8, p, PT, 6, IT, 24, c1, r); - DrawIndexedPrimitive(D3DPT_LINELIST, 12, p, PT, 6, IL, 24, c, r); - return; + DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 8, p, PT, 6, IT, 24, c1, r); + DrawIndexedPrimitive(D3DPT_LINELIST, 12, p, PT, 6, IL, 24, c, r); + return; u32 vBase, iBase; int k; - FVF::L* pv; - WORD* i; - _VertexStream* Stream = &RCache.Vertex; - _IndexStream* StreamI = &RCache.Index; - - // fill VB - pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - pv->set (p.x, p.y+r, p.z, c1); pv++; - pv->set (p.x, p.y-r, p.z, c1); pv++; - pv->set (p.x, p.y, p.z-r, c1); pv++; - pv->set (p.x, p.y, p.z+r, c1); pv++; - pv->set (p.x-r, p.y, p.z, c1); pv++; - pv->set (p.x+r, p.y, p.z, c1); pv++; - Stream->Unlock (6,vs_L->vb_stride); - - i = StreamI->Lock(24,iBase); - for (k=0; k<24; k++,i++) *i=IT[k]; + FVF::L *pv; + WORD*i; + _VertexStream *Stream = &RCache.Vertex; + _IndexStream *StreamI = &RCache.Index; + + // fill VB + pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + pv->set(p.x, p.y+r, p.z, c1); + pv++; + pv->set(p.x, p.y-r, p.z, c1); + pv++; + pv->set(p.x, p.y, p.z-r, c1); + pv++; + pv->set(p.x, p.y, p.z+r, c1); + pv++; + pv->set(p.x-r, p.y, p.z, c1); + pv++; + pv->set(p.x+r, p.y, p.z, c1); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + + i = StreamI->Lock(24, iBase); + for (k = 0; k<24; k++,i++) + *i = IT[k]; StreamI->Unlock(24); - // and Render it as triangle list - DU_DRAW_DIP (D3DPT_TRIANGLELIST,vs_L,vBase,0,6, iBase,12); + // and Render it as triangle list + DU_DRAW_DIP(D3DPT_TRIANGLELIST, vs_L, vBase, 0, 6, iBase, 12); // draw lines - pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - pv->set (p.x, p.y+r, p.z, c); pv++; - pv->set (p.x, p.y-r, p.z, c); pv++; - pv->set (p.x, p.y, p.z-r, c); pv++; - pv->set (p.x, p.y, p.z+r, c); pv++; - pv->set (p.x-r, p.y, p.z, c); pv++; - pv->set (p.x+r, p.y, p.z, c); pv++; - Stream->Unlock (6,vs_L->vb_stride); - - i = StreamI->Lock(24,iBase); - for (k=0; k<24; k++,i++) *i=IL[k]; - StreamI->Unlock (24); - - DU_DRAW_DIP (D3DPT_LINELIST,vs_L,vBase,0,6, iBase,12); - + pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + pv->set(p.x, p.y+r, p.z, c); + pv++; + pv->set(p.x, p.y-r, p.z, c); + pv++; + pv->set(p.x, p.y, p.z-r, c); + pv++; + pv->set(p.x, p.y, p.z+r, c); + pv++; + pv->set(p.x-r, p.y, p.z, c); + pv++; + pv->set(p.x+r, p.y, p.z, c); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + + i = StreamI->Lock(24, iBase); + for (k = 0; k<24; k++,i++) + *i = IL[k]; + StreamI->Unlock(24); + + DU_DRAW_DIP(D3DPT_LINELIST, vs_L, vBase, 0, 6, iBase, 12); } + //------------------------------------------------------------------------------ -void CDrawUtilities::DrawSound(const Fvector& p, float r, u32 c){ - DrawCross(p, r,r,r, r,r,r, c, true); +void CDrawUtilities::DrawSound(const Fvector &p, float r, u32 c) +{ + DrawCross(p, r, r, r, r, r, r, c, true); } + //------------------------------------------------------------------------------ -void CDrawUtilities::DrawIdentCone (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) +void CDrawUtilities::DrawIdentCone(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - if (bWire){ - DU_DRAW_SH_C (EDevice.m_WireShader, clr_w); - m_WireCone.Render (); + if (bWire) + { + DU_DRAW_SH_C (EDevice.m_WireShader, clr_w); + m_WireCone.Render(); } - if (bSolid){ - DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader, clr_s); - m_SolidCone.Render (); + if (bSolid) + { + DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader, clr_s); + m_SolidCone.Render(); } - DU_DRAW_RS (D3DRS_TEXTUREFACTOR, 0xffffffff); + DU_DRAW_RS(D3DRS_TEXTUREFACTOR, 0xffffffff); } -void CDrawUtilities::DrawIdentSphere (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) +void CDrawUtilities::DrawIdentSphere(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - if (bWire){ - DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); - m_WireSphere.Render (); + if (bWire) + { + DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); + m_WireSphere.Render(); } - if (bSolid){ - DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); - m_SolidSphere.Render(); + if (bSolid) + { + DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); + m_SolidSphere.Render(); } - DU_DRAW_RS (D3DRS_TEXTUREFACTOR, 0xffffffff); + DU_DRAW_RS(D3DRS_TEXTUREFACTOR, 0xffffffff); } void CDrawUtilities::DrawIdentSpherePart(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - if (bWire){ - DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); - m_WireSpherePart.Render (); + if (bWire) + { + DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); + m_WireSpherePart.Render(); } - if (bSolid){ - DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); - m_SolidSpherePart.Render(); + if (bSolid) + { + DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); + m_SolidSpherePart.Render(); } - DU_DRAW_RS (D3DRS_TEXTUREFACTOR, 0xffffffff); + DU_DRAW_RS(D3DRS_TEXTUREFACTOR, 0xffffffff); } -void CDrawUtilities::DrawIdentCylinder (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) +void CDrawUtilities::DrawIdentCylinder(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - if (bWire){ - DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); - m_WireCylinder.Render (); + if (bWire) + { + DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); + m_WireCylinder.Render(); } - if (bSolid){ - DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); - m_SolidCylinder.Render (); + if (bSolid) + { + DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); + m_SolidCylinder.Render(); } - DU_DRAW_RS (D3DRS_TEXTUREFACTOR, 0xffffffff); + DU_DRAW_RS(D3DRS_TEXTUREFACTOR, 0xffffffff); } void CDrawUtilities::DrawIdentBox(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - if (bWire){ - DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); - m_WireBox.Render (); + if (bWire) + { + DU_DRAW_SH_C (EDevice.m_WireShader,clr_w); + m_WireBox.Render(); } - if (bSolid){ - DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); - m_SolidBox.Render (); + if (bSolid) + { + DU_DRAW_SH_C (color_get_A(clr_s)>=254?EDevice.m_WireShader:EDevice.m_SelectionShader,clr_s); + m_SolidBox.Render(); } - DU_DRAW_RS (D3DRS_TEXTUREFACTOR, 0xffffffff); + DU_DRAW_RS(D3DRS_TEXTUREFACTOR, 0xffffffff); } -void CDrawUtilities::DrawLineSphere(const Fvector& p, float radius, u32 c, BOOL bCross) +void CDrawUtilities::DrawLineSphere(const Fvector &p, float radius, u32 c, BOOL bCross) { - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; int i; - FVF::L* pv; + FVF::L *pv; // seg 0 - pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1,vs_L->vb_stride,vBase); - for( i=0; ip.mad(p,circledef1[i],radius); pv->color=c;} + pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1, vs_L->vb_stride, vBase); + for (i = 0; ip.mad(p, circledef1[i], radius); + pv->color = c; + } pv->set(*(pv-LINE_DIVISION)); - Stream->Unlock (LINE_DIVISION+1,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,LINE_DIVISION); + Stream->Unlock(LINE_DIVISION+1, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase,LINE_DIVISION); // seg 1 - pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1,vs_L->vb_stride,vBase); - for( i=0; ip.mad(p,circledef2[i],radius); pv->color=c; pv++; } - pv->set(*(pv-LINE_DIVISION)); pv++; - Stream->Unlock (LINE_DIVISION+1,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,LINE_DIVISION); + pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1, vs_L->vb_stride, vBase); + for (i = 0; ip.mad(p, circledef2[i], radius); + pv->color = c; + pv++; + } + pv->set(*(pv-LINE_DIVISION)); + pv++; + Stream->Unlock(LINE_DIVISION+1, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase,LINE_DIVISION); // seg 2 - pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1,vs_L->vb_stride,vBase); - for( i=0; ip.mad(p,circledef3[i],radius); pv->color=c; pv++; } - pv->set(*(pv-LINE_DIVISION)); pv++; - Stream->Unlock (LINE_DIVISION+1,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,LINE_DIVISION); + pv = (FVF::L*)Stream->Lock(LINE_DIVISION+1, vs_L->vb_stride, vBase); + for (i = 0; ip.mad(p, circledef3[i], radius); + pv->color = c; + pv++; + } + pv->set(*(pv-LINE_DIVISION)); + pv++; + Stream->Unlock(LINE_DIVISION+1, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase,LINE_DIVISION); - if (bCross) DrawCross(p, radius,radius,radius, radius,radius,radius, c); + if (bCross) + DrawCross(p, radius, radius, radius, radius, radius, radius, c); } //---------------------------------------------------- @@ -571,737 +679,908 @@ IC float _x2real (float x) IC float _y2real (float y) { return (y+1)*EDevice.m_RenderHeight_2;} #else -IC float _x2real (float x) -{ return (x+1)*EDevice.dwWidth*0.5f; } -IC float _y2real (float y) -{ return (y+1)*EDevice.dwHeight*0.5f;} +IC + +float _x2real(float x) +{ + return (x+1)*EDevice.dwWidth*0.5f; +} + +IC + +float _y2real(float y) +{ + return (y+1)*EDevice.dwHeight*0.5f; +} #endif -void CDrawUtilities::dbgDrawPlacement(const Fvector& p, int sz, u32 clr, LPCSTR caption, u32 clr_font) +void CDrawUtilities::dbgDrawPlacement(const Fvector &p, int sz, u32 clr, LPCSTR caption, u32 clr_font) { - VERIFY( EDevice.b_is_Ready ); + VERIFY(EDevice.b_is_Ready); Fvector c; - float w = p.x*EDevice.mFullTransform._14 + p.y*EDevice.mFullTransform._24 + p.z*EDevice.mFullTransform._34 + EDevice.mFullTransform._44; - if (w<0) return; // culling + float w = p.x*EDevice.mFullTransform._14+p.y*EDevice.mFullTransform._24+p.z*EDevice.mFullTransform._34+EDevice.mFullTransform._44; + if (w<0) + return; // culling - float s = (float)sz; - EDevice.mFullTransform.transform(c,p); - c.x = (float)iFloor(_x2real(c.x)); c.y = (float)iFloor(_y2real(-c.y)); + float s = (float)sz; + EDevice.mFullTransform.transform(c, p); + c.x = (float)iFloor(_x2real(c.x)); + c.y = (float)iFloor(_y2real(-c.y)); - _VertexStream* Stream = &RCache.Vertex; + _VertexStream *Stream = &RCache.Vertex; u32 vBase; - FVF::TL* pv = (FVF::TL*)Stream->Lock(5,vs_TL->vb_stride,vBase); - pv->p.set(c.x-s,c.y-s,0,1); pv->color=clr; pv++; - pv->p.set(c.x+s,c.y-s,0,1); pv->color=clr; pv++; - pv->p.set(c.x+s,c.y+s,0,1); pv->color=clr; pv++; - pv->p.set(c.x-s,c.y+s,0,1); pv->color=clr; pv++; - pv->p.set(c.x-s,c.y-s,0,1); pv->color=clr; pv++; - Stream->Unlock(5,vs_TL->vb_stride); - - // Render it as line strip - DU_DRAW_DP (D3DPT_LINESTRIP,vs_TL,vBase,4); - if (caption){ - m_Font->SetColor(clr_font); - m_Font->Out(c.x,c.y+s,"%s",caption); + FVF::TL *pv = (FVF::TL*)Stream->Lock(5, vs_TL->vb_stride, vBase); + pv->p.set(c.x-s, c.y-s, 0, 1); + pv->color = clr; + pv++; + pv->p.set(c.x+s, c.y-s, 0, 1); + pv->color = clr; + pv++; + pv->p.set(c.x+s, c.y+s, 0, 1); + pv->color = clr; + pv++; + pv->p.set(c.x-s, c.y+s, 0, 1); + pv->color = clr; + pv++; + pv->p.set(c.x-s, c.y-s, 0, 1); + pv->color = clr; + pv++; + Stream->Unlock(5, vs_TL->vb_stride); + + // Render it as line strip + DU_DRAW_DP(D3DPT_LINESTRIP, vs_TL, vBase, 4); + if (caption) + { + m_Font->SetColor(clr_font); + m_Font->Out(c.x, c.y+s, "%s", caption); } } -void CDrawUtilities::dbgDrawVert(const Fvector& p0, u32 clr, LPCSTR caption) +void CDrawUtilities::dbgDrawVert(const Fvector &p0, u32 clr, LPCSTR caption) { - dbgDrawPlacement(p0,1,clr,caption); - DrawCross (p0,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); + dbgDrawPlacement(p0, 1, clr, caption); + DrawCross(p0, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); } -void CDrawUtilities::dbgDrawEdge(const Fvector& p0, const Fvector& p1, u32 clr, LPCSTR caption) +void CDrawUtilities::dbgDrawEdge(const Fvector &p0, const Fvector &p1, u32 clr, LPCSTR caption) { - dbgDrawPlacement(p0,1,clr,caption); - DrawCross (p0,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); - DrawCross (p1,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); - DrawLine (p0,p1,clr); + dbgDrawPlacement(p0, 1, clr, caption); + DrawCross(p0, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); + DrawCross(p1, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); + DrawLine(p0, p1, clr); } -void CDrawUtilities::dbgDrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr, LPCSTR caption) +void CDrawUtilities::dbgDrawFace(const Fvector &p0, const Fvector &p1, const Fvector &p2, u32 clr, LPCSTR caption) { - dbgDrawPlacement(p0,1,clr,caption); - DrawCross (p0,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); - DrawCross (p1,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); - DrawCross (p2,0.01f,0.01f,0.01f, 0.01f,0.01f,0.01f, clr,false); - DrawLine (p0,p1,clr); - DrawLine (p1,p2,clr); - DrawLine (p2,p0,clr); + dbgDrawPlacement(p0, 1, clr, caption); + DrawCross(p0, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); + DrawCross(p1, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); + DrawCross(p2, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, 0.01f, clr, false); + DrawLine(p0, p1, clr); + DrawLine(p1, p2, clr); + DrawLine(p2, p0, clr); } + //---------------------------------------------------- -void CDrawUtilities::DrawLine(const Fvector& p0, const Fvector& p1, u32 c){ - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(2,vs_L->vb_stride,vBase); - pv->set (p0,c); pv++; - pv->set (p1,c); pv++; - Stream->Unlock (2,vs_L->vb_stride); - // and Render it as triangle list - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,1); +void CDrawUtilities::DrawLine(const Fvector &p0, const Fvector &p1, u32 c) +{ + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(2, vs_L->vb_stride, vBase); + pv->set(p0, c); + pv++; + pv->set(p1, c); + pv++; + Stream->Unlock(2, vs_L->vb_stride); + // and Render it as triangle list + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, 1); } -void CDrawUtilities::DrawSelectionBoxB(const Fbox& box, u32* c) +void CDrawUtilities::DrawSelectionBoxB(const Fbox &box, u32 *c) { - Fvector S,C; + Fvector S, C; box.getsize(S); box.getcenter(C); - DrawSelectionBox(C,S,c); + DrawSelectionBox(C, S, c); } //---------------------------------------------------- -void CDrawUtilities::DrawSelectionBox(const Fvector& C, const Fvector& S, u32* clr) +void CDrawUtilities::DrawSelectionBox(const Fvector &C, const Fvector &S, u32 *clr) { - u32 cc=(clr)?*clr:boxcolor; - - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(boxvertcount,vs_L->vb_stride,vBase); - for (int i=0; ip.mul(boxvert[i],S); + u32 cc = (clr) ? *clr : boxcolor; + + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(boxvertcount, vs_L->vb_stride, vBase); + for (int i = 0; ip.mul(boxvert[i], S); pv->p.add(C); - pv->color = cc; + pv->color = cc; } - Stream->Unlock (boxvertcount,vs_L->vb_stride); + Stream->Unlock(boxvertcount, vs_L->vb_stride); - // and Render it as triangle list - DU_DRAW_RS (D3DRS_FILLMODE,D3DFILL_SOLID); - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,boxvertcount/2); - DU_DRAW_RS (D3DRS_FILLMODE,FILL_MODE); + // and Render it as triangle list + DU_DRAW_RS(D3DRS_FILLMODE, D3DFILL_SOLID); + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, boxvertcount/2); + DU_DRAW_RS(D3DRS_FILLMODE,FILL_MODE); } -void CDrawUtilities::DrawBox(const Fvector& offs, const Fvector& Size, BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) +void CDrawUtilities::DrawBox(const Fvector &offs, const Fvector &Size, BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w) { - _VertexStream* Stream = &RCache.Vertex; - if (bWire){ - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(identboxwirecount,vs_L->vb_stride,vBase); - for (int i=0; ip.mul (identboxwire[i],Size); - pv->p.mul (2); - pv->p.add (offs); - pv->color = clr_w; + _VertexStream *Stream = &RCache.Vertex; + if (bWire) + { + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(identboxwirecount, vs_L->vb_stride, vBase); + for (int i = 0; ip.mul(identboxwire[i], Size); + pv->p.mul(2); + pv->p.add(offs); + pv->color = clr_w; } - Stream->Unlock(identboxwirecount,vs_L->vb_stride); + Stream->Unlock(identboxwirecount, vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,identboxwirecount/2); + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, identboxwirecount/2); } - if (bSolid){ - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(DU_BOX_NUMVERTEX2,vs_L->vb_stride,vBase); - for (int i=0; ip.mul (du_box_vertices2[i],Size); - pv->p.mul (2); - pv->p.add (offs); - pv->color = clr_s; + if (bSolid) + { + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(DU_BOX_NUMVERTEX2, vs_L->vb_stride, vBase); + for (int i = 0; ip.mul(du_box_vertices2[i], Size); + pv->p.mul(2); + pv->p.add(offs); + pv->color = clr_s; } - Stream->Unlock(DU_BOX_NUMVERTEX2,vs_L->vb_stride); + Stream->Unlock(DU_BOX_NUMVERTEX2, vs_L->vb_stride); - DU_DRAW_DP (D3DPT_TRIANGLELIST,vs_L,vBase,DU_BOX_NUMFACES); + DU_DRAW_DP(D3DPT_TRIANGLELIST, vs_L, vBase,DU_BOX_NUMFACES); } } + //---------------------------------------------------- -void CDrawUtilities::DrawOBB(const Fmatrix& parent, const Fobb& box, u32 clr_s, u32 clr_w) +void CDrawUtilities::DrawOBB(const Fmatrix &parent, const Fobb &box, u32 clr_s, u32 clr_w) { - Fmatrix R,S,X; - box.xform_get (R); - S.scale (box.m_halfsize.x*2.f,box.m_halfsize.y*2.f,box.m_halfsize.z*2.f); - X.mul_43 (R,S); - R.mul_43 (parent,X); - RCache.set_xform_world(R); - DrawIdentBox (true,true,clr_s,clr_w); + Fmatrix R, S, X; + box.xform_get(R); + S.scale(box.m_halfsize.x*2.f, box.m_halfsize.y*2.f, box.m_halfsize.z*2.f); + X.mul_43(R, S); + R.mul_43(parent, X); + RCache.set_xform_world(R); + DrawIdentBox(true, true, clr_s, clr_w); } + //---------------------------------------------------- -void CDrawUtilities::DrawAABB(const Fmatrix& parent, const Fvector& center, const Fvector& size, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawAABB(const Fmatrix &parent, const Fvector ¢er, const Fvector &size, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { - Fmatrix R,S; - S.scale (size.x*2.f,size.y*2.f,size.z*2.f); + Fmatrix R, S; + S.scale(size.x*2.f, size.y*2.f, size.z*2.f); S.translate_over(center); - R.mul_43 (parent,S); - RCache.set_xform_world(R); - DrawIdentBox (bSolid,bWire,clr_s,clr_w); + R.mul_43(parent, S); + RCache.set_xform_world(R); + DrawIdentBox(bSolid, bWire, clr_s, clr_w); } -void CDrawUtilities::DrawAABB(const Fvector& p0, const Fvector& p1, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawAABB(const Fvector &p0, const Fvector &p1, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { - Fmatrix R; - Fvector C; C.set((p1.x+p0.x)*0.5f,(p1.y+p0.y)*0.5f,(p1.z+p0.z)*0.5f); - R.scale (_abs(p1.x-p0.x),_abs(p1.y-p0.y),_abs(p1.z-p0.z)); + Fmatrix R; + Fvector C; + C.set((p1.x+p0.x)*0.5f, (p1.y+p0.y)*0.5f, (p1.z+p0.z)*0.5f); + R.scale(_abs(p1.x-p0.x), _abs(p1.y-p0.y), _abs(p1.z-p0.z)); R.translate_over(C); - RCache.set_xform_world(R); - DrawIdentBox (bSolid,bWire,clr_s,clr_w); + RCache.set_xform_world(R); + DrawIdentBox(bSolid, bWire, clr_s, clr_w); } -void CDrawUtilities::DrawSphere(const Fmatrix& parent, const Fvector& center, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawSphere(const Fmatrix &parent, const Fvector ¢er, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { Fmatrix B; - B.scale (radius,radius,radius); - B.translate_over (center); - B.mulA_43 (parent); + B.scale(radius, radius, radius); + B.translate_over(center); + B.mulA_43(parent); RCache.set_xform_world(B); - DrawIdentSphere (bSolid, bWire, clr_s,clr_w); + DrawIdentSphere(bSolid, bWire, clr_s, clr_w); } + //---------------------------------------------------- -void CDrawUtilities::DrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawFace(const Fvector &p0, const Fvector &p1, const Fvector &p2, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { - _VertexStream* Stream = &RCache.Vertex; + _VertexStream *Stream = &RCache.Vertex; - u32 vBase; + u32 vBase; if (bSolid) { - FVF::L* pv = (FVF::L*)Stream->Lock(3,vs_L->vb_stride,vBase); - pv->set (p0,clr_s); pv++; - pv->set (p1,clr_s); pv++; - pv->set (p2,clr_s); pv++; - Stream->Unlock (3,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_TRIANGLELIST,vs_L,vBase,1); + FVF::L *pv = (FVF::L*)Stream->Lock(3, vs_L->vb_stride, vBase); + pv->set(p0, clr_s); + pv++; + pv->set(p1, clr_s); + pv++; + pv->set(p2, clr_s); + pv++; + Stream->Unlock(3, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_TRIANGLELIST, vs_L, vBase, 1); } if (bWire) { - FVF::L* pv = (FVF::L*)Stream->Lock(4,vs_L->vb_stride,vBase); - pv->set (p0,clr_w); pv++; - pv->set (p1,clr_w); pv++; - pv->set (p2,clr_w); pv++; - pv->set (p0,clr_w); pv++; - Stream->Unlock (4,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,3); + FVF::L *pv = (FVF::L*)Stream->Lock(4, vs_L->vb_stride, vBase); + pv->set(p0, clr_w); + pv++; + pv->set(p1, clr_w); + pv++; + pv->set(p2, clr_w); + pv++; + pv->set(p0, clr_w); + pv++; + Stream->Unlock(4, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase, 3); } } + //---------------------------------------------------- -static const u32 MAX_VERT_COUNT = 0xFFFF; +static const u32 MAX_VERT_COUNT = 0xFFFF; + void CDrawUtilities::DD_DrawFace_begin(BOOL bWire) { - VERIFY (m_DD_pv_start==0); - m_DD_wire = bWire; - m_DD_pv_start = (FVF::L*)RCache.Vertex.Lock(MAX_VERT_COUNT,vs_L->vb_stride,m_DD_base); - m_DD_pv = m_DD_pv_start; + VERIFY(m_DD_pv_start==0); + m_DD_wire = bWire; + m_DD_pv_start = (FVF::L*)RCache.Vertex.Lock(MAX_VERT_COUNT, vs_L->vb_stride, m_DD_base); + m_DD_pv = m_DD_pv_start; } + void CDrawUtilities::DD_DrawFace_flush(BOOL try_again) { - RCache.Vertex.Unlock((u32)(m_DD_pv-m_DD_pv_start),vs_L->vb_stride); - if (m_DD_wire) DU_DRAW_RS(D3DRS_FILLMODE,D3DFILL_WIREFRAME); - DU_DRAW_DP (D3DPT_TRIANGLELIST,vs_L,m_DD_base,u32(m_DD_pv-m_DD_pv_start)/3); - if (m_DD_wire) DU_DRAW_RS(D3DRS_FILLMODE,FILL_MODE); - if (try_again){ - m_DD_pv_start = (FVF::L*)RCache.Vertex.Lock(MAX_VERT_COUNT,vs_L->vb_stride,m_DD_base); - m_DD_pv = m_DD_pv_start; + RCache.Vertex.Unlock((u32)(m_DD_pv-m_DD_pv_start), vs_L->vb_stride); + if (m_DD_wire) DU_DRAW_RS(D3DRS_FILLMODE, D3DFILL_WIREFRAME); + DU_DRAW_DP(D3DPT_TRIANGLELIST, vs_L, m_DD_base, u32(m_DD_pv-m_DD_pv_start)/3); + if (m_DD_wire) DU_DRAW_RS(D3DRS_FILLMODE,FILL_MODE); + if (try_again) + { + m_DD_pv_start = (FVF::L*)RCache.Vertex.Lock(MAX_VERT_COUNT, vs_L->vb_stride, m_DD_base); + m_DD_pv = m_DD_pv_start; } } -void CDrawUtilities::DD_DrawFace_push(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr) + +void CDrawUtilities::DD_DrawFace_push(const Fvector &p0, const Fvector &p1, const Fvector &p2, u32 clr) { - m_DD_pv->set (p0,clr); m_DD_pv++; - m_DD_pv->set (p1,clr); m_DD_pv++; - m_DD_pv->set (p2,clr); m_DD_pv++; + m_DD_pv->set(p0, clr); + m_DD_pv++; + m_DD_pv->set(p1, clr); + m_DD_pv++; + m_DD_pv->set(p2, clr); + m_DD_pv++; if (m_DD_pv-m_DD_pv_start==MAX_VERT_COUNT) - DD_DrawFace_flush (TRUE); + DD_DrawFace_flush(TRUE); } + void CDrawUtilities::DD_DrawFace_end() { - DD_DrawFace_flush (FALSE); - m_DD_pv_start = 0; + DD_DrawFace_flush(FALSE); + m_DD_pv_start = 0; } + //---------------------------------------------------- -void CDrawUtilities::DrawCylinder(const Fmatrix& parent, const Fvector& center, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawCylinder(const Fmatrix &parent, const Fvector ¢er, const Fvector &dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { Fmatrix mScale; - mScale.scale (2.f*radius,2.f*radius,height); - + mScale.scale(2.f*radius, 2.f*radius, height); + // build final rotation / translation - Fvector L_dir,L_up,L_right; - L_dir.set (dir); L_dir.normalize (); - L_up.set (0,1,0); if (_abs(L_up.dotproduct(L_dir))>.99f) L_up.set(0,0,1); - L_right.crossproduct(L_up,L_dir); L_right.normalize (); - L_up.crossproduct (L_dir,L_right); L_up.normalize (); - - Fmatrix mR; - mR.i = L_right; mR._14 = 0; - mR.j = L_up; mR._24 = 0; - mR.k = L_dir; mR._34 = 0; - mR.c = center; mR._44 = 1; + Fvector L_dir, L_up, L_right; + L_dir.set(dir); + L_dir.normalize(); + L_up.set(0, 1, 0); + if (_abs(L_up.dotproduct(L_dir))>.99f) + L_up.set(0, 0, 1); + L_right.crossproduct(L_up, L_dir); + L_right.normalize(); + L_up.crossproduct(L_dir, L_right); + L_up.normalize(); + + Fmatrix mR; + mR.i = L_right; + mR._14 = 0; + mR.j = L_up; + mR._24 = 0; + mR.k = L_dir; + mR._34 = 0; + mR.c = center; + mR._44 = 1; // final xform - Fmatrix xf; xf.mul (mR,mScale); - xf.mulA_43 (parent); + Fmatrix xf; + xf.mul(mR, mScale); + xf.mulA_43(parent); RCache.set_xform_world(xf); - DrawIdentCylinder (bSolid,bWire,clr_s,clr_w); + DrawIdentCylinder(bSolid, bWire, clr_s, clr_w); } + //---------------------------------------------------- -void CDrawUtilities::DrawCone (const Fmatrix& parent, const Fvector& apex, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawCone(const Fmatrix &parent, const Fvector &apex, const Fvector &dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { Fmatrix mScale; - mScale.scale (2.f*radius,2.f*radius,height); - + mScale.scale(2.f*radius, 2.f*radius, height); + // build final rotation / translation - Fvector L_dir,L_up,L_right; - L_dir.set (dir); L_dir.normalize (); - L_up.set (0,1,0); if (_abs(L_up.dotproduct(L_dir))>.99f) L_up.set(0,0,1); - L_right.crossproduct(L_up,L_dir); L_right.normalize (); - L_up.crossproduct (L_dir,L_right); L_up.normalize (); - - Fmatrix mR; - mR.i = L_right; mR._14 = 0; - mR.j = L_up; mR._24 = 0; - mR.k = L_dir; mR._34 = 0; - mR.c = apex; mR._44 = 1; + Fvector L_dir, L_up, L_right; + L_dir.set(dir); + L_dir.normalize(); + L_up.set(0, 1, 0); + if (_abs(L_up.dotproduct(L_dir))>.99f) + L_up.set(0, 0, 1); + L_right.crossproduct(L_up, L_dir); + L_right.normalize(); + L_up.crossproduct(L_dir, L_right); + L_up.normalize(); + + Fmatrix mR; + mR.i = L_right; + mR._14 = 0; + mR.j = L_up; + mR._24 = 0; + mR.k = L_dir; + mR._34 = 0; + mR.c = apex; + mR._44 = 1; // final xform - Fmatrix xf; xf.mul (mR,mScale); - xf.mulA_43 (parent); + Fmatrix xf; + xf.mul(mR, mScale); + xf.mulA_43(parent); RCache.set_xform_world(xf); - DrawIdentCone (bSolid,bWire,clr_s,clr_w); + DrawIdentCone(bSolid, bWire, clr_s, clr_w); } + //---------------------------------------------------- -void CDrawUtilities::DrawPlane (const Fvector& p, const Fvector& n, const Fvector2& scale, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawPlane(const Fvector &p, const Fvector &n, const Fvector2 &scale, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire) { - if (n.square_magnitude().99f) L_dir.set(1,0,0); - L_right.crossproduct(L_up,L_dir); L_right.normalize (); - L_dir.crossproduct (L_right,L_up); L_dir.normalize (); - - Fmatrix mR; - mR.i = L_right; mR._14 = 0; - mR.j = L_up; mR._24 = 0; - mR.k = L_dir; mR._34 = 0; - mR.c = p; mR._44 = 1; - - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - - if (bSolid){ - DU_DRAW_SH(EDevice.m_SelectionShader); - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (-scale.x, 0, -scale.y, clr_s); mR.transform_tiny(pv->p); pv++; - pv->set (-scale.x, 0, +scale.y, clr_s); mR.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, +scale.y, clr_s); mR.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, -scale.y, clr_s); mR.transform_tiny(pv->p); pv++; - pv->set (*(pv-4)); - Stream->Unlock(5,vs_L->vb_stride); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_DP (D3DPT_TRIANGLEFAN,vs_L,vBase,2); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + Fvector L_dir, L_up = n, L_right; + L_dir.set(0, 0, 1); + if (_abs(L_up.dotproduct(L_dir))>.99f) + L_dir.set(1, 0, 0); + L_right.crossproduct(L_up, L_dir); + L_right.normalize(); + L_dir.crossproduct(L_right, L_up); + L_dir.normalize(); + + Fmatrix mR; + mR.i = L_right; + mR._14 = 0; + mR.j = L_up; + mR._24 = 0; + mR.k = L_dir; + mR._34 = 0; + mR.c = p; + mR._44 = 1; + + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + + if (bSolid) + { + DU_DRAW_SH(EDevice.m_SelectionShader); + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(-scale.x, 0, -scale.y, clr_s); + mR.transform_tiny(pv->p); + pv++; + pv->set(-scale.x, 0, +scale.y, clr_s); + mR.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, +scale.y, clr_s); + mR.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, -scale.y, clr_s); + mR.transform_tiny(pv->p); + pv++; + pv->set(*(pv-4)); + Stream->Unlock(5, vs_L->vb_stride); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_DP(D3DPT_TRIANGLEFAN, vs_L, vBase, 2); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } - if (bWire){ - DU_DRAW_SH(EDevice.m_WireShader); - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (-scale.x, 0, -scale.y, clr_w); mR.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, -scale.y, clr_w); mR.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, +scale.y, clr_w); mR.transform_tiny(pv->p); pv++; - pv->set (-scale.x, 0, +scale.y, clr_w); mR.transform_tiny(pv->p); pv++; - pv->set (*(pv-4)); - Stream->Unlock(5,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,4); + if (bWire) + { + DU_DRAW_SH(EDevice.m_WireShader); + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(-scale.x, 0, -scale.y, clr_w); + mR.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, -scale.y, clr_w); + mR.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, +scale.y, clr_w); + mR.transform_tiny(pv->p); + pv++; + pv->set(-scale.x, 0, +scale.y, clr_w); + mR.transform_tiny(pv->p); + pv++; + pv->set(*(pv-4)); + Stream->Unlock(5, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase, 4); } } + //---------------------------------------------------- -void CDrawUtilities::DrawPlane (const Fvector& center, const Fvector2& scale, const Fvector& rotate, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawPlane(const Fvector ¢er, const Fvector2 &scale, const Fvector &rotate, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire) { Fmatrix M; - M.setHPB (rotate.y,rotate.x,rotate.z); + M.setHPB(rotate.y, rotate.x, rotate.z); M.translate_over(center); - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - - if (bSolid){ - DU_DRAW_SH(EDevice.m_SelectionShader); - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (-scale.x, 0, -scale.y, clr_s); M.transform_tiny(pv->p); pv++; - pv->set (-scale.x, 0, +scale.y, clr_s); M.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, +scale.y, clr_s); M.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, -scale.y, clr_s); M.transform_tiny(pv->p); pv++; - pv->set (*(pv-4)); - Stream->Unlock(5,vs_L->vb_stride); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_DP (D3DPT_TRIANGLEFAN,vs_L,vBase,2); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + + if (bSolid) + { + DU_DRAW_SH(EDevice.m_SelectionShader); + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(-scale.x, 0, -scale.y, clr_s); + M.transform_tiny(pv->p); + pv++; + pv->set(-scale.x, 0, +scale.y, clr_s); + M.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, +scale.y, clr_s); + M.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, -scale.y, clr_s); + M.transform_tiny(pv->p); + pv++; + pv->set(*(pv-4)); + Stream->Unlock(5, vs_L->vb_stride); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_DP(D3DPT_TRIANGLEFAN, vs_L, vBase, 2); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } - if (bWire){ - DU_DRAW_SH(EDevice.m_WireShader); - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (-scale.x, 0, -scale.y, clr_w); M.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, -scale.y, clr_w); M.transform_tiny(pv->p); pv++; - pv->set (+scale.x, 0, +scale.y, clr_w); M.transform_tiny(pv->p); pv++; - pv->set (-scale.x, 0, +scale.y, clr_w); M.transform_tiny(pv->p); pv++; - pv->set (*(pv-4)); - Stream->Unlock(5,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,4); + if (bWire) + { + DU_DRAW_SH(EDevice.m_WireShader); + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(-scale.x, 0, -scale.y, clr_w); + M.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, -scale.y, clr_w); + M.transform_tiny(pv->p); + pv++; + pv->set(+scale.x, 0, +scale.y, clr_w); + M.transform_tiny(pv->p); + pv++; + pv->set(-scale.x, 0, +scale.y, clr_w); + M.transform_tiny(pv->p); + pv++; + pv->set(*(pv-4)); + Stream->Unlock(5, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase, 4); } } + //---------------------------------------------------- -void CDrawUtilities::DrawRectangle(const Fvector& o, const Fvector& u, const Fvector& v, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) +void CDrawUtilities::DrawRectangle(const Fvector &o, const Fvector &u, const Fvector &v, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { - _VertexStream* Stream = &RCache.Vertex; + _VertexStream *Stream = &RCache.Vertex; - u32 vBase; + u32 vBase; if (bSolid) { - DU_DRAW_SH(EDevice.m_SelectionShader); - FVF::L* pv = (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase); - pv->set (o.x, o.y, o.z, clr_s); pv++; - pv->set (o.x+u.x+v.x, o.y+u.y+v.y,o.z+u.z+v.z,clr_s); pv++; - pv->set (o.x+v.x, o.y+v.y, o.z+v.z, clr_s); pv++; - pv->set (o.x, o.y, o.z, clr_s); pv++; - pv->set (o.x+u.x, o.y+u.y, o.z+u.z, clr_s); pv++; - pv->set (o.x+u.x+v.x, o.y+u.y+v.y,o.z+u.z+v.z,clr_s); pv++; - Stream->Unlock (6,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_TRIANGLELIST,vs_L,vBase,2); + DU_DRAW_SH(EDevice.m_SelectionShader); + FVF::L *pv = (FVF::L*)Stream->Lock(6, vs_L->vb_stride, vBase); + pv->set(o.x, o.y, o.z, clr_s); + pv++; + pv->set(o.x+u.x+v.x, o.y+u.y+v.y, o.z+u.z+v.z, clr_s); + pv++; + pv->set(o.x+v.x, o.y+v.y, o.z+v.z, clr_s); + pv++; + pv->set(o.x, o.y, o.z, clr_s); + pv++; + pv->set(o.x+u.x, o.y+u.y, o.z+u.z, clr_s); + pv++; + pv->set(o.x+u.x+v.x, o.y+u.y+v.y, o.z+u.z+v.z, clr_s); + pv++; + Stream->Unlock(6, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_TRIANGLELIST, vs_L, vBase, 2); } if (bWire) { - DU_DRAW_SH(EDevice.m_WireShader); - FVF::L* pv = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase); - pv->set (o.x, o.y, o.z, clr_w); pv++; - pv->set (o.x+u.x, o.y+u.y, o.z+u.z, clr_w); pv++; - pv->set (o.x+u.x+v.x, o.y+u.y+v.y,o.z+u.z+v.z,clr_w); pv++; - pv->set (o.x+v.x, o.y+v.y, o.z+v.z, clr_w); pv++; - pv->set (o.x, o.y, o.z, clr_w); pv++; - Stream->Unlock (5,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINESTRIP,vs_L,vBase,4); + DU_DRAW_SH(EDevice.m_WireShader); + FVF::L *pv = (FVF::L*)Stream->Lock(5, vs_L->vb_stride, vBase); + pv->set(o.x, o.y, o.z, clr_w); + pv++; + pv->set(o.x+u.x, o.y+u.y, o.z+u.z, clr_w); + pv++; + pv->set(o.x+u.x+v.x, o.y+u.y+v.y, o.z+u.z+v.z, clr_w); + pv++; + pv->set(o.x+v.x, o.y+v.y, o.z+v.z, clr_w); + pv++; + pv->set(o.x, o.y, o.z, clr_w); + pv++; + Stream->Unlock(5, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINESTRIP, vs_L, vBase, 4); } } + //---------------------------------------------------- -void CDrawUtilities::DrawCross(const Fvector& p, float szx1, float szy1, float szz1, float szx2, float szy2, float szz2, u32 clr, BOOL bRot45) +void CDrawUtilities::DrawCross(const Fvector &p, float szx1, float szy1, float szz1, float szx2, float szy2, float szz2, u32 clr, BOOL bRot45) { - _VertexStream* Stream = &RCache.Vertex; - // actual rendering - u32 vBase; - FVF::L* pv = (FVF::L*)Stream->Lock(bRot45?12:6,vs_L->vb_stride,vBase); - pv->set(p.x+szx2,p.y,p.z,clr); pv++; - pv->set(p.x-szx1,p.y,p.z,clr); pv++; - pv->set(p.x,p.y+szy2,p.z,clr); pv++; - pv->set(p.x,p.y-szy1,p.z,clr); pv++; - pv->set(p.x,p.y,p.z+szz2,clr); pv++; - pv->set(p.x,p.y,p.z-szz1,clr); pv++; - if (bRot45){ - Fmatrix M; - M.setHPB(PI_DIV_4,PI_DIV_4,PI_DIV_4); - for(int i=0;i<6;i++,pv++){ - pv->p.sub((pv-6)->p,p); - M.transform_dir(pv->p); - pv->p.add(p); + _VertexStream *Stream = &RCache.Vertex; + // actual rendering + u32 vBase; + FVF::L *pv = (FVF::L*)Stream->Lock(bRot45 ? 12 : 6, vs_L->vb_stride, vBase); + pv->set(p.x+szx2, p.y, p.z, clr); + pv++; + pv->set(p.x-szx1, p.y, p.z, clr); + pv++; + pv->set(p.x, p.y+szy2, p.z, clr); + pv++; + pv->set(p.x, p.y-szy1, p.z, clr); + pv++; + pv->set(p.x, p.y, p.z+szz2, clr); + pv++; + pv->set(p.x, p.y, p.z-szz1, clr); + pv++; + if (bRot45) + { + Fmatrix M; + M.setHPB(PI_DIV_4, PI_DIV_4, PI_DIV_4); + for (int i = 0; i<6; i++,pv++) + { + pv->p.sub((pv-6)->p, p); + M.transform_dir(pv->p); + pv->p.add(p); pv->color = clr; } } - // unlock VB and Render it as triangle list - Stream->Unlock(bRot45?12:6,vs_L->vb_stride); - DU_DRAW_DP (D3DPT_LINELIST,vs_L,vBase,bRot45?6:3); + // unlock VB and Render it as triangle list + Stream->Unlock(bRot45 ? 12 : 6, vs_L->vb_stride); + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, bRot45 ? 6 : 3); } -void CDrawUtilities::DrawPivot(const Fvector& pos, float sz){ - DU_DRAW_SH(EDevice.m_WireShader); +void CDrawUtilities::DrawPivot(const Fvector &pos, float sz) +{ + DU_DRAW_SH(EDevice.m_WireShader); DrawCross(pos, sz, sz, sz, sz, sz, sz, 0xFF7FFF7F); } -void CDrawUtilities::DrawAxis(const Fmatrix& T) +void CDrawUtilities::DrawAxis(const Fmatrix &T) { -/* - _VertexStream* Stream = &RCache.Vertex; - Fvector p[6]; - u32 c[6]; - - // colors - c[0]=c[2]=c[4]=0x00222222; c[1]=0x00FF0000; c[3]=0x0000FF00; c[5]=0x000000FF; - - // position - p[0].mad(T.c,T.k,0.25f); - p[1].set(p[0]); p[1].x+=.015f; - p[2].set(p[0]); - p[3].set(p[0]); p[3].y+=.015f; - p[4].set(p[0]); - p[5].set(p[0]); p[5].z+=.015f; - - u32 vBase; - FVF::TL* pv = (FVF::TL*)Stream->Lock(6,vs_TL->vb_stride,vBase); - // transform to screen - float dx=-float(EDevice.dwWidth)/2.2f; - float dy=float(EDevice.dwHeight)/2.25f; - - for (int i=0; i<6; i++,pv++) - { - pv->color = c[i]; - pv->transform (p[i],EDevice.mFullTransform); - pv->p.set((float)iFloor(_x2real(pv->p.x)+dx),(float)iFloor(_y2real(pv->p.y)+dy),0,1); - p[i].set(pv->p.x,pv->p.y,0); - } - - // unlock VB and Render it as triangle list - Stream->Unlock(6,vs_TL->vb_stride); - DU_DRAW_RS(D3DRS_SHADEMODE,D3DSHADE_GOURAUD); - DU_DRAW_SH(EDevice.m_WireShader); - DU_DRAW_DP(D3DPT_LINELIST,vs_TL,vBase,3); - DU_DRAW_RS(D3DRS_SHADEMODE,SHADE_MODE); - - m_Font->SetColor(0xFF909090); - m_Font->Out(p[1].x,p[1].y,"x"); - m_Font->Out(p[3].x,p[3].y,"y"); - m_Font->Out(p[5].x,p[5].y,"z"); - m_Font->SetColor(0xFF000000); - m_Font->Out(p[1].x-1,p[1].y-1,"x"); - m_Font->Out(p[3].x-1,p[3].y-1,"y"); - m_Font->Out(p[5].x-1,p[5].y-1,"z"); -*/ - if(!m_axis_object) - m_axis_object = Lib.CreateEditObject("editor\\axis"); + /* + _VertexStream* Stream = &RCache.Vertex; + Fvector p[6]; + u32 c[6]; + + // colors + c[0]=c[2]=c[4]=0x00222222; c[1]=0x00FF0000; c[3]=0x0000FF00; c[5]=0x000000FF; + + // position + p[0].mad(T.c,T.k,0.25f); + p[1].set(p[0]); p[1].x+=.015f; + p[2].set(p[0]); + p[3].set(p[0]); p[3].y+=.015f; + p[4].set(p[0]); + p[5].set(p[0]); p[5].z+=.015f; + + u32 vBase; + FVF::TL* pv = (FVF::TL*)Stream->Lock(6,vs_TL->vb_stride,vBase); + // transform to screen + float dx=-float(EDevice.dwWidth)/2.2f; + float dy=float(EDevice.dwHeight)/2.25f; - Fmatrix M = Fidentity; - Fmatrix S; - S.scale (0.04f,0.04f,0.04f); - M.mulB_44 (S); + for (int i=0; i<6; i++,pv++) + { + pv->color = c[i]; + pv->transform (p[i],EDevice.mFullTransform); + pv->p.set((float)iFloor(_x2real(pv->p.x)+dx),(float)iFloor(_y2real(pv->p.y)+dy),0,1); + p[i].set(pv->p.x,pv->p.y,0); + } + + // unlock VB and Render it as triangle list + Stream->Unlock(6,vs_TL->vb_stride); + DU_DRAW_RS(D3DRS_SHADEMODE,D3DSHADE_GOURAUD); + DU_DRAW_SH(EDevice.m_WireShader); + DU_DRAW_DP(D3DPT_LINELIST,vs_TL,vBase,3); + DU_DRAW_RS(D3DRS_SHADEMODE,SHADE_MODE); + + m_Font->SetColor(0xFF909090); + m_Font->Out(p[1].x,p[1].y,"x"); + m_Font->Out(p[3].x,p[3].y,"y"); + m_Font->Out(p[5].x,p[5].y,"z"); + m_Font->SetColor(0xFF000000); + m_Font->Out(p[1].x-1,p[1].y-1,"x"); + m_Font->Out(p[3].x-1,p[3].y-1,"y"); + m_Font->Out(p[5].x-1,p[5].y-1,"z"); + */ + if (!m_axis_object) + m_axis_object = Lib.CreateEditObject("editor\\axis"); + + Fmatrix M = Fidentity; + Fmatrix S; + S.scale(0.04f, 0.04f, 0.04f); + M.mulB_44(S); Fvector start, dir; Ivector2 pt; - static int _wh = 50; - static float _kl = 1.0f; + static int _wh = 50; + static float _kl = 1.0f; - pt.x = _wh; - pt.y = iFloor(UI->GetRealHeight()-_wh); + pt.x = _wh; + pt.y = iFloor(UI->GetRealHeight()-_wh); EDevice.m_Camera.MouseRayFromPoint(M.c, dir, pt); M.c.mad(dir, _kl); - m_axis_object->Render (M, 2, false); + m_axis_object->Render(M, 2, false); } -void CDrawUtilities::DrawObjectAxis(const Fmatrix& T, float sz, BOOL sel) +void CDrawUtilities::DrawObjectAxis(const Fmatrix &T, float sz, BOOL sel) { - VERIFY( EDevice.b_is_Ready ); - // RCache.set_xform_world (Fidentity); - _VertexStream* Stream = &RCache.Vertex; - Fvector c,r,n,d; - float w = T.c.x*EDevice.mFullTransform._14 + T.c.y*EDevice.mFullTransform._24 + T.c.z*EDevice.mFullTransform._34 + EDevice.mFullTransform._44; - if (w<0) - return; // culling - - float s = w*sz; - - EDevice.mFullTransform.transform(c,T.c); - r.mul(T.i,s); - r.add(T.c); + VERIFY(EDevice.b_is_Ready); + // RCache.set_xform_world (Fidentity); + _VertexStream *Stream = &RCache.Vertex; + Fvector c, r, n, d; + float w = T.c.x*EDevice.mFullTransform._14+T.c.y*EDevice.mFullTransform._24+T.c.z*EDevice.mFullTransform._34+EDevice.mFullTransform._44; + if (w<0) + return; // culling + + float s = w*sz; + + EDevice.mFullTransform.transform(c, T.c); + r.mul(T.i, s); + r.add(T.c); EDevice.mFullTransform.transform(r); - n.mul(T.j,s); - n.add(T.c); + n.mul(T.j, s); + n.add(T.c); EDevice.mFullTransform.transform(n); - d.mul(T.k,s); - d.add(T.c); + d.mul(T.k, s); + d.add(T.c); EDevice.mFullTransform.transform(d); - c.x = (float)iFloor(_x2real(c.x)); + c.x = (float)iFloor(_x2real(c.x)); c.y = (float)iFloor(_y2real(-c.y)); - r.x = (float)iFloor(_x2real(r.x)); + r.x = (float)iFloor(_x2real(r.x)); r.y = (float)iFloor(_y2real(-r.y)); - n.x = (float)iFloor(_x2real(n.x)); + n.x = (float)iFloor(_x2real(n.x)); n.y = (float)iFloor(_y2real(-n.y)); - d.x = (float)iFloor(_x2real(d.x)); + d.x = (float)iFloor(_x2real(d.x)); d.y = (float)iFloor(_y2real(-d.y)); u32 vBase; - FVF::TL* pv = (FVF::TL*)Stream->Lock(6,vs_TL->vb_stride,vBase); -/* - c.set (200,200,0); - d.set (150,250,0); - r.set (300,200,0); - n.set (200,100,0); -*/ - pv->set (c.x, c.y, 0, 1, 0xFF222222, 0,0); pv++; - pv->set (d.x, d.y, 0, 1, sel?0xFF0000FF:0xFF000080, 0,0); pv++; - pv->set (c.x, c.y, 0, 1, 0xFF222222, 0,0); pv++; - pv->set (r.x, r.y, 0, 1, sel?0xFFFF0000:0xFF800000, 0,0); pv++; - pv->set (c.x, c.y, 0, 1, 0xFF222222, 0,0); pv++; - pv->set (n.x, n.y, 0, 1, sel?0xFF00FF00:0xFF008000, 0,0); - Stream->Unlock(6,vs_TL->vb_stride); - - // Render it as line list - DU_DRAW_RS (D3DRS_SHADEMODE,D3DSHADE_GOURAUD); - DU_DRAW_SH (EDevice.m_WireShader); - DU_DRAW_DP (D3DPT_LINELIST,vs_TL,vBase,3); - DU_DRAW_RS (D3DRS_SHADEMODE,SHADE_MODE); - - m_Font->SetColor(sel?0xFF000000:0xFF909090); - m_Font->Out(r.x,r.y,"x"); - m_Font->Out(n.x,n.y,"y"); - m_Font->Out(d.x,d.y,"z"); - m_Font->SetColor(sel?0xFFFFFFFF:0xFF000000); - m_Font->Out(r.x-1,r.y-1,"x"); - m_Font->Out(n.x-1,n.y-1,"y"); - m_Font->Out(d.x-1,d.y-1,"z"); + FVF::TL *pv = (FVF::TL*)Stream->Lock(6, vs_TL->vb_stride, vBase); + /* + c.set (200,200,0); + d.set (150,250,0); + r.set (300,200,0); + n.set (200,100,0); + */ + pv->set(c.x, c.y, 0, 1, 0xFF222222, 0, 0); + pv++; + pv->set(d.x, d.y, 0, 1, sel ? 0xFF0000FF : 0xFF000080, 0, 0); + pv++; + pv->set(c.x, c.y, 0, 1, 0xFF222222, 0, 0); + pv++; + pv->set(r.x, r.y, 0, 1, sel ? 0xFFFF0000 : 0xFF800000, 0, 0); + pv++; + pv->set(c.x, c.y, 0, 1, 0xFF222222, 0, 0); + pv++; + pv->set(n.x, n.y, 0, 1, sel ? 0xFF00FF00 : 0xFF008000, 0, 0); + Stream->Unlock(6, vs_TL->vb_stride); + + // Render it as line list + DU_DRAW_RS(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); + DU_DRAW_SH (EDevice.m_WireShader); + DU_DRAW_DP(D3DPT_LINELIST, vs_TL, vBase, 3); + DU_DRAW_RS(D3DRS_SHADEMODE,SHADE_MODE); + + m_Font->SetColor(sel ? 0xFF000000 : 0xFF909090); + m_Font->Out(r.x, r.y, "x"); + m_Font->Out(n.x, n.y, "y"); + m_Font->Out(d.x, d.y, "z"); + m_Font->SetColor(sel ? 0xFFFFFFFF : 0xFF000000); + m_Font->Out(r.x-1, r.y-1, "x"); + m_Font->Out(n.x-1, n.y-1, "y"); + m_Font->Out(d.x-1, d.y-1, "z"); } void CDrawUtilities::DrawGrid() { - VERIFY( EDevice.b_is_Ready ); - _VertexStream* Stream = &RCache.Vertex; + VERIFY(EDevice.b_is_Ready); + _VertexStream *Stream = &RCache.Vertex; u32 vBase; - // fill VB - FVF::L* pv = (FVF::L*)Stream->Lock(m_GridPoints.size(),vs_L->vb_stride,vBase); - for (FLvertexIt v_it=m_GridPoints.begin(); v_it!=m_GridPoints.end(); v_it++,pv++) pv->set(*v_it); - Stream->Unlock(m_GridPoints.size(),vs_L->vb_stride); - // Render it as triangle list + // fill VB + FVF::L *pv = (FVF::L*)Stream->Lock(m_GridPoints.size(), vs_L->vb_stride, vBase); + for (FLvertexIt v_it = m_GridPoints.begin(); v_it!=m_GridPoints.end(); v_it++,pv++) + pv->set(*v_it); + Stream->Unlock(m_GridPoints.size(), vs_L->vb_stride); + // Render it as triangle list Fmatrix ddd; ddd.identity(); RCache.set_xform_world(ddd); - DU_DRAW_SH(EDevice.m_WireShader); - DU_DRAW_DP(D3DPT_LINELIST,vs_L,vBase,m_GridPoints.size()/2); + DU_DRAW_SH(EDevice.m_WireShader); + DU_DRAW_DP(D3DPT_LINELIST, vs_L, vBase, m_GridPoints.size()/2); } -void CDrawUtilities::DrawSelectionRect(const Ivector2& m_SelStart, const Ivector2& m_SelEnd){ - VERIFY( EDevice.b_is_Ready ); - // fill VB - _VertexStream* Stream = &RCache.Vertex; +void CDrawUtilities::DrawSelectionRect(const Ivector2 &m_SelStart, const Ivector2 &m_SelEnd) +{ + VERIFY(EDevice.b_is_Ready); + // fill VB + _VertexStream *Stream = &RCache.Vertex; u32 vBase; - FVF::TL* pv = (FVF::TL*)Stream->Lock(4,vs_TL->vb_stride,vBase); - pv->set(m_SelStart.x*SCREEN_QUALITY, m_SelStart.y*SCREEN_QUALITY, m_SelectionRect,0.f,0.f); pv++; - pv->set(m_SelStart.x*SCREEN_QUALITY, m_SelEnd.y*SCREEN_QUALITY, m_SelectionRect,0.f,0.f); pv++; - pv->set(m_SelEnd.x*SCREEN_QUALITY, m_SelEnd.y*SCREEN_QUALITY, m_SelectionRect,0.f,0.f); pv++; - pv->set(m_SelEnd.x*SCREEN_QUALITY, m_SelStart.y*SCREEN_QUALITY, m_SelectionRect,0.f,0.f); pv++; - Stream->Unlock(4,vs_TL->vb_stride); - // Render it as triangle list - DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_SH(EDevice.m_SelectionShader); - DU_DRAW_DP(D3DPT_TRIANGLEFAN,vs_TL,vBase,2); - DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + FVF::TL *pv = (FVF::TL*)Stream->Lock(4, vs_TL->vb_stride, vBase); + pv->set(m_SelStart.x*SCREEN_QUALITY, m_SelStart.y*SCREEN_QUALITY, m_SelectionRect, 0.f, 0.f); + pv++; + pv->set(m_SelStart.x*SCREEN_QUALITY, m_SelEnd.y*SCREEN_QUALITY, m_SelectionRect, 0.f, 0.f); + pv++; + pv->set(m_SelEnd.x*SCREEN_QUALITY, m_SelEnd.y*SCREEN_QUALITY, m_SelectionRect, 0.f, 0.f); + pv++; + pv->set(m_SelEnd.x*SCREEN_QUALITY, m_SelStart.y*SCREEN_QUALITY, m_SelectionRect, 0.f, 0.f); + pv++; + Stream->Unlock(4, vs_TL->vb_stride); + // Render it as triangle list + DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_SH(EDevice.m_SelectionShader); + DU_DRAW_DP(D3DPT_TRIANGLEFAN, vs_TL, vBase, 2); + DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } -void CDrawUtilities::DrawPrimitiveL (D3DPRIMITIVETYPE pt, u32 pc, Fvector* vertices, int vc, u32 color, BOOL bCull, BOOL bCycle) +void CDrawUtilities::DrawPrimitiveL(D3DPRIMITIVETYPE pt, u32 pc, Fvector *vertices, int vc, u32 color, BOOL bCull, BOOL bCycle) { - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase, dwNeed=(bCycle)?vc+1:vc; - FVF::L* pv = (FVF::L*)Stream->Lock(dwNeed,vs_L->vb_stride,vBase); - for(int k=0; kset (vertices[k],color); - if (bCycle) pv->set(*(pv-vc)); - Stream->Unlock(dwNeed,vs_L->vb_stride); - - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_DP (pt,vs_L,vBase,pc); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase, dwNeed = (bCycle) ? vc+1 : vc; + FVF::L *pv = (FVF::L*)Stream->Lock(dwNeed, vs_L->vb_stride, vBase); + for (int k = 0; kset(vertices[k], color); + if (bCycle) + pv->set(*(pv-vc)); + Stream->Unlock(dwNeed, vs_L->vb_stride); + + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_DP(pt, vs_L, vBase, pc); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } -void CDrawUtilities::DrawIndexedPrimitive( int pt, - u32 pc, - const Fvector& pos, - const Fvector* vb, - const u32& vb_size, - const u32* ib, - const u32& ib_size, - const u32& clr_argb, - float scale) +void CDrawUtilities::DrawIndexedPrimitive(int pt, + u32 pc, + const Fvector &pos, + const Fvector *vb, + const u32 &vb_size, + const u32 *ib, + const u32 &ib_size, + const u32 &clr_argb, + float scale) { - _VertexStream* Stream = &RCache.Vertex; - _IndexStream* StreamI = &RCache.Index; - - u32 vBase, iBase; - WORD* i; - - FVF::L* pv = (FVF::L*)Stream->Lock(vb_size, vs_L->vb_stride, vBase); - for(int k=0; kset (Fvector().add(pos, Fvector().mul(vb[k],scale)), clr_argb); - - Stream->Unlock(vb_size, vs_L->vb_stride); - - i = StreamI->Lock(ib_size,iBase); - for (k=0; kLock(vb_size, vs_L->vb_stride, vBase); + for (int k = 0; kset(Fvector().add(pos, Fvector().mul(vb[k], scale)), clr_argb); + + Stream->Unlock(vb_size, vs_L->vb_stride); + + i = StreamI->Lock(ib_size, iBase); + for (k = 0; kUnlock(ib_size); - EDevice.SetShader (EDevice.m_SelectionShader); - // and Render it as triangle list - DU_DRAW_DIP ((D3DPRIMITIVETYPE)pt, vs_L, vBase, 0, vb_size, iBase, pc); + EDevice.SetShader(EDevice.m_SelectionShader); + // and Render it as triangle list + DU_DRAW_DIP((D3DPRIMITIVETYPE)pt, vs_L, vBase, 0, vb_size, iBase, pc); } -void CDrawUtilities::DrawPrimitiveTL(D3DPRIMITIVETYPE pt, u32 pc, FVF::TL* vertices, int vc, BOOL bCull, BOOL bCycle) +void CDrawUtilities::DrawPrimitiveTL(D3DPRIMITIVETYPE pt, u32 pc, FVF::TL *vertices, int vc, BOOL bCull, BOOL bCycle) { - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase, dwNeed=(bCycle)?vc+1:vc; - FVF::TL* pv = (FVF::TL*)Stream->Lock(dwNeed,vs_TL->vb_stride,vBase); - for(int k=0; kset (vertices[k]); - if (bCycle) pv->set(*(pv-vc)); - Stream->Unlock(dwNeed,vs_TL->vb_stride); - - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_DP (pt,vs_TL,vBase,pc); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase, dwNeed = (bCycle) ? vc+1 : vc; + FVF::TL *pv = (FVF::TL*)Stream->Lock(dwNeed, vs_TL->vb_stride, vBase); + for (int k = 0; kset(vertices[k]); + if (bCycle) + pv->set(*(pv-vc)); + Stream->Unlock(dwNeed, vs_TL->vb_stride); + + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_DP(pt, vs_TL, vBase, pc); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } -void CDrawUtilities::DrawPrimitiveLIT(D3DPRIMITIVETYPE pt, u32 pc, FVF::LIT* vertices, int vc, BOOL bCull, BOOL bCycle) +void CDrawUtilities::DrawPrimitiveLIT(D3DPRIMITIVETYPE pt, u32 pc, FVF::LIT *vertices, int vc, BOOL bCull, BOOL bCycle) { - // fill VB - _VertexStream* Stream = &RCache.Vertex; - u32 vBase, dwNeed=(bCycle)?vc+1:vc; - FVF::LIT* pv = (FVF::LIT*)Stream->Lock(dwNeed,vs_LIT->vb_stride,vBase); - for(int k=0; kset (vertices[k]); - if (bCycle) pv->set(*(pv-vc)); - Stream->Unlock(dwNeed,vs_LIT->vb_stride); - - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE); - DU_DRAW_DP (pt,vs_LIT,vBase,pc); - if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW); + // fill VB + _VertexStream *Stream = &RCache.Vertex; + u32 vBase, dwNeed = (bCycle) ? vc+1 : vc; + FVF::LIT *pv = (FVF::LIT*)Stream->Lock(dwNeed, vs_LIT->vb_stride, vBase); + for (int k = 0; kset(vertices[k]); + if (bCycle) + pv->set(*(pv-vc)); + Stream->Unlock(dwNeed, vs_LIT->vb_stride); + + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_NONE); + DU_DRAW_DP(pt, vs_LIT, vBase, pc); + if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE, D3DCULL_CCW); } -void CDrawUtilities::DrawLink(const Fvector& p0, const Fvector& p1, float sz, u32 clr) +void CDrawUtilities::DrawLink(const Fvector &p0, const Fvector &p1, float sz, u32 clr) { - DrawLine(p1,p0,clr); - Fvector pp[2],D,R,N={0,1,0}; - D.sub(p1,p0); D.normalize(); - R.crossproduct(N,D); R.mul(0.5f); D.mul(2.0f); N.mul(0.5f); + DrawLine(p1, p0, clr); + Fvector pp[2], D, R, N = {0,1,0}; + D.sub(p1, p0); + D.normalize(); + R.crossproduct(N, D); + R.mul(0.5f); + D.mul(2.0f); + N.mul(0.5f); // LR - pp[0].add(R,D); pp[0].mul(sz*-0.5f); pp[0].add(p1); - R.invert(); - pp[1].add(R,D); pp[1].mul(sz*-0.5f); pp[1].add(p1); - DrawLine(p1,pp[0],clr); - DrawLine(p1,pp[1],clr); + pp[0].add(R, D); + pp[0].mul(sz*-0.5f); + pp[0].add(p1); + R.invert(); + pp[1].add(R, D); + pp[1].mul(sz*-0.5f); + pp[1].add(p1); + DrawLine(p1, pp[0], clr); + DrawLine(p1, pp[1], clr); // UB - pp[0].add(N,D); pp[0].mul(sz*-0.5f); pp[0].add(p1); + pp[0].add(N, D); + pp[0].mul(sz*-0.5f); + pp[0].add(p1); N.invert(); - pp[1].add(N,D); pp[1].mul(sz*-0.5f); pp[1].add(p1); - DrawLine(p1,pp[0],clr); - DrawLine(p1,pp[1],clr); + pp[1].add(N, D); + pp[1].mul(sz*-0.5f); + pp[1].add(p1); + DrawLine(p1, pp[0], clr); + DrawLine(p1, pp[1], clr); } -void CDrawUtilities::DrawJoint(const Fvector& p, float radius, u32 clr) +void CDrawUtilities::DrawJoint(const Fvector &p, float radius, u32 clr) { - // RCache.set_xform_world (Fidentity); - DrawLineSphere(p,radius,clr,false); + // RCache.set_xform_world (Fidentity); + DrawLineSphere(p, radius, clr, false); } void CDrawUtilities::OnRender() { - m_Font->OnRender(); + m_Font->OnRender(); } -void CDrawUtilities::OutText(const Fvector& pos, LPCSTR text, u32 color, u32 shadow_color) +void CDrawUtilities::OutText(const Fvector &pos, LPCSTR text, u32 color, u32 shadow_color) { - Fvector p; - float w = pos.x*EDevice.mFullTransform._14 + pos.y*EDevice.mFullTransform._24 + pos.z*EDevice.mFullTransform._34 + EDevice.mFullTransform._44; - if (w>=0){ - EDevice.mFullTransform.transform(p,pos); - p.x = (float)iFloor(_x2real(p.x)); p.y = (float)iFloor(_y2real(-p.y)); - - m_Font->SetColor(shadow_color); - m_Font->Out(p.x,p.y,(LPSTR)text); - m_Font->SetColor(color); - m_Font->Out(p.x-1,p.y-1,(LPSTR)text); - } + Fvector p; + float w = pos.x*EDevice.mFullTransform._14+pos.y*EDevice.mFullTransform._24+pos.z*EDevice.mFullTransform._34+EDevice.mFullTransform._44; + if (w>=0) + { + EDevice.mFullTransform.transform(p, pos); + p.x = (float)iFloor(_x2real(p.x)); + p.y = (float)iFloor(_y2real(-p.y)); + + m_Font->SetColor(shadow_color); + m_Font->Out(p.x, p.y, (LPSTR)text); + m_Font->SetColor(color); + m_Font->Out(p.x-1, p.y-1, (LPSTR)text); + } } + diff --git a/src/editors/ECore/Editor/D3DUtils.h b/src/editors/ECore/Editor/D3DUtils.h index 38912ce08b9..bae99d9ab34 100644 --- a/src/editors/ECore/Editor/D3DUtils.h +++ b/src/editors/ECore/Editor/D3DUtils.h @@ -4,8 +4,8 @@ #ifndef D3DUtilsH_included #define D3DUtilsH_included - -#include "..\Include\xrRender\DrawUtils.h" + +#include "Include\xrRender\DrawUtils.h" //---------------------------------------------------- #ifdef _EDITOR @@ -18,135 +18,160 @@ class CEditableObject; -struct SPrimitiveBuffer{ - ref_geom pGeom; - u32 v_cnt; - u32 i_cnt; - D3DPRIMITIVETYPE p_type; - u32 p_cnt; - typedef fastdelegate::FastDelegate0<> TOnRender; - TOnRender OnRender; - void xr_stdcall RenderDIP() {DU_DRAW_DIP(p_type,pGeom,0,0,v_cnt,0,p_cnt);} - void xr_stdcall RenderDP() {DU_DRAW_DP (p_type,pGeom,0,p_cnt);} +struct SPrimitiveBuffer +{ + ref_geom pGeom; + u32 v_cnt; + u32 i_cnt; + D3DPRIMITIVETYPE p_type; + u32 p_cnt; + typedef fastdelegate::FastDelegate0<> TOnRender; + TOnRender OnRender; + + void xr_stdcall RenderDIP() + { + DU_DRAW_DIP(p_type, pGeom, 0, 0, v_cnt, 0, p_cnt); + } + + void xr_stdcall RenderDP() + { + DU_DRAW_DP(p_type, pGeom, 0, p_cnt); + } + public: - SPrimitiveBuffer():OnRender(0),pGeom(0){;} - void CreateFromData(D3DPRIMITIVETYPE _pt, u32 _p_cnt, u32 FVF, LPVOID vertices, u32 _v_cnt, u16* indices=0, u32 _i_cnt=0); - void Destroy(); - void Render(){OnRender();} + SPrimitiveBuffer(): OnRender(0), pGeom(0) + { + ; + } + + void CreateFromData(D3DPRIMITIVETYPE _pt, u32 _p_cnt, u32 FVF, LPVOID vertices, u32 _v_cnt, u16 *indices = 0, u32 _i_cnt = 0); + void Destroy(); + + void Render() + { + OnRender(); + } }; //---------------------------------------------------- // Utilities //---------------------------------------------------- -class ECORE_API CDrawUtilities: public CDUInterface, public pureRender{ - SPrimitiveBuffer m_SolidCone; - SPrimitiveBuffer m_WireCone; - SPrimitiveBuffer m_SolidSphere; - SPrimitiveBuffer m_WireSphere; - SPrimitiveBuffer m_SolidSpherePart; - SPrimitiveBuffer m_WireSpherePart; - SPrimitiveBuffer m_SolidCylinder; - SPrimitiveBuffer m_WireCylinder; - SPrimitiveBuffer m_SolidBox; - SPrimitiveBuffer m_WireBox; - CGameFont* m_Font; - CEditableObject* m_axis_object; -public: - ref_geom vs_L; - ref_geom vs_TL; - ref_geom vs_LIT; -protected: - FVF::L* m_DD_pv; - FVF::L* m_DD_pv_start; - u32 m_DD_base; - BOOL m_DD_wire; - void DD_DrawFace_flush (BOOL try_again); -public: - void DD_DrawFace_begin (BOOL bWire); - void DD_DrawFace_push (const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr); - void DD_DrawFace_end (); -public: - CDrawUtilities() +class ECORE_API CDrawUtilities: + +public +CDUInterface +, +public +pureRender +{ + SPrimitiveBuffer m_SolidCone; + SPrimitiveBuffer m_WireCone; + SPrimitiveBuffer m_SolidSphere; + SPrimitiveBuffer m_WireSphere; + SPrimitiveBuffer m_SolidSpherePart; + SPrimitiveBuffer m_WireSpherePart; + SPrimitiveBuffer m_SolidCylinder; + SPrimitiveBuffer m_WireCylinder; + SPrimitiveBuffer m_SolidBox; + SPrimitiveBuffer m_WireBox; + CGameFont* m_Font; + CEditableObject* m_axis_object; + public: + ref_geom vs_L; + ref_geom vs_TL; + ref_geom vs_LIT; + protected: + FVF::L* m_DD_pv; + FVF::L* m_DD_pv_start; + u32 m_DD_base; + BOOL m_DD_wire; + void DD_DrawFace_flush (BOOL try_again); + public: + void DD_DrawFace_begin (BOOL bWire); + void DD_DrawFace_push (const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr); + void DD_DrawFace_end (); + public: + CDrawUtilities() { - vs_L = 0; - vs_TL = 0; - vs_LIT = 0; - m_DD_pv = 0; - m_DD_pv_start = 0; - m_DD_base = 0; - m_Font = 0; - } - - void OnDeviceCreate (); - void OnDeviceDestroy(); - - void UpdateGrid(int number_of_cell, float square_size, int subdiv=10); - - //---------------------------------------------------- - virtual void __stdcall DrawCross(const Fvector& p, float szx1, float szy1, float szz1, float szx2, float szy2, float szz2, u32 clr, BOOL bRot45=false); - virtual void __stdcall DrawCross(const Fvector& p, float sz, u32 clr, BOOL bRot45=false){ DrawCross(p, sz,sz,sz, sz,sz,sz, clr, bRot45); } - virtual void __stdcall DrawEntity(u32 clr, ref_shader s); - virtual void __stdcall DrawFlag(const Fvector& p, float heading, float height, float sz, float sz_fl, u32 clr, BOOL bDrawEntity); - virtual void __stdcall DrawRomboid(const Fvector& p, float radius, u32 clr); - virtual void __stdcall DrawJoint(const Fvector& p, float radius, u32 clr); - - virtual void __stdcall DrawSpotLight(const Fvector& p, const Fvector& d, float range, float phi, u32 clr); - virtual void __stdcall DrawDirectionalLight(const Fvector& p, const Fvector& d, float radius, float range, u32 clr); - virtual void __stdcall DrawPointLight(const Fvector& p, float radius, u32 clr); - - virtual void __stdcall DrawSound(const Fvector& p, float radius, u32 clr); - virtual void __stdcall DrawLineSphere(const Fvector& p, float radius, u32 clr, BOOL bCross); - - virtual void __stdcall dbgDrawPlacement(const Fvector& p, int sz, u32 clr, LPCSTR caption=0, u32 clr_font=0xffffffff); - virtual void __stdcall dbgDrawVert(const Fvector& p0, u32 clr, LPCSTR caption=0); - virtual void __stdcall dbgDrawEdge(const Fvector& p0, const Fvector& p1, u32 clr, LPCSTR caption=0); - virtual void __stdcall dbgDrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr, LPCSTR caption=0); - - virtual void __stdcall DrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawLine(const Fvector& p0, const Fvector& p1, u32 clr); - virtual void __stdcall DrawLink(const Fvector& p0, const Fvector& p1, float sz, u32 clr); - IC virtual void __stdcall DrawFaceNormal(const Fvector& p0, const Fvector& p1, const Fvector& p2, float size, u32 clr){ - Fvector N,C,P; N.mknormal(p0,p1,p2); C.set(p0);C.add(p1);C.add(p2);C.div(3); - P.mad(C,N,size); - DrawLine(C,P,clr);} - IC virtual void __stdcall DrawFaceNormal(const Fvector* p, float size, u32 clr){DrawFaceNormal(p[0],p[1],p[2],size,clr);} - IC virtual void __stdcall DrawFaceNormal(const Fvector& C, const Fvector& N, float size, u32 clr){ - Fvector P; P.mad(C,N,size);DrawLine(C,P,clr);} - virtual void __stdcall DrawSelectionBox(const Fvector& center, const Fvector& size, u32* c=0); - virtual void __stdcall DrawSelectionBoxB(const Fbox& box, u32* c=0); - - virtual void __stdcall DrawIdentSphere (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawIdentSpherePart(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawIdentCone (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawIdentCylinder (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawIdentBox (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - - virtual void __stdcall DrawBox (const Fvector& offs, const Fvector& Size, BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawAABB (const Fvector& p0, const Fvector& p1, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawAABB (const Fmatrix& parent, const Fvector& center, const Fvector& size, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawOBB (const Fmatrix& parent, const Fobb& box, u32 clr_s, u32 clr_w); - virtual void __stdcall DrawSphere (const Fmatrix& parent, const Fvector& center, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawSphere (const Fmatrix& parent, const Fsphere& S, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire){DrawSphere(parent,S.P,S.R,clr_s,clr_w,bSolid,bWire);} - virtual void __stdcall DrawCylinder(const Fmatrix& parent, const Fvector& center, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawCone (const Fmatrix& parent, const Fvector& apex, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawPlane (const Fvector& center, const Fvector2& scale, const Fvector& rotate, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawPlane (const Fvector& p, const Fvector& n, const Fvector2& scale, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire); - virtual void __stdcall DrawRectangle(const Fvector& o, const Fvector& u, const Fvector& v, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); - - virtual void __stdcall DrawGrid (); - virtual void __stdcall DrawPivot (const Fvector& pos, float sz=5.f); - virtual void __stdcall DrawAxis (const Fmatrix& T); - virtual void __stdcall DrawObjectAxis(const Fmatrix& T, float sz, BOOL sel); - virtual void __stdcall DrawSelectionRect(const Ivector2& m_SelStart, const Ivector2& m_SelEnd); - virtual void __stdcall DrawIndexedPrimitive (int pt, u32 pc, const Fvector& pos, const Fvector* vb, const u32& vb_size, const u32* ib, const u32& ib_size, const u32& clr_argb, float scale=1.0f); - - virtual void __stdcall DrawPrimitiveL(D3DPRIMITIVETYPE pt, u32 pc, Fvector* vertices, int vc, u32 color, BOOL bCull, BOOL bCycle); - virtual void __stdcall DrawPrimitiveTL(D3DPRIMITIVETYPE pt, u32 pc, FVF::TL* vertices, int vc, BOOL bCull, BOOL bCycle); - virtual void __stdcall DrawPrimitiveLIT(D3DPRIMITIVETYPE pt, u32 pc, FVF::LIT* vertices, int vc, BOOL bCull, BOOL bCycle); - - virtual void __stdcall OutText (const Fvector& pos, LPCSTR text, u32 color=0xFF000000, u32 shadow_color=0xFF909090); - - virtual void OnRender (); + vs_L = 0; + vs_TL = 0; + vs_LIT = 0; + m_DD_pv = 0; + m_DD_pv_start = 0; + m_DD_base = 0; + m_Font = 0; +} + +void OnDeviceCreate (); +void OnDeviceDestroy(); + +void UpdateGrid(int number_of_cell, float square_size, int subdiv=10); + +//---------------------------------------------------- +virtual void __stdcall DrawCross(const Fvector& p, float szx1, float szy1, float szz1, float szx2, float szy2, float szz2, u32 clr, BOOL bRot45=false); +virtual void __stdcall DrawCross(const Fvector& p, float sz, u32 clr, BOOL bRot45=false){ DrawCross(p, sz,sz,sz, sz,sz,sz, clr, bRot45); } +virtual void __stdcall DrawEntity(u32 clr, ref_shader s); +virtual void __stdcall DrawFlag(const Fvector& p, float heading, float height, float sz, float sz_fl, u32 clr, BOOL bDrawEntity); +virtual void __stdcall DrawRomboid(const Fvector& p, float radius, u32 clr); +virtual void __stdcall DrawJoint(const Fvector& p, float radius, u32 clr); + +virtual void __stdcall DrawSpotLight(const Fvector& p, const Fvector& d, float range, float phi, u32 clr); +virtual void __stdcall DrawDirectionalLight(const Fvector& p, const Fvector& d, float radius, float range, u32 clr); +virtual void __stdcall DrawPointLight(const Fvector& p, float radius, u32 clr); + +virtual void __stdcall DrawSound(const Fvector& p, float radius, u32 clr); +virtual void __stdcall DrawLineSphere(const Fvector& p, float radius, u32 clr, BOOL bCross); + +virtual void __stdcall dbgDrawPlacement(const Fvector& p, int sz, u32 clr, LPCSTR caption=0, u32 clr_font=0xffffffff); +virtual void __stdcall dbgDrawVert(const Fvector& p0, u32 clr, LPCSTR caption=0); +virtual void __stdcall dbgDrawEdge(const Fvector& p0, const Fvector& p1, u32 clr, LPCSTR caption=0); +virtual void __stdcall dbgDrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr, LPCSTR caption=0); + +virtual void __stdcall DrawFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawLine(const Fvector& p0, const Fvector& p1, u32 clr); +virtual void __stdcall DrawLink(const Fvector& p0, const Fvector& p1, float sz, u32 clr); +IC virtual void __stdcall DrawFaceNormal(const Fvector& p0, const Fvector& p1, const Fvector& p2, float size, u32 clr){ + Fvector N,C,P; N.mknormal(p0,p1,p2); C.set(p0);C.add(p1);C.add(p2);C.div(3); + P.mad(C,N,size); + DrawLine(C,P,clr);} +IC virtual void __stdcall DrawFaceNormal(const Fvector* p, float size, u32 clr){DrawFaceNormal(p[0],p[1],p[2],size,clr);} +IC virtual void __stdcall DrawFaceNormal(const Fvector& C, const Fvector& N, float size, u32 clr){ + Fvector P; P.mad(C,N,size);DrawLine(C,P,clr);} +virtual void __stdcall DrawSelectionBox(const Fvector& center, const Fvector& size, u32* c=0); +virtual void __stdcall DrawSelectionBoxB(const Fbox& box, u32* c=0); + +virtual void __stdcall DrawIdentSphere (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawIdentSpherePart(BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawIdentCone (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawIdentCylinder (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawIdentBox (BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); + +virtual void __stdcall DrawBox (const Fvector& offs, const Fvector& Size, BOOL bSolid, BOOL bWire, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawAABB (const Fvector& p0, const Fvector& p1, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawAABB (const Fmatrix& parent, const Fvector& center, const Fvector& size, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawOBB (const Fmatrix& parent, const Fobb& box, u32 clr_s, u32 clr_w); +virtual void __stdcall DrawSphere (const Fmatrix& parent, const Fvector& center, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawSphere (const Fmatrix& parent, const Fsphere& S, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire){DrawSphere(parent,S.P,S.R,clr_s,clr_w,bSolid,bWire);} +virtual void __stdcall DrawCylinder(const Fmatrix& parent, const Fvector& center, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawCone (const Fmatrix& parent, const Fvector& apex, const Fvector& dir, float height, float radius, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawPlane (const Fvector& center, const Fvector2& scale, const Fvector& rotate, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawPlane (const Fvector& p, const Fvector& n, const Fvector2& scale, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire); +virtual void __stdcall DrawRectangle(const Fvector& o, const Fvector& u, const Fvector& v, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire); + +virtual void __stdcall DrawGrid (); +virtual void __stdcall DrawPivot (const Fvector& pos, float sz=5.f); +virtual void __stdcall DrawAxis (const Fmatrix& T); +virtual void __stdcall DrawObjectAxis(const Fmatrix& T, float sz, BOOL sel); +virtual void __stdcall DrawSelectionRect(const Ivector2& m_SelStart, const Ivector2& m_SelEnd); +virtual void __stdcall DrawIndexedPrimitive (int pt, u32 pc, const Fvector& pos, const Fvector* vb, const u32& vb_size, const u32* ib, const u32& ib_size, const u32& clr_argb, float scale=1.0f); + +virtual void __stdcall DrawPrimitiveL(D3DPRIMITIVETYPE pt, u32 pc, Fvector* vertices, int vc, u32 color, BOOL bCull, BOOL bCycle); +virtual void __stdcall DrawPrimitiveTL(D3DPRIMITIVETYPE pt, u32 pc, FVF::TL* vertices, int vc, BOOL bCull, BOOL bCycle); +virtual void __stdcall DrawPrimitiveLIT(D3DPRIMITIVETYPE pt, u32 pc, FVF::LIT* vertices, int vc, BOOL bCull, BOOL bCycle); + +virtual void __stdcall OutText (const Fvector& pos, LPCSTR text, u32 color=0xFF000000, u32 shadow_color=0xFF909090); + +virtual void OnRender (); }; extern ECORE_API CDrawUtilities DU_impl; //---------------------------------------------------- diff --git a/src/editors/ECore/Editor/D3DX_Wrapper.h b/src/editors/ECore/Editor/D3DX_Wrapper.h index b06701f0271..f65d19c7583 100644 --- a/src/editors/ECore/Editor/D3DX_Wrapper.h +++ b/src/editors/ECore/Editor/D3DX_Wrapper.h @@ -2,206 +2,211 @@ #define D3DX_WraperH #pragma once +#include "xrCore/Platform.h" + #ifdef ETOOLS_EXPORTS -#define ETOOLS_API __declspec( dllexport ) +#define ETOOLS_API XR_EXPORT #else -#define ETOOLS_API __declspec( dllimport ) +#define ETOOLS_API XR_IMPORT #endif -extern "C" { - ETOOLS_API UINT WINAPI - D3DX_GetDriverLevel( - LPDIRECT3DDEVICE9 pDevice); - - ETOOLS_API HRESULT WINAPI - D3DX_GetImageInfoFromFileInMemory( - LPCVOID pSrcData, - UINT SrcDataSize, - D3DXIMAGE_INFO* pSrcInfo); - - ETOOLS_API HRESULT WINAPI - D3DX_CreateCubeTextureFromFileInMemoryEx( - LPDIRECT3DDEVICE9 pDevice, - LPCVOID pSrcData, - UINT SrcDataSize, - UINT Size, - UINT MipLevels, - DWORD Usage, - D3DFORMAT Format, - D3DPOOL Pool, - DWORD Filter, - DWORD MipFilter, - D3DCOLOR ColorKey, - D3DXIMAGE_INFO* pSrcInfo, - PALETTEENTRY* pPalette, - LPDIRECT3DCUBETEXTURE9* ppCubeTexture); - - ETOOLS_API HRESULT WINAPI - D3DX_CreateTextureFromFileInMemoryEx( - LPDIRECT3DDEVICE9 pDevice, - LPCVOID pSrcData, - UINT SrcDataSize, - UINT Width, - UINT Height, - UINT MipLevels, - DWORD Usage, - D3DFORMAT Format, - D3DPOOL Pool, - DWORD Filter, - DWORD MipFilter, - D3DCOLOR ColorKey, - D3DXIMAGE_INFO* pSrcInfo, - PALETTEENTRY* pPalette, - LPDIRECT3DTEXTURE9* ppTexture); - - ETOOLS_API HRESULT WINAPI - D3DX_CreateTexture( - LPDIRECT3DDEVICE9 pDevice, - UINT Width, - UINT Height, - UINT MipLevels, - DWORD Usage, - D3DFORMAT Format, - D3DPOOL Pool, - LPDIRECT3DTEXTURE9* ppTexture); - - ETOOLS_API HRESULT WINAPI - D3DX_ComputeNormalMap( - LPDIRECT3DTEXTURE9 pTexture, - LPDIRECT3DTEXTURE9 pSrcTexture, - const PALETTEENTRY *pSrcPalette, - DWORD Flags, - DWORD Channel, - FLOAT Amplitude); - - ETOOLS_API HRESULT WINAPI - D3DX_LoadSurfaceFromSurface( - LPDIRECT3DSURFACE9 pDestSurface, - CONST PALETTEENTRY* pDestPalette, - CONST RECT* pDestRect, - LPDIRECT3DSURFACE9 pSrcSurface, - CONST PALETTEENTRY* pSrcPalette, - CONST RECT* pSrcRect, - DWORD Filter, - D3DCOLOR ColorKey); - - ETOOLS_API HRESULT WINAPI - D3DX_CompileShader( - LPCSTR pSrcData, - UINT SrcDataLen, - CONST D3DXMACRO* pDefines, - LPD3DXINCLUDE pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - LPD3DXBUFFER* ppShader, - LPD3DXBUFFER* ppErrorMsgs, - LPD3DXCONSTANTTABLE* ppConstantTable); - - ETOOLS_API HRESULT WINAPI - D3DX_CompileShaderFromFile( - LPCSTR pSrcFile, - CONST D3DXMACRO* pDefines, - LPD3DXINCLUDE pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - LPD3DXBUFFER* ppShader, - LPD3DXBUFFER* ppErrorMsgs, - LPD3DXCONSTANTTABLE* ppConstantTable); - - ETOOLS_API HRESULT WINAPI - D3DX_FindShaderComment( - CONST DWORD* pFunction, - DWORD FourCC, - LPCVOID* ppData, - UINT* pSizeInBytes); - - ETOOLS_API HRESULT WINAPI - D3DX_DeclaratorFromFVF( - DWORD FVF, - D3DVERTEXELEMENT9 pDeclarator[MAX_FVF_DECL_SIZE]); - - ETOOLS_API UINT WINAPI - D3DX_GetDeclVertexSize( - CONST D3DVERTEXELEMENT9*pDecl, - DWORD Stream); - - ETOOLS_API UINT WINAPI - D3DX_GetDeclLength( - CONST D3DVERTEXELEMENT9*pDecl); - - ETOOLS_API UINT WINAPI - D3DX_GetFVFVertexSize( - DWORD FVF); - - ETOOLS_API const char* WINAPI - DX_GetErrorDescription9( - HRESULT hr); - - ETOOLS_API D3DXMATRIX* WINAPI - D3DX_MatrixInverse( - D3DXMATRIX *pOut, - FLOAT *pDeterminant, - CONST D3DXMATRIX *pM); - - ETOOLS_API D3DXMATRIX* WINAPI - D3DX_MatrixTranspose( - D3DXMATRIX *pOut, - CONST D3DXMATRIX *pM); - - ETOOLS_API D3DXPLANE* WINAPI - D3DX_PlaneNormalize( - D3DXPLANE *pOut, - CONST D3DXPLANE *pP); - - ETOOLS_API D3DXPLANE* WINAPI - D3DX_PlaneTransform( - D3DXPLANE *pOut, - CONST D3DXPLANE *pP, - CONST D3DXMATRIX *pM); - - ETOOLS_API HRESULT WINAPI - D3DX_OptimizeFaces( - LPCVOID pIndices, - UINT NumFaces, - UINT NumVertices, - BOOL Indices32Bit, - DWORD * pFaceRemap); - - ETOOLS_API HRESULT WINAPI - D3DX_OptimizeVertices( - LPCVOID pIndices, - UINT NumFaces, - UINT NumVertices, - BOOL Indices32Bit, - DWORD * pVertexRemap); +extern "C" +{ + ETOOLS_API UINT WINAPI + D3DX_GetDriverLevel( + LPDIRECT3DDEVICE9 pDevice); + + ETOOLS_API HRESULT WINAPI + D3DX_GetImageInfoFromFileInMemory( + LPCVOID pSrcData, + UINT SrcDataSize, + D3DXIMAGE_INFO *pSrcInfo); + + ETOOLS_API HRESULT WINAPI + D3DX_CreateCubeTextureFromFileInMemoryEx( + LPDIRECT3DDEVICE9 pDevice, + LPCVOID pSrcData, + UINT SrcDataSize, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO *pSrcInfo, + PALETTEENTRY *pPalette, + LPDIRECT3DCUBETEXTURE9 *ppCubeTexture); + + ETOOLS_API HRESULT WINAPI + D3DX_CreateTextureFromFileInMemoryEx( + LPDIRECT3DDEVICE9 pDevice, + LPCVOID pSrcData, + UINT SrcDataSize, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO *pSrcInfo, + PALETTEENTRY *pPalette, + LPDIRECT3DTEXTURE9 *ppTexture); + + ETOOLS_API HRESULT WINAPI + D3DX_CreateTexture( + LPDIRECT3DDEVICE9 pDevice, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + LPDIRECT3DTEXTURE9 *ppTexture); + + ETOOLS_API HRESULT WINAPI + D3DX_ComputeNormalMap( + LPDIRECT3DTEXTURE9 pTexture, + LPDIRECT3DTEXTURE9 pSrcTexture, + const PALETTEENTRY *pSrcPalette, + DWORD Flags, + DWORD Channel, + FLOAT Amplitude); + + ETOOLS_API HRESULT WINAPI + D3DX_LoadSurfaceFromSurface( + LPDIRECT3DSURFACE9 pDestSurface, + CONST PALETTEENTRY* pDestPalette, + CONST RECT* pDestRect, + LPDIRECT3DSURFACE9 pSrcSurface, + CONST PALETTEENTRY* pSrcPalette, + CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey); + + ETOOLS_API HRESULT WINAPI + D3DX_CompileShader( + LPCSTR pSrcData, + UINT SrcDataLen, + CONST D3DXMACRO* pDefines, + LPD3DXINCLUDE pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + LPD3DXBUFFER *ppShader, + LPD3DXBUFFER *ppErrorMsgs, + LPD3DXCONSTANTTABLE *ppConstantTable); + + ETOOLS_API HRESULT WINAPI + D3DX_CompileShaderFromFile( + LPCSTR pSrcFile, + CONST D3DXMACRO* pDefines, + LPD3DXINCLUDE pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + LPD3DXBUFFER *ppShader, + LPD3DXBUFFER *ppErrorMsgs, + LPD3DXCONSTANTTABLE *ppConstantTable); + + ETOOLS_API HRESULT WINAPI + D3DX_FindShaderComment( + CONST DWORD* pFunction, + DWORD FourCC, + LPCVOID *ppData, + UINT *pSizeInBytes); + + ETOOLS_API HRESULT WINAPI + D3DX_DeclaratorFromFVF( + DWORD FVF, + D3DVERTEXELEMENT9 pDeclarator[MAX_FVF_DECL_SIZE]); + + ETOOLS_API UINT WINAPI + D3DX_GetDeclVertexSize( + CONST D3DVERTEXELEMENT9*pDecl, + DWORD Stream); + + ETOOLS_API UINT WINAPI + D3DX_GetDeclLength( + CONST D3DVERTEXELEMENT9*pDecl); + + ETOOLS_API UINT WINAPI + D3DX_GetFVFVertexSize( + DWORD FVF); + + ETOOLS_API const + char *WINAPI + DX_GetErrorDescription9( + HRESULT hr); + + ETOOLS_API D3DXMATRIX* WINAPI + D3DX_MatrixInverse( + D3DXMATRIX *pOut, + FLOAT *pDeterminant, + CONST D3DXMATRIX*pM); + + ETOOLS_API D3DXMATRIX* WINAPI + D3DX_MatrixTranspose( + D3DXMATRIX *pOut, + CONST D3DXMATRIX*pM); + + ETOOLS_API D3DXPLANE* WINAPI + D3DX_PlaneNormalize( + D3DXPLANE *pOut, + CONST D3DXPLANE*pP); + + ETOOLS_API D3DXPLANE* WINAPI + D3DX_PlaneTransform( + D3DXPLANE *pOut, + CONST D3DXPLANE*pP, + CONST D3DXMATRIX*pM); + + ETOOLS_API HRESULT WINAPI + D3DX_OptimizeFaces( + LPCVOID pIndices, + UINT NumFaces, + UINT NumVertices, + BOOL Indices32Bit, + DWORD *pFaceRemap); + + ETOOLS_API HRESULT WINAPI + D3DX_OptimizeVertices( + LPCVOID pIndices, + UINT NumFaces, + UINT NumVertices, + BOOL Indices32Bit, + DWORD *pVertexRemap); } #ifndef ETOOLS_EXPORTS - #undef D3DXCompileShaderFromFile - #undef DXGetErrorDescription9 - #define D3DXGetDriverLevel D3DX_GetDriverLevel - #define D3DXGetImageInfoFromFileInMemory D3DX_GetImageInfoFromFileInMemory - #define D3DXCreateCubeTextureFromFileInMemoryEx D3DX_CreateCubeTextureFromFileInMemoryEx - #define D3DXCreateTextureFromFileInMemoryEx D3DX_CreateTextureFromFileInMemoryEx - #define D3DXCreateTexture D3DX_CreateTexture - #define D3DXComputeNormalMap D3DX_ComputeNormalMap - #define D3DXLoadSurfaceFromSurface D3DX_LoadSurfaceFromSurface - #define D3DXCompileShaderFromFile D3DX_CompileShaderFromFile - #define D3DXCompileShader D3DX_CompileShader - #define D3DXFindShaderComment D3DX_FindShaderComment - #define D3DXDeclaratorFromFVF D3DX_DeclaratorFromFVF - #define D3DXGetDeclVertexSize D3DX_GetDeclVertexSize - #define D3DXGetDeclLength D3DX_GetDeclLength - #define D3DXGetFVFVertexSize D3DX_GetFVFVertexSize - #define DXGetErrorDescription9 DX_GetErrorDescription9 - #define D3DXMatrixInverse D3DX_MatrixInverse - #define D3DXMatrixTranspose D3DX_MatrixTranspose - #define D3DXPlaneNormalize D3DX_PlaneNormalize - #define D3DXPlaneTransform D3DX_PlaneTransform - #define D3DXOptimizeFaces D3DX_OptimizeFaces - #define D3DXOptimizeVertices D3DX_OptimizeVertices +#undef D3DXCompileShaderFromFile +#undef DXGetErrorDescription9 +#define D3DXGetDriverLevel D3DX_GetDriverLevel +#define D3DXGetImageInfoFromFileInMemory D3DX_GetImageInfoFromFileInMemory +#define D3DXCreateCubeTextureFromFileInMemoryEx D3DX_CreateCubeTextureFromFileInMemoryEx +#define D3DXCreateTextureFromFileInMemoryEx D3DX_CreateTextureFromFileInMemoryEx +#define D3DXCreateTexture D3DX_CreateTexture +#define D3DXComputeNormalMap D3DX_ComputeNormalMap +#define D3DXLoadSurfaceFromSurface D3DX_LoadSurfaceFromSurface +#define D3DXCompileShaderFromFile D3DX_CompileShaderFromFile +#define D3DXCompileShader D3DX_CompileShader +#define D3DXFindShaderComment D3DX_FindShaderComment +#define D3DXDeclaratorFromFVF D3DX_DeclaratorFromFVF +#define D3DXGetDeclVertexSize D3DX_GetDeclVertexSize +#define D3DXGetDeclLength D3DX_GetDeclLength +#define D3DXGetFVFVertexSize D3DX_GetFVFVertexSize +#define DXGetErrorDescription9 DX_GetErrorDescription9 +#define D3DXMatrixInverse D3DX_MatrixInverse +#define D3DXMatrixTranspose D3DX_MatrixTranspose +#define D3DXPlaneNormalize D3DX_PlaneNormalize +#define D3DXPlaneTransform D3DX_PlaneTransform +#define D3DXOptimizeFaces D3DX_OptimizeFaces +#define D3DXOptimizeVertices D3DX_OptimizeVertices #endif #endif + diff --git a/src/editors/ECore/Editor/DeviceScreenshot.cpp b/src/editors/ECore/Editor/DeviceScreenshot.cpp index 7b9e82ca073..cb02cced574 100644 --- a/src/editors/ECore/Editor/DeviceScreenshot.cpp +++ b/src/editors/ECore/Editor/DeviceScreenshot.cpp @@ -2,59 +2,61 @@ #include "stdafx.h" #pragma hdrstop -#include "ui_toolscustom.h" +#include "UI_ToolsCustom.h" #include "ui_main.h" -#include "ResourceManager.h" +#include "Layers/xrRender/ResourceManager.h" -bool CEditorRenderDevice::MakeScreenshot(U32Vec& pixels, u32 width, u32 height) +bool CEditorRenderDevice::MakeScreenshot(U32Vec &pixels, u32 width, u32 height) { - if (!b_is_Ready) return false; + if (!b_is_Ready) + return false; // free managed resource Resources->Evict(); - IDirect3DSurface9* poldZB=0; - IDirect3DSurface9* pZB=0; - IDirect3DSurface9* pRT=0; - IDirect3DSurface9* poldRT=0; - D3DVIEWPORT9 oldViewport; - SetRS(D3DRS_COLORWRITEENABLE,D3DCOLORWRITEENABLE_ALPHA|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_RED); - CHK_DX(HW.pDevice->GetRenderTarget(0,&poldRT)); + IDirect3DSurface9 *poldZB = 0; + IDirect3DSurface9 *pZB = 0; + IDirect3DSurface9 *pRT = 0; + IDirect3DSurface9 *poldRT = 0; + D3DVIEWPORT9 oldViewport; + SetRS(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_RED); + CHK_DX(HW.pDevice->GetRenderTarget(0, &poldRT)); CHK_DX(HW.pDevice->GetDepthStencilSurface(&poldZB)); CHK_DX(HW.pDevice->GetViewport(&oldViewport)); - CHK_DX(HW.pDevice->CreateRenderTarget(width,height,D3DFMT_A8R8G8B8,D3DMULTISAMPLE_NONE,0,FALSE,&pRT,0)); - CHK_DX(HW.pDevice->CreateDepthStencilSurface(width,height,HW.Caps.bStencil?D3DFMT_D24S8:D3DFMT_D24X8,D3DMULTISAMPLE_NONE,0,FALSE,&pZB,0)); - CHK_DX(HW.pDevice->SetRenderTarget(0,pRT)); - CHK_DX(HW.pDevice->SetDepthStencilSurface(pZB)); + CHK_DX(HW.pDevice->CreateRenderTarget(width, height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &pRT, 0)); + CHK_DX(HW.pDevice->CreateDepthStencilSurface(width, height, HW.Caps.bStencil ? D3DFMT_D24S8 : D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, FALSE, &pZB, 0)); + CHK_DX(HW.pDevice->SetRenderTarget(0, pRT)); + CHK_DX(HW.pDevice->SetDepthStencilSurface(pZB)); - UI->PrepareRedraw (); - EDevice.Begin (); - Tools->Render (); - EDevice.End (); + UI->PrepareRedraw(); + EDevice.Begin(); + Tools->Render(); + EDevice.End(); - // Create temp-surface - IDirect3DSurface9* pFB; - R_CHK(HW.pDevice->CreateOffscreenPlainSurface( - width,height,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM,&pFB,NULL)); - R_CHK(HW.pDevice->GetRenderTargetData(pRT, pFB)); + // Create temp-surface + IDirect3DSurface9 *pFB; + R_CHK(HW.pDevice->CreateOffscreenPlainSurface( + width, height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pFB, NULL)); + R_CHK(HW.pDevice->GetRenderTargetData(pRT, pFB)); - D3DLOCKED_RECT D; - R_CHK(pFB->LockRect(&D,0,D3DLOCK_NOSYSLOCK)); - pixels.resize(width*height); - // Image processing - u32* pPixel = (u32*)D.pBits; + D3DLOCKED_RECT D; + R_CHK(pFB->LockRect(&D, 0, D3DLOCK_NOSYSLOCK)); + pixels.resize(width*height); + // Image processing + u32 *pPixel = (u32*)D.pBits; - U32It it = pixels.begin(); - for (int h=height-1; h>=0; h--,it+=width){ - LPDWORD dt = LPDWORD(u32(pPixel)+u32(D.Pitch*h)); - CopyMemory (it,dt,sizeof(u32)*width); + U32It it = pixels.begin(); + for (int h = height-1; h>=0; h--,it += width) + { + LPDWORD dt = LPDWORD(u32(pPixel)+u32(D.Pitch*h)); + CopyMemory(it, dt, sizeof(u32)*width); } R_CHK(pFB->UnlockRect()); - CHK_DX(HW.pDevice->SetDepthStencilSurface(poldZB)); - CHK_DX(HW.pDevice->SetRenderTarget(0,poldRT)); + CHK_DX(HW.pDevice->SetDepthStencilSurface(poldZB)); + CHK_DX(HW.pDevice->SetRenderTarget(0, poldRT)); CHK_DX(HW.pDevice->SetViewport(&oldViewport)); _RELEASE(pZB); @@ -66,4 +68,3 @@ bool CEditorRenderDevice::MakeScreenshot(U32Vec& pixels, u32 width, u32 height) return true; } - diff --git a/src/editors/ECore/Editor/DrawUtils.h b/src/editors/ECore/Editor/DrawUtils.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/DrawUtils.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/EDetailModel.cpp b/src/editors/ECore/Editor/EDetailModel.cpp index 404f928ad8a..d0dad6ce4f4 100644 --- a/src/editors/ECore/Editor/EDetailModel.cpp +++ b/src/editors/ECore/Editor/EDetailModel.cpp @@ -15,256 +15,281 @@ #define DETOBJ_CHUNK_FLAGS 0x0104 #define DETOBJ_VERSION 0x0001 + //------------------------------------------------------------------------------ -void EDetail::EVertexIn::remapUV(const fvfVertexIn& src, const Fvector2& offs, const Fvector2& scale, bool bRotate) +void EDetail::EVertexIn::remapUV(const fvfVertexIn &src, const Fvector2 &offs, const Fvector2 &scale, bool bRotate) { - P.set (src.P); - ImageLib.MergedTextureRemapUV(u,v,src.u,src.v, offs, scale, bRotate); + P.set(src.P); + ImageLib.MergedTextureRemapUV(u, v, src.u, src.v, offs, scale, bRotate); } EDetail::EDetail() { - shader = 0; - m_Flags.zero (); - m_pRefs = 0; - m_fMinScale = 0.5f; - m_fMaxScale = 2.f; - m_fDensityFactor = 1.f; - m_sRefs = ""; - vertices = 0; - number_vertices = 0; - indices = 0; - number_indices = 0; + shader = 0; + m_Flags.zero(); + m_pRefs = 0; + m_fMinScale = 0.5f; + m_fMaxScale = 2.f; + m_fDensityFactor = 1.f; + m_sRefs = ""; + vertices = 0; + number_vertices = 0; + indices = 0; + number_indices = 0; } EDetail::~EDetail() { - Unload(); + Unload(); } void EDetail::Unload() { - CDetail::Unload (); + CDetail::Unload(); Lib.RemoveEditObject(m_pRefs); - OnDeviceDestroy (); + OnDeviceDestroy(); } -LPCSTR EDetail::GetName () +LPCSTR EDetail::GetName() { - return m_pRefs?m_pRefs->GetName():m_sRefs.c_str(); + return m_pRefs ? m_pRefs->GetName() : m_sRefs.c_str(); } LPCSTR EDetail::GetTextureName() { - VERIFY(m_pRefs); - CSurface* surf = *m_pRefs->FirstSurface(); VERIFY(surf); + VERIFY(m_pRefs); + CSurface*surf = *m_pRefs->FirstSurface(); + VERIFY(surf); return surf->_Texture(); } -void EDetail::DefferedLoad() -{ -} +void EDetail::DefferedLoad() {} void EDetail::OnDeviceCreate() { - if (!m_pRefs) return; - CSurface* surf = *m_pRefs->FirstSurface(); - VERIFY (surf); - AnsiString s_name = surf->_ShaderName(); - AnsiString t_name = surf->_Texture(); - shader.create (s_name.c_str(),t_name.c_str()); + if (!m_pRefs) + return; + CSurface*surf = *m_pRefs->FirstSurface(); + VERIFY(surf); + AnsiString s_name = surf->_ShaderName(); + AnsiString t_name = surf->_Texture(); + shader.create(s_name.c_str(), t_name.c_str()); } void EDetail::OnDeviceDestroy() { - shader.destroy(); + shader.destroy(); } -u16 EDetail::_AddVert(const Fvector& p, float u, float v) +u16 EDetail::_AddVert(const Fvector &p, float u, float v) { - EVertexIn V(p,u,v); - for (u16 k=0; k<(u16)number_vertices; k++) - if (V.similar((EVertexIn&)vertices[k])) return k; + EVertexIn V(p, u, v); + for (u16 k = 0; k<(u16)number_vertices; k++) + if (V.similar((EVertexIn&)vertices[k])) + return k; number_vertices++; - vertices = (fvfVertexIn*)xr_realloc(vertices,number_vertices*sizeof(fvfVertexIn)); + vertices = (fvfVertexIn*)xr_realloc(vertices, number_vertices*sizeof(fvfVertexIn)); vertices[number_vertices-1] = V; return u16(number_vertices-1); } IC BOOL isDegenerated(u16 v[3]) { - return (v[0]==v[1] || v[0]==v[2] || v[1]==v[2]); + return (v[0]==v[1]||v[0]==v[2]||v[1]==v[2]); }; -IC BOOL isEqual(U16Vec& ind, u16 v[3]) + +IC BOOL isEqual(U16Vec &ind, u16 v[3]) { - for (U16It it=ind.begin(); it!=ind.end(); it+=3){ + for (U16It it = ind.begin(); it!=ind.end(); it += 3) + { // Test for 6 variations - if ((*(it+0)==v[0]) && (*(it+1)==v[1]) && (*(it+2)==v[2])) return true; - if ((*(it+0)==v[0]) && (*(it+2)==v[1]) && (*(it+1)==v[2])) return true; - if ((*(it+2)==v[0]) && (*(it+0)==v[1]) && (*(it+1)==v[2])) return true; - if ((*(it+2)==v[0]) && (*(it+1)==v[1]) && (*(it+0)==v[2])) return true; - if ((*(it+1)==v[0]) && (*(it+0)==v[1]) && (*(it+2)==v[2])) return true; - if ((*(it+1)==v[0]) && (*(it+2)==v[1]) && (*(it+0)==v[2])) return true; + if ((*(it+0)==v[0])&&(*(it+1)==v[1])&&(*(it+2)==v[2])) + return true; + if ((*(it+0)==v[0])&&(*(it+2)==v[1])&&(*(it+1)==v[2])) + return true; + if ((*(it+2)==v[0])&&(*(it+0)==v[1])&&(*(it+1)==v[2])) + return true; + if ((*(it+2)==v[0])&&(*(it+1)==v[1])&&(*(it+0)==v[2])) + return true; + if ((*(it+1)==v[0])&&(*(it+0)==v[1])&&(*(it+2)==v[2])) + return true; + if ((*(it+1)==v[0])&&(*(it+2)==v[1])&&(*(it+0)==v[2])) + return true; } return false; } -bool EDetail::Update (LPCSTR name) +bool EDetail::Update(LPCSTR name) { - m_sRefs = name; + m_sRefs = name; // update link - CEditableObject* R = Lib.CreateEditObject(name); - if (!R){ - ELog.Msg (mtError,"Can't load detail object '%s'.", name); + CEditableObject*R = Lib.CreateEditObject(name); + if (!R) + { + ELog.Msg(mtError, "Can't load detail object '%s'.", name); return false; } - if(R->SurfaceCount()!=1){ - ELog.Msg (mtError,"Object must contain 1 material."); - Lib.RemoveEditObject(R); - return false; + if (R->SurfaceCount()!=1) + { + ELog.Msg(mtError, "Object must contain 1 material."); + Lib.RemoveEditObject(R); + return false; } - if(R->MeshCount()==0){ - ELog.Msg (mtError,"Object must contain 1 mesh."); - Lib.RemoveEditObject(R); - return false; + if (R->MeshCount()==0) + { + ELog.Msg(mtError, "Object must contain 1 mesh."); + Lib.RemoveEditObject(R); + return false; } Lib.RemoveEditObject(m_pRefs); - m_pRefs = R; + m_pRefs = R; // fill geometry - CEditableMesh* M = *m_pRefs->FirstMesh(); + CEditableMesh*M = *m_pRefs->FirstMesh(); U16Vec inds; // fill vertices bv_bb.invalidate(); - u32 idx = 0; - for (u32 f_id=0; f_idGetFCount(); f_id++) + u32 idx = 0; + for (u32 f_id = 0; f_idGetFCount(); f_id++) { - st_Face& F = M->GetFaces()[f_id]; - u16 ind[3]; - for (int k=0; k<3; k++,idx++){ - Fvector& P = M->GetVertices()[F.pv[k].pindex]; - st_VMapPt&vm= M->GetVMRefs()[F.pv[k].vmref].pts[0]; - Fvector2& uv= M->GetVMaps()[vm.vmap_index]->getUV(vm.index); - ind[k] = _AddVert (P,uv.x,uv.y); - bv_bb.modify(vertices[ind[k]].P); + st_Face&F = M->GetFaces()[f_id]; + u16 ind[3]; + for (int k = 0; k<3; k++,idx++) + { + Fvector &P = M->GetVertices()[F.pv[k].pindex]; + st_VMapPt&vm = M->GetVMRefs()[F.pv[k].vmref].pts[0]; + Fvector2 &uv = M->GetVMaps()[vm.vmap_index]->getUV(vm.index); + ind[k] = _AddVert(P, uv.x, uv.y); + bv_bb.modify(vertices[ind[k]].P); } - if (isDegenerated(ind)) continue; - if (isEqual(inds,ind)) continue; + if (isDegenerated(ind)) + continue; + if (isEqual(inds, ind)) + continue; inds.push_back(ind[0]); inds.push_back(ind[1]); inds.push_back(ind[2]); } - number_indices = inds.size(); - indices = (u16*)xr_malloc(number_indices*sizeof(u16)); - Memory.mem_copy (indices,inds.begin(),number_indices*sizeof(u16)); + number_indices = inds.size(); + indices = (u16*)xr_malloc(number_indices*sizeof(u16)); + Memory.mem_copy(indices, inds.begin(), number_indices*sizeof(u16)); - bv_bb.getsphere (bv_sphere.P,bv_sphere.R); + bv_bb.getsphere(bv_sphere.P, bv_sphere.R); - OnDeviceCreate (); + OnDeviceCreate(); return true; } -bool EDetail::Load(IReader& F) +bool EDetail::Load(IReader &F) { - // check version - R_ASSERT (F.find_chunk(DETOBJ_CHUNK_VERSION)); - u32 version = F.r_u32(); - if (version!=DETOBJ_VERSION){ - ELog.Msg(mtError,"EDetail: unsupported version."); + // check version + R_ASSERT(F.find_chunk(DETOBJ_CHUNK_VERSION)); + u32 version = F.r_u32(); + if (version!=DETOBJ_VERSION) + { + ELog.Msg(mtError, "EDetail: unsupported version."); return false; } - // references - string256 buf; - R_ASSERT (F.find_chunk(DETOBJ_CHUNK_REFERENCE)); - F.r_stringZ (buf,sizeof(buf)); + // references + string256 buf; + R_ASSERT(F.find_chunk(DETOBJ_CHUNK_REFERENCE)); + F.r_stringZ(buf, sizeof(buf)); // scale - R_ASSERT (F.find_chunk(DETOBJ_CHUNK_SCALE_LIMITS)); - m_fMinScale = F.r_float(); if (fis_zero(m_fMinScale)) m_fMinScale = 0.1f; - m_fMaxScale = F.r_float(); if (m_fMaxScaleFirstSurface(); - R_ASSERT (surf); + R_ASSERT(m_pRefs); + CSurface*surf = *m_pRefs->FirstSurface(); + R_ASSERT(surf); // write data - F.w_stringZ (surf->_ShaderName()); - F.w_stringZ (tex_name);//surf->_Texture()); + F.w_stringZ(surf->_ShaderName()); + F.w_stringZ(tex_name);//surf->_Texture()); - F.w_u32 (m_Flags.get()); - F.w_float (m_fMinScale); - F.w_float (m_fMaxScale); + F.w_u32(m_Flags.get()); + F.w_float(m_fMinScale); + F.w_float(m_fMaxScale); - F.w_u32 (number_vertices); - F.w_u32 (number_indices); + F.w_u32(number_vertices); + F.w_u32(number_indices); // remap UV - EVertexIn* rm_vertices = xr_alloc(number_vertices); - for (u32 k=0; k(number_vertices); + for (u32 k = 0; kFirstSurface(); - R_ASSERT (surf); - IWriter* F = FS.w_open(name); - if (F){ - Fvector2 offs = {0,0}; - Fvector2 scale = {1,1}; - Export (*F,surf->_Texture(),offs,scale,false); - FS.w_close (F); - }else{ - Log ("!Can't export detail:",name); + CSurface*surf = *m_pRefs->FirstSurface(); + R_ASSERT(surf); + IWriter *F = FS.w_open(name); + if (F) + { + Fvector2 offs = {0,0}; + Fvector2 scale = {1,1}; + Export(*F, surf->_Texture(), offs, scale, false); + FS.w_close(F); + } + else + { + Log("!Can't export detail:", name); } } diff --git a/src/editors/ECore/Editor/EDetailModel.h b/src/editors/ECore/Editor/EDetailModel.h index f1503c3a106..244f822cfa6 100644 --- a/src/editors/ECore/Editor/EDetailModel.h +++ b/src/editors/ECore/Editor/EDetailModel.h @@ -2,35 +2,39 @@ #define EDetailModelH #pragma once -#include "..\..\Layers\xrRender\DetailModel.h" +#include "Layers/xrRender/DetailModel.h" // refs class CEditableObject; -class ECORE_API EDetail: public CDetail{ - friend class EDetailManager; - friend class CDetailManager; +class ECORE_API EDetail: + +public +CDetail +{ + friend class EDetailManager; + friend class CDetailManager; friend class TfrmDOShuffle; struct EVertexIn: public fvfVertexIn { - EVertexIn (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; - IC void set (EVertexIn& src){P.set(src.P); u=src.u; v=src.v;}; - IC void set (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; - IC BOOL similar (EVertexIn& V) - { - if (!fsimilar (u,V.u,EPS_L)) return FALSE; - if (!fsimilar (v,V.v,EPS_L)) return FALSE; - if (!P.similar (V.P,EPS_L)) return FALSE; - return TRUE; - } - void remapUV (const fvfVertexIn& src, const Fvector2& offs, const Fvector2& scale, bool bRotate); - }; + EVertexIn (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; +IC void set (EVertexIn& src){P.set(src.P); u=src.u; v=src.v;}; +IC void set (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; +IC BOOL similar (EVertexIn& V) +{ + if (!fsimilar (u,V.u,EPS_L)) return FALSE; + if (!fsimilar (v,V.v,EPS_L)) return FALSE; + if (!P.similar (V.P,EPS_L)) return FALSE; + return TRUE; +} +void remapUV (const fvfVertexIn& src, const Fvector2& offs, const Fvector2& scale, bool bRotate); +}; /* - struct fvfVertexIn{ - Fvector P; - float u,v; - fvfVertexIn (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; + struct fvfVertexIn{ + Fvector P; + float u,v; + fvfVertexIn (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; void set (fvfVertexIn& src){P.set(src.P); u=src.u; v=src.v;}; void set (const Fvector& _P, float _u, float _v){P.set(_P); u=_u; v=_v;}; BOOL similar (fvfVertexIn& V) @@ -40,55 +44,56 @@ class ECORE_API EDetail: public CDetail{ if (!P.similar (V.P,EPS_L)) return FALSE; return TRUE; } - }; - struct fvfVertexOut - { - Fvector P; - DWORD C; - float u,v; - }; + }; + struct fvfVertexOut + { + Fvector P; + DWORD C; + float u,v; + }; float m_fMinScale; float m_fMaxScale; - // render - fvfVertexIn *vertices; - DWORD number_vertices; - WORD *indices; - DWORD number_indices; - ref_shader shader; - Flags32 m_Flags; - Fsphere bv_sphere; - Fbox bv_bb; + // render + fvfVertexIn *vertices; + DWORD number_vertices; + WORD *indices; + DWORD number_indices; + ref_shader shader; + Flags32 m_Flags; + Fsphere bv_sphere; + Fbox bv_bb; */ - float m_fDensityFactor; +float m_fDensityFactor; - // references - AnsiString m_sRefs; - CEditableObject* m_pRefs; +// references +AnsiString m_sRefs; +CEditableObject* m_pRefs; - u16 _AddVert (const Fvector& p, float u, float v); +u16 _AddVert (const Fvector& p, float u, float v); public: // bool m_bMarkDel; public: - EDetail (); - virtual ~EDetail (); +EDetail (); +virtual ~EDetail (); - bool Load (IReader&); - void Save (IWriter&); - void Export (IWriter&, LPCSTR tex_name, const Fvector2& offs, const Fvector2& scale, bool rot); - void Export (LPCSTR name); +bool Load (IReader&); +void Save (IWriter&); +void Export (IWriter&, LPCSTR tex_name, const Fvector2& offs, const Fvector2& scale, bool rot); +void Export (LPCSTR name); - bool Update (LPCSTR name); - virtual void Unload (); +bool Update (LPCSTR name); +virtual void Unload (); - LPCSTR GetName (); - LPCSTR GetTextureName (); - void OnDeviceCreate (); - void OnDeviceDestroy (); - void DefferedLoad (); +LPCSTR GetName (); +LPCSTR GetTextureName (); +void OnDeviceCreate (); +void OnDeviceDestroy (); +void DefferedLoad (); }; -DEFINE_VECTOR(EDetail*,DOVec,DOIt); +DEFINE_VECTOR(EDetail *, DOVec, DOIt); #endif //_INCDEF_DetailModel_H_ + diff --git a/src/editors/ECore/Editor/ELog.cpp b/src/editors/ECore/Editor/ELog.cpp index c78afd834ce..7e9f77379b3 100644 --- a/src/editors/ECore/Editor/ELog.cpp +++ b/src/editors/ECore/Editor/ELog.cpp @@ -60,17 +60,18 @@ //---------------------------------------------------- CLog ELog; + //---------------------------------------------------- -int CLog::DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) +int CLog::DlgMsg(TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) { in_use = true; - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); - int res=0; + int res = 0; #ifdef _EDITOR ExecCommand(COMMAND_RENDER_FOCUS); @@ -107,15 +108,15 @@ int CLog::DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) } -int CLog::DlgMsg (TMsgDlgType mt, LPCSTR _Format, ...) +int CLog::DlgMsg(TMsgDlgType mt, LPCSTR _Format, ...) { in_use = true; - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); - int res=0; + int res = 0; #ifdef _EDITOR ExecCommand(COMMAND_RENDER_FOCUS); @@ -146,19 +147,19 @@ int CLog::DlgMsg (TMsgDlgType mt, LPCSTR _Format, ...) } #endif - Msg(mt,buf); + Msg(mt, buf); in_use = false; - + return res; } void CLog::Msg(TMsgDlgType mt, LPCSTR _Format, ...) { - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); #ifdef _EDITOR TfrmLog::AddMessage(mt,AnsiString(buf)); @@ -172,8 +173,11 @@ void CLog::Msg(TMsgDlgType mt, LPCSTR _Format, ...) } #endif - ::LogExecCB = FALSE; - ::Msg (buf); - ::LogExecCB = TRUE; + ::LogExecCB = FALSE; + ::Msg(buf); + ::LogExecCB = TRUE; } + //---------------------------------------------------- + + diff --git a/src/editors/ECore/Editor/ELog.h b/src/editors/ECore/Editor/ELog.h index bef7f68670f..fd99fb3f5d6 100644 --- a/src/editors/ECore/Editor/ELog.h +++ b/src/editors/ECore/Editor/ELog.h @@ -5,14 +5,15 @@ #ifndef ELogH #define ELogH -class ECORE_API CLog{ -public: - bool in_use; -public: - CLog (){in_use=false;} - void Msg (TMsgDlgType mt, LPCSTR _Format, ...); - int DlgMsg (TMsgDlgType mt, LPCSTR _Format, ...); - int DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...); +class ECORE_API CLog +{ + public: + bool in_use; + public: + CLog(){in_use = false;} + void Msg(TMsgDlgType mt, LPCSTR _Format, ...); + int DlgMsg(TMsgDlgType mt, LPCSTR _Format, ...); + int DlgMsg(TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...); }; void ECORE_API ELogCallback(void *context, LPCSTR txt); diff --git a/src/editors/ECore/Editor/EStats.cpp b/src/editors/ECore/Editor/EStats.cpp index 8f487ad99ab..756d7ae2458 100644 --- a/src/editors/ECore/Editor/EStats.cpp +++ b/src/editors/ECore/Editor/EStats.cpp @@ -2,8 +2,8 @@ #pragma hdrstop #include "EStats.h" -#include "hw.h" -#include "gamefont.h" +#include "Layers/xrRender/HW.h" +#include "xrEngine/GameFont.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -11,130 +11,131 @@ CEStats::CEStats() { - fFPS = 30.f; - fRFPS = 30.f; - fTPS = 0; - dwLevelSelFaceCount = 0; - dwLevelSelVertexCount=0; + fFPS = 30.f; + fRFPS = 30.f; + fTPS = 0; + dwLevelSelFaceCount = 0; + dwLevelSelVertexCount = 0; } -CEStats::~CEStats() -{ +CEStats::~CEStats() {} -} +#include "xrEngine/IGame_Persistent.h" -#include "igame_persistent.h" -void CEStats::Show(CGameFont* font) +void CEStats::Show(CGameFont *font) { - // Stop timers - { - RenderTOTAL.FrameEnd (); - RenderCALC.FrameEnd (); - - RenderDUMP_SKIN.FrameEnd (); - - Animation.FrameEnd (); - Input.FrameEnd (); - clRAY.FrameEnd (); - clBOX.FrameEnd (); - clFRUSTUM.FrameEnd (); - - RenderDUMP_RT.FrameEnd (); - - RenderDUMP_DT_VIS.FrameEnd (); - RenderDUMP_DT_Render.FrameEnd(); - RenderDUMP_DT_Cache.FrameEnd(); - TEST0.FrameEnd (); - TEST1.FrameEnd (); - TEST2.FrameEnd (); - TEST3.FrameEnd (); - } - - // calc FPS & TPS - CBackend::_stats& DPS = RCache.stat; - if (EDevice.fTimeDelta>EPS_S) { - float fps = 1.f/EDevice.fTimeDelta; - float fOne = 0.3f; - float fInv = 1.f-fOne; - fFPS = fInv*fFPS + fOne*fps; - - if (RenderTOTAL.result>EPS_S) { - fTPS = fInv*fTPS + fOne*float(DPS.polys)/(RenderTOTAL.result*1000.f); - fRFPS= fInv*fRFPS+ fOne*1000.f/RenderTOTAL.result; - } - } - - // Show them - if (psDeviceFlags.is(rsStatistic)) - { - CGameFont& F = *font; - F.SetColor (0xFFFFFFFF ); - F.OutSet (5,5); - F.OutNext ("FPS/RFPS: %3.1f/%3.1f", fFPS,fRFPS); - F.OutNext ("TPS: %2.2f M", fTPS); - F.OutNext ("VERT: %d", DPS.verts); - F.OutNext ("POLY: %d", DPS.polys); - F.OutNext ("DIP/DP: %d", DPS.calls); - F.OutNext ("SH/T/M/C: %d/%d/%d/%d", dwShader_Codes,dwShader_Textures,dwShader_Matrices,dwShader_Constants); - F.OutNext ("LIGHT S/T: %d/%d", dwLightInScene,dwTotalLight); - F.OutNext ("Skeletons: %2.2fms, %d", Animation.result,Animation.count); - F.OutNext ("Skinning: %2.2fms", RenderDUMP_SKIN.result); - F.OutSkip (); - F.OutNext ("Input: %2.2fms", Input.result); - F.OutNext ("clRAY: %2.2fms, %d", clRAY.result,clRAY.count); - F.OutNext ("clBOX: %2.2fms, %d", clBOX.result,clBOX.count); - F.OutNext ("clFRUSTUM: %2.2fms, %d", clFRUSTUM.result,clFRUSTUM.count); - F.OutSkip (); -// F.OutNext ("Render: %2.2fms", RenderDUMP.result); - F.OutNext (" RT: %2.2fms, %d", RenderDUMP_RT.result,RenderDUMP_RT.count); - F.OutNext (" DT_Vis: %2.2fms", RenderDUMP_DT_VIS.result); - F.OutNext (" DT_Render: %2.2fms", RenderDUMP_DT_Render.result); - F.OutNext (" DT_Cache: %2.2fms", RenderDUMP_DT_Cache.result); - F.OutSkip (); - F.OutNext ("TEST 0: %2.2fms, %d", TEST0.result,TEST0.count); - F.OutNext ("TEST 1: %2.2fms, %d", TEST1.result,TEST1.count); - F.OutNext ("TEST 2: %2.2fms, %d", TEST2.result,TEST2.count); - F.OutNext ("TEST 3: %2.2fms, %d", TEST3.result,TEST3.count); - F.OutSkip (); -// F.OutNext ("GAME TIME: %s", FloatTimeToStrTime(g_pGamePersistent->Environment().GetGameTime()).c_str()); -// F.OutSkip (2.f); -// F.OutNext ("Level summary:"); -// F.OutNext (" Sel Faces: %d", dwLevelSelFaceCount); -// F.OutNext (" Sel Verts: %d", dwLevelSelVertexCount); - } - - { - Animation.FrameStart (); - RenderTOTAL.FrameStart (); - - Input.FrameStart (); - clRAY.FrameStart (); - clBOX.FrameStart (); - clFRUSTUM.FrameStart (); - - RenderDUMP_SKIN.FrameStart (); - RenderDUMP_RT.FrameStart (); - - RenderDUMP_DT_VIS.FrameStart(); - RenderDUMP_DT_Render.FrameStart(); - RenderDUMP_DT_Cache.FrameStart(); - - TEST0.FrameStart (); - TEST1.FrameStart (); - TEST2.FrameStart (); - TEST3.FrameStart (); - } - dwShader_Codes = dwShader_Textures = dwShader_Matrices = dwShader_Constants = 0; - dwSND_Played = dwSND_Allocated = 0; + // Stop timers + { + RenderTOTAL.FrameEnd(); + RenderCALC.FrameEnd(); + + RenderDUMP_SKIN.FrameEnd(); + + Animation.FrameEnd(); + Input.FrameEnd(); + clRAY.FrameEnd(); + clBOX.FrameEnd(); + clFRUSTUM.FrameEnd(); + + RenderDUMP_RT.FrameEnd(); + + RenderDUMP_DT_VIS.FrameEnd(); + RenderDUMP_DT_Render.FrameEnd(); + RenderDUMP_DT_Cache.FrameEnd(); + TEST0.FrameEnd(); + TEST1.FrameEnd(); + TEST2.FrameEnd(); + TEST3.FrameEnd(); + } + + // calc FPS & TPS + CBackend::_stats &DPS = RCache.stat; + if (EDevice.fTimeDelta>EPS_S) + { + float fps = 1.f/EDevice.fTimeDelta; + float fOne = 0.3f; + float fInv = 1.f-fOne; + fFPS = fInv*fFPS+fOne*fps; + + if (RenderTOTAL.result>EPS_S) + { + fTPS = fInv*fTPS+fOne*float(DPS.polys)/(RenderTOTAL.result*1000.f); + fRFPS = fInv*fRFPS+fOne*1000.f/RenderTOTAL.result; + } + } + + // Show them + if (psDeviceFlags.is(rsStatistic)) + { + CGameFont &F = *font; + F.SetColor(0xFFFFFFFF); + F.OutSet(5, 5); + F.OutNext("FPS/RFPS: %3.1f/%3.1f", fFPS, fRFPS); + F.OutNext("TPS: %2.2f M", fTPS); + F.OutNext("VERT: %d", DPS.verts); + F.OutNext("POLY: %d", DPS.polys); + F.OutNext("DIP/DP: %d", DPS.calls); + F.OutNext("SH/T/M/C: %d/%d/%d/%d", dwShader_Codes, dwShader_Textures, dwShader_Matrices, dwShader_Constants); + F.OutNext("LIGHT S/T: %d/%d", dwLightInScene, dwTotalLight); + F.OutNext("Skeletons: %2.2fms, %d", Animation.result, Animation.count); + F.OutNext("Skinning: %2.2fms", RenderDUMP_SKIN.result); + F.OutSkip(); + F.OutNext("Input: %2.2fms", Input.result); + F.OutNext("clRAY: %2.2fms, %d", clRAY.result, clRAY.count); + F.OutNext("clBOX: %2.2fms, %d", clBOX.result, clBOX.count); + F.OutNext("clFRUSTUM: %2.2fms, %d", clFRUSTUM.result, clFRUSTUM.count); + F.OutSkip(); + // F.OutNext ("Render: %2.2fms", RenderDUMP.result); + F.OutNext(" RT: %2.2fms, %d", RenderDUMP_RT.result, RenderDUMP_RT.count); + F.OutNext(" DT_Vis: %2.2fms", RenderDUMP_DT_VIS.result); + F.OutNext(" DT_Render: %2.2fms", RenderDUMP_DT_Render.result); + F.OutNext(" DT_Cache: %2.2fms", RenderDUMP_DT_Cache.result); + F.OutSkip(); + F.OutNext("TEST 0: %2.2fms, %d", TEST0.result, TEST0.count); + F.OutNext("TEST 1: %2.2fms, %d", TEST1.result, TEST1.count); + F.OutNext("TEST 2: %2.2fms, %d", TEST2.result, TEST2.count); + F.OutNext("TEST 3: %2.2fms, %d", TEST3.result, TEST3.count); + F.OutSkip(); + // F.OutNext ("GAME TIME: %s", FloatTimeToStrTime(g_pGamePersistent->Environment().GetGameTime()).c_str()); + // F.OutSkip (2.f); + // F.OutNext ("Level summary:"); + // F.OutNext (" Sel Faces: %d", dwLevelSelFaceCount); + // F.OutNext (" Sel Verts: %d", dwLevelSelVertexCount); + } + + { + Animation.FrameStart(); + RenderTOTAL.FrameStart(); + + Input.FrameStart(); + clRAY.FrameStart(); + clBOX.FrameStart(); + clFRUSTUM.FrameStart(); + + RenderDUMP_SKIN.FrameStart(); + RenderDUMP_RT.FrameStart(); + + RenderDUMP_DT_VIS.FrameStart(); + RenderDUMP_DT_Render.FrameStart(); + RenderDUMP_DT_Cache.FrameStart(); + + TEST0.FrameStart(); + TEST1.FrameStart(); + TEST2.FrameStart(); + TEST3.FrameStart(); + } + dwShader_Codes = dwShader_Textures = dwShader_Matrices = dwShader_Constants = 0; + dwSND_Played = dwSND_Allocated = 0; dwTotalLight = dwLightInScene = 0; - DPS.polys = 0; - DPS.verts = 0; - DPS.calls = 0; - DPS.vs = 0; -// DPS.vb = 0; -// DPS.ib = 0; + DPS.polys = 0; + DPS.verts = 0; + DPS.calls = 0; + DPS.vs = 0; + // DPS.vb = 0; + // DPS.ib = 0; - dwLevelSelFaceCount = 0; - dwLevelSelVertexCount = 0; + dwLevelSelFaceCount = 0; + dwLevelSelVertexCount = 0; } + diff --git a/src/editors/ECore/Editor/EStats.h b/src/editors/ECore/Editor/EStats.h index 1417533231a..7a61cf83a6d 100644 --- a/src/editors/ECore/Editor/EStats.h +++ b/src/editors/ECore/Editor/EStats.h @@ -5,52 +5,56 @@ #ifndef EStatsH #define EStatsH #pragma once -#include "../../../xrengine/stats.h" +#include "xrEngine/Stats.h" // refs class CGameFont; class ENGINE_API CEStats: - public CStatsPhysics + +public +CStatsPhysics { -public: - float fFPS,fRFPS,fTPS; // FPS, RenderFPS, TPS - u32 dwShader_Codes; // Number of times the shader-code changes - u32 dwShader_Textures; // Number of times the shader-tex changes - u32 dwShader_Matrices; // Number of times the shader-xform changes - u32 dwShader_Constants; // Number of times the shader-consts changes - u32 dwSND_Played,dwSND_Allocated; // Play/Alloc - u32 dwTotalLight,dwLightInScene; - u32 dwLevelSelFaceCount; // Number of faces in scene - u32 dwLevelSelVertexCount; // Number of vertices in scene - - CStatTimer RenderDUMP_RT; - CStatTimer RenderTOTAL; // - CStatTimer RenderTOTAL_Real; - CStatTimer RenderCALC; // portal traversal, frustum culling, entities "OnVisible" - CStatTimer RenderDUMP_SKIN; - CStatTimer Animation; // skeleton calculation - CStatTimer RenderDUMP_DT_VIS; // ...details visibility detection - CStatTimer RenderDUMP_DT_Render;// ...details rendering - CStatTimer RenderDUMP_DT_Cache;// ...details slot cache access - - u32 RenderDUMP_DT_Count; - - CStatTimer Input; // total time taken by input subsystem (accurate only in single-threaded mode) - CStatTimer clRAY; // total: ray-testing - CStatTimer clBOX; // total: box query - CStatTimer clFRUSTUM; // total: frustum query - - CStatTimer TEST0; // debug counter - CStatTimer TEST1; // debug counter - CStatTimer TEST2; // debug counter - CStatTimer TEST3; // debug counter - - void Show (CGameFont* font); - - CEStats (); - ~CEStats (); + public: + float fFPS,fRFPS,fTPS; // FPS, RenderFPS, TPS + u32 dwShader_Codes; // Number of times the shader-code changes + u32 dwShader_Textures; // Number of times the shader-tex changes + u32 dwShader_Matrices; // Number of times the shader-xform changes + u32 dwShader_Constants; // Number of times the shader-consts changes + u32 dwSND_Played,dwSND_Allocated; // Play/Alloc + u32 dwTotalLight,dwLightInScene; + u32 dwLevelSelFaceCount; // Number of faces in scene + u32 dwLevelSelVertexCount; // Number of vertices in scene + + CStatTimer RenderDUMP_RT; + CStatTimer RenderTOTAL; // + CStatTimer RenderTOTAL_Real; + CStatTimer RenderCALC; // portal traversal, frustum culling, entities "OnVisible" + CStatTimer RenderDUMP_SKIN; + CStatTimer Animation; // skeleton calculation + CStatTimer RenderDUMP_DT_VIS; // ...details visibility detection + CStatTimer RenderDUMP_DT_Render;// ...details rendering + CStatTimer RenderDUMP_DT_Cache;// ...details slot cache access + + u32 RenderDUMP_DT_Count; + + CStatTimer Input; // total time taken by input subsystem (accurate only in single-threaded mode) + CStatTimer clRAY; // total: ray-testing + CStatTimer clBOX; // total: box query + CStatTimer clFRUSTUM; // total: frustum query + + CStatTimer TEST0; // debug counter + CStatTimer TEST1; // debug counter + CStatTimer TEST2; // debug counter + CStatTimer TEST3; // debug counter + + void Show (CGameFont* font); + + CEStats (); + ~CEStats (); }; #define UPDATEC(vert,poly,pass) { EDevice.Statistic->dwVert+=(vert)*(pass);EDevice.Statistic->dwPoly+=(poly)*pass; EDevice.Statistic->dwCalls+=pass; } #endif // !defined(AFX_STATS_H__4C8D1860_0EE2_11D4_B4E3_4854E82A090D__INCLUDED_) + + diff --git a/src/editors/ECore/Editor/ETextureParams.cpp b/src/editors/ECore/Editor/ETextureParams.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/ETextureParams.cpp @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/ETextureParams.h b/src/editors/ECore/Editor/ETextureParams.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/ETextureParams.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/EThumbnail.cpp b/src/editors/ECore/Editor/EThumbnail.cpp index 13ada8d40a3..7292ad21763 100644 --- a/src/editors/ECore/Editor/EThumbnail.cpp +++ b/src/editors/ECore/Editor/EThumbnail.cpp @@ -2,7 +2,7 @@ #pragma hdrstop #include "EThumbnail.h" -#include "folderlib.h" +#include "editors/xrEProps/FolderLib.h" #include "xrImage_Resampler.h" #pragma package(smart_init) //------------------------------------------------------------------------------ @@ -10,20 +10,20 @@ //------------------------------------------------------------------------------ ECustomThumbnail::ECustomThumbnail(LPCSTR src_name, THMType type) { - m_Type = type; - m_SrcName = src_name; - m_Name = ChangeFileExt(AnsiString(src_name),".thm"); - m_Age = 0; + m_Type = type; + m_SrcName = src_name; + m_Name = ChangeFileExt(AnsiString(src_name), ".thm"); + m_Age = 0; } + //------------------------------------------------------------------------------ -ECustomThumbnail::~ECustomThumbnail() -{ -} +ECustomThumbnail::~ECustomThumbnail() {} + /* void DrawThumbnail(TCanvas* pCanvas, TRect& r, U32Vec& data, bool bDrawWithAlpha, int _w = THUMB_WIDTH, int _h = THUMB_HEIGHT) { - pCanvas->CopyMode = cmSrcCopy; + pCanvas->CopyMode = cmSrcCopy; Graphics::TBitmap *pBitmap = xr_new(); pBitmap->PixelFormat = pf32bit; @@ -31,7 +31,7 @@ void DrawThumbnail(TCanvas* pCanvas, TRect& r, U32Vec& data, bool bDrawWithAlpha pBitmap->Width = _w; if (bDrawWithAlpha){ - Fcolor back; + Fcolor back; back.set (bgr2rgb(pCanvas->Brush->Color)); back.mul_rgb(255.f); for (int y = 0; y < pBitmap->Height; y++) { @@ -64,45 +64,46 @@ void DrawThumbnail(TCanvas* pCanvas, TRect& r, U32Vec& data, bool bDrawWithAlpha //------------------------------------------------------------------------------ EImageThumbnail::~EImageThumbnail() { - m_Pixels.clear(); + m_Pixels.clear(); } void EImageThumbnail::VFlip() { - R_ASSERT(!m_Pixels.empty()); - u32 line[THUMB_WIDTH]; - u32 sz_ln=sizeof(u32)*THUMB_WIDTH; + R_ASSERT(!m_Pixels.empty()); + u32 line[THUMB_WIDTH]; + u32 sz_ln = sizeof(u32)*THUMB_WIDTH; u32 y2 = THUMB_WIDTH-1; - for (int y=0; y0)&&(h>0)); - m_Pixels.resize(THUMB_SIZE); - imf_Process(m_Pixels.begin(),THUMB_WIDTH,THUMB_HEIGHT,p,w,h,imf_box); + // imf_filter imf_box imf_triangle imf_bell imf_b_spline imf_lanczos3 imf_mitchell + R_ASSERT(p&&(w>0)&&(h>0)); + m_Pixels.resize(THUMB_SIZE); + imf_Process(m_Pixels.begin(), THUMB_WIDTH, THUMB_HEIGHT, p, w, h, imf_box); } -void EImageThumbnail::Draw(HDC hdc, const Irect& r) +void EImageThumbnail::Draw(HDC hdc, const Irect &r) { - if (Valid()) - FHelper.DrawThumbnail(hdc,r,Pixels(),THUMB_WIDTH,THUMB_HEIGHT); + if (Valid()) + FHelper.DrawThumbnail(hdc, r, Pixels(), THUMB_WIDTH, THUMB_HEIGHT); } -EImageThumbnail* CreateThumbnail(LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad) +EImageThumbnail *CreateThumbnail(LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad) { - switch (type){ - case ECustomThumbnail::ETObject: return xr_new (src_name,bLoad); - case ECustomThumbnail::ETTexture: return xr_new(src_name,bLoad); - case ECustomThumbnail::ETGroup: return xr_new (src_name,bLoad); - default: NODEFAULT; + switch (type) + { + case ECustomThumbnail::ETObject: return xr_new(src_name,bLoad); + case ECustomThumbnail::ETTexture: return xr_new(src_name,bLoad); + case ECustomThumbnail::ETGroup: return xr_new(src_name,bLoad); + default: NODEFAULT; } - return 0; + return 0; } - diff --git a/src/editors/ECore/Editor/EThumbnail.h b/src/editors/ECore/Editor/EThumbnail.h index 7873d474b03..7940f430580 100644 --- a/src/editors/ECore/Editor/EThumbnail.h +++ b/src/editors/ECore/Editor/EThumbnail.h @@ -1,171 +1,195 @@ #ifndef EThumbnailH #define EThumbnailH -#include "../Layers/xrRender/ETextureParams.h" -#include "../../xrServerEntities/PropertiesListHelper.h" +#include "Layers/xrRender/ETextureParams.h" +#include "xrServerEntities/PropertiesListHelper.h" #include "MXCtrls.hpp" //------------------------------------------------------------------------------ // Custom class //------------------------------------------------------------------------------ -class ECORE_API ECustomThumbnail{ -public: - enum THMType{ - ETUndef = -1, - ETObject = 0, - ETTexture = 1, - ETSound = 2, - ETGroup = 3, +class ECORE_API ECustomThumbnail{ + public: + enum THMType{ + ETUndef = -1, + ETObject = 0, + ETTexture = 1, + ETSound = 2, + ETGroup = 3, force_dword = (-1) }; -protected: - AnsiString m_SrcName; - AnsiString m_Name; - int m_Age; - THMType m_Type; -public: - ECustomThumbnail(LPCSTR src_name, THMType type); - virtual ~ECustomThumbnail(); + protected: + AnsiString m_SrcName; + AnsiString m_Name; + int m_Age; + THMType m_Type; + public: + ECustomThumbnail(LPCSTR src_name, THMType type); + virtual ~ECustomThumbnail(); - LPCSTR Name (){return m_Name.c_str();} - LPCSTR SrcName (){return m_SrcName.c_str();} + LPCSTR Name(){return m_Name.c_str();} + LPCSTR SrcName(){return m_SrcName.c_str();} - IC bool IsClass (THMType type){return m_Type==type;} + IC bool IsClass(THMType type){return m_Type==type;} // thumbnail public routines - virtual bool Load (LPCSTR src_name=0, LPCSTR path=0)=0; - virtual void Save (int age=0,LPCSTR path=0)=0; - virtual bool Valid ()=0; -// virtual void FillProp (PropItemVec& values)=0; - virtual void FillInfo (PropItemVec& values)=0; + virtual bool Load(LPCSTR src_name = 0, LPCSTR path = 0) = 0; + virtual void Save(int age = 0, LPCSTR path = 0) = 0; + virtual bool Valid() = 0; + // virtual void FillProp (PropItemVec& values)=0; + virtual void FillInfo(PropItemVec&values) = 0; }; + //------------------------------------------------------------------------------ -class ECORE_API EImageThumbnail: public ECustomThumbnail{ - friend class CImageManager; -protected: - U32Vec m_Pixels; -protected: - void CreatePixels (u32* p, u32 w, u32 h); - void VFlip (); -public: - EImageThumbnail (LPCSTR src_name, THMType type):ECustomThumbnail(src_name, type){}; - virtual ~EImageThumbnail(); - virtual void Draw (HDC hdc, const Irect& r); - virtual void Draw (TMxPanel* panel){Irect r; r.set(1,1,1+panel->Width,1+panel->Height); Draw(panel->Canvas->Handle,r);} - u32* Pixels (){return &*m_Pixels.begin();} - virtual int MemoryUsage (){return 0;}; +class ECORE_API EImageThumbnail: + +public +ECustomThumbnail +{ + friend class CImageManager; + protected: + U32Vec m_Pixels; + protected: + void CreatePixels (u32* p, u32 w, u32 h); + void VFlip (); + public: + EImageThumbnail (LPCSTR src_name, THMType type):ECustomThumbnail(src_name, type){}; +virtual ~EImageThumbnail(); +virtual void Draw (HDC hdc, const Irect& r); +virtual void Draw (TMxPanel* panel){Irect r; r.set(1,1,1+panel->Width,1+panel->Height); Draw(panel->Canvas->Handle,r);} +u32* Pixels (){return &*m_Pixels.begin();} +virtual int MemoryUsage (){return 0;}; }; -class ECORE_API ETextureThumbnail: public EImageThumbnail{ - friend class CImageManager; - typedef EImageThumbnail inherited; -private: - STextureParams m_TexParams; - bool m_bValid; -public: - ETextureThumbnail (LPCSTR src_name, bool bLoad=true); - virtual ~ETextureThumbnail (); +class ECORE_API ETextureThumbnail: + +public +EImageThumbnail +{ + friend class CImageManager; + typedef EImageThumbnail inherited; + private: + STextureParams m_TexParams; + bool m_bValid; + public: + ETextureThumbnail (LPCSTR src_name, bool bLoad=true); + virtual ~ETextureThumbnail (); // Texture routines - void CreateFromData (u32* p, u32 w, u32 h); - IC u32 _Width (){return m_TexParams.width;} - IC u32 _Height (){return m_TexParams.height;} - IC u32 _Alpha (){return m_TexParams.HasAlphaChannel();} - // thumbnail public routines - IC STextureParams& _Format (){return m_TexParams;} - virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); - virtual void Save (int age=0,LPCSTR path=0); - virtual bool Valid (){return m_bValid; /*return !m_Pixels.empty();*/} - void SetValid () {m_bValid = true;} - virtual void FillProp (PropItemVec& values, PropValue::TOnChange on_type_change); - virtual void FillInfo (PropItemVec& values); - - virtual void Draw (HDC hdc, const Irect& r); - virtual void Draw (TMxPanel* panel){inherited::Draw(panel);} - - virtual int MemoryUsage (); - LPCSTR FormatString (); - BOOL similar (ETextureThumbnail* thm1, xr_vector& sel_params); + void CreateFromData (u32* p, u32 w, u32 h); + IC u32 _Width (){return m_TexParams.width;} +IC u32 _Height (){return m_TexParams.height;} +IC u32 _Alpha (){return m_TexParams.HasAlphaChannel();} +// thumbnail public routines +IC STextureParams& _Format (){return m_TexParams;} +virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); +virtual void Save (int age=0,LPCSTR path=0); +virtual bool Valid (){return m_bValid; /*return !m_Pixels.empty();*/} +void SetValid () {m_bValid = true;} +virtual void FillProp (PropItemVec& values, PropValue::TOnChange on_type_change); +virtual void FillInfo (PropItemVec& values); + +virtual void Draw (HDC hdc, const Irect& r); +virtual void Draw (TMxPanel* panel){inherited::Draw(panel);} + +virtual int MemoryUsage (); +LPCSTR FormatString (); +BOOL similar (ETextureThumbnail* thm1, xr_vector& sel_params); }; + //------------------------------------------------------------------------------ -class ECORE_API EObjectThumbnail: public EImageThumbnail{ - friend class CImageManager; - typedef EImageThumbnail inherited; -private: - u32 face_count; - u32 vertex_count; -public: - EObjectThumbnail (LPCSTR src_name, bool bLoad=true); - virtual ~EObjectThumbnail (); +class ECORE_API EObjectThumbnail: - // Object routines - void CreateFromData (u32* p, u32 w, u32 h, int fc, int vc); - IC int _VertexCount (){return vertex_count;} - IC int _FaceCount (){return face_count;} +public +EImageThumbnail +{ + friend class CImageManager; + typedef EImageThumbnail inherited; + private: + u32 face_count; + u32 vertex_count; + public: + EObjectThumbnail (LPCSTR src_name, bool bLoad=true); + virtual ~EObjectThumbnail (); - // thumbnail public routines - virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); - virtual void Save (int age=0,LPCSTR path=0); - virtual bool Valid (){return !m_Pixels.empty();} - virtual void FillProp (PropItemVec& values); - virtual void FillInfo (PropItemVec& values); + // Object routines + void CreateFromData (u32* p, u32 w, u32 h, int fc, int vc); + IC int _VertexCount (){return vertex_count;} +IC int _FaceCount (){return face_count;} + +// thumbnail public routines +virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); +virtual void Save (int age=0,LPCSTR path=0); +virtual bool Valid (){return !m_Pixels.empty();} +virtual void FillProp (PropItemVec& values); +virtual void FillInfo (PropItemVec& values); }; + //------------------------------------------------------------------------------ -class ECORE_API EGroupThumbnail: public EImageThumbnail{ - friend class CImageManager; - typedef EImageThumbnail inherited; -private: - SStringVec objects; -public: - EGroupThumbnail (LPCSTR src_name, bool bLoad=true); - virtual ~EGroupThumbnail(); +class ECORE_API EGroupThumbnail: + +public +EImageThumbnail +{ + friend class CImageManager; + typedef EImageThumbnail inherited; + private: + SStringVec objects; + public: + EGroupThumbnail (LPCSTR src_name, bool bLoad=true); + virtual ~EGroupThumbnail(); // Object routines - void CreateFromData (u32* p, u32 w, u32 h, const SStringVec& lst); + void CreateFromData (u32* p, u32 w, u32 h, const SStringVec& lst); // thumbnail public routines - virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); - virtual void Save (int age=0,LPCSTR path=0); - virtual bool Valid (){return !m_Pixels.empty();} - virtual void FillProp (PropItemVec& values); - virtual void FillInfo (PropItemVec& values); + virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); + virtual void Save (int age=0,LPCSTR path=0); + virtual bool Valid (){return !m_Pixels.empty();} +virtual void FillProp (PropItemVec& values); +virtual void FillInfo (PropItemVec& values); }; + //------------------------------------------------------------------------------ -class ECORE_API ESoundThumbnail: public ECustomThumbnail{ - friend class CSoundManager; - typedef ECustomThumbnail inherited; -private: - float m_fQuality; - float m_fMinDist; - float m_fMaxDist; - float m_fMaxAIDist; - float m_fBaseVolume; - u32 m_uGameType; - bool OnMaxAIDistAfterEdit(PropValue* sender, float& edit_val); - void OnMaxDistChange (PropValue* sender); -public: - ESoundThumbnail (LPCSTR src_name, bool bLoad=true); - virtual ~ESoundThumbnail(); +class ECORE_API ESoundThumbnail: + +public +ECustomThumbnail +{ + friend class CSoundManager; + typedef ECustomThumbnail inherited; + private: + float m_fQuality; + float m_fMinDist; + float m_fMaxDist; + float m_fMaxAIDist; + float m_fBaseVolume; + u32 m_uGameType; + bool OnMaxAIDistAfterEdit(PropValue* sender, float& edit_val); + void OnMaxDistChange (PropValue* sender); + public: + ESoundThumbnail (LPCSTR src_name, bool bLoad=true); + virtual ~ESoundThumbnail(); // thumbnail public routines - virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); - virtual void Save (int age=0,LPCSTR path=0); - virtual bool Valid (){return true;} - virtual void FillProp (PropItemVec& values); - virtual void FillInfo (PropItemVec& values); - float MinDist (){return m_fMinDist;} - float MaxDist (){return m_fMaxDist;}; - float BaseVolume (){return m_fBaseVolume;}; - void SetMinDist (float d){m_fMinDist=d;} - void SetMaxDist (float d){m_fMaxDist=d;}; + virtual bool Load (LPCSTR src_name=0, LPCSTR path=0); + virtual void Save (int age=0,LPCSTR path=0); + virtual bool Valid (){return true;} +virtual void FillProp (PropItemVec& values); +virtual void FillInfo (PropItemVec& values); +float MinDist (){return m_fMinDist;} +float MaxDist (){return m_fMaxDist;}; +float BaseVolume (){return m_fBaseVolume;}; +void SetMinDist (float d){m_fMinDist=d;} +void SetMaxDist (float d){m_fMaxDist=d;}; }; //------------------------------------------------------------------------------ -EImageThumbnail* CreateThumbnail (LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad=true); +EImageThumbnail *CreateThumbnail(LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad = true); #endif diff --git a/src/editors/ECore/Editor/EThumbnailGroup.cpp b/src/editors/ECore/Editor/EThumbnailGroup.cpp index 4c2f1c71a99..f964929ea0a 100644 --- a/src/editors/ECore/Editor/EThumbnailGroup.cpp +++ b/src/editors/ECore/Editor/EThumbnailGroup.cpp @@ -9,109 +9,129 @@ #define THM_GROUP_VERSION 0x0001 //------------------------------------------------------------------------------ #define THM_CHUNK_GROUPPARAM 0x0001 + //------------------------------------------------------------------------------ -EGroupThumbnail::EGroupThumbnail(LPCSTR src_name, bool bLoad):EImageThumbnail(src_name,ETObject) +EGroupThumbnail::EGroupThumbnail(LPCSTR src_name, bool bLoad): EImageThumbnail(src_name, ETObject) { - if (bLoad) Load(); + if (bLoad) + Load(); } + //------------------------------------------------------------------------------ EGroupThumbnail::~EGroupThumbnail() { - m_Pixels.clear(); + m_Pixels.clear(); } + //------------------------------------------------------------------------------ -void EGroupThumbnail::CreateFromData(u32* p, u32 w, u32 h, const SStringVec& lst) +void EGroupThumbnail::CreateFromData(u32 *p, u32 w, u32 h, const SStringVec &lst) { - EImageThumbnail::CreatePixels(p, w, h); - objects = lst; + EImageThumbnail::CreatePixels(p, w, h); + objects = lst; } + //------------------------------------------------------------------------------ bool EGroupThumbnail::Load(LPCSTR src_name, LPCSTR path) { - string_path fn; - strcpy(fn,EFS.ChangeFileExt(src_name?src_name:m_Name.c_str(),".thm").c_str()); - if (path) FS.update_path(fn,path,fn); - else FS.update_path(fn,_objects_,fn); - if (!FS.exist(fn)) return false; - - IReader* F = FS.r_open(fn); - u16 version = 0; - - R_ASSERT(F->r_chunk(THM_CHUNK_VERSION,&version)); - if( version!=THM_GROUP_VERSION ){ - Msg ("!Thumbnail: Unsupported version."); - return false; + string_path fn; + strcpy(fn, EFS.ChangeFileExt(src_name ? src_name : m_Name.c_str(), ".thm").c_str()); + if (path) + FS.update_path(fn, path, fn); + else + FS.update_path(fn, _objects_, fn); + if (!FS.exist(fn)) + return false; + + IReader *F = FS.r_open(fn); + u16 version = 0; + + R_ASSERT(F->r_chunk(THM_CHUNK_VERSION, &version)); + if (version!=THM_GROUP_VERSION) + { + Msg("!Thumbnail: Unsupported version."); + return false; } - IReader* D = F->open_chunk(THM_CHUNK_DATA); R_ASSERT(D); - m_Pixels.resize (THUMB_SIZE); - D->r (m_Pixels.begin(),THUMB_SIZE*sizeof(u32)); - D->close (); + IReader *D = F->open_chunk(THM_CHUNK_DATA); + R_ASSERT(D); + m_Pixels.resize(THUMB_SIZE); + D->r(m_Pixels.begin(), THUMB_SIZE*sizeof(u32)); + D->close(); - R_ASSERT (F->find_chunk(THM_CHUNK_TYPE)); - m_Type = THMType(F->r_u32()); - R_ASSERT (m_Type==ETObject); + R_ASSERT(F->find_chunk(THM_CHUNK_TYPE)); + m_Type = THMType(F->r_u32()); + R_ASSERT(m_Type==ETObject); - R_ASSERT (F->find_chunk(THM_CHUNK_GROUPPARAM)); - objects.resize (F->r_u32()); - for (SStringVecIt it=objects.begin(); it!=objects.end(); it++) - F->r_stringZ(*it); - - m_Age = FS.get_file_age(fn); + R_ASSERT(F->find_chunk(THM_CHUNK_GROUPPARAM)); + objects.resize(F->r_u32()); + for (SStringVecIt it = objects.begin(); it!=objects.end(); it++) + F->r_stringZ(*it); - FS.r_close (F); + m_Age = FS.get_file_age(fn); + + FS.r_close(F); return true; } + //------------------------------------------------------------------------------ void EGroupThumbnail::Save(int age, LPCSTR path) { - if (!Valid()) return; + if (!Valid()) + return; CMemoryWriter F; - F.open_chunk (THM_CHUNK_VERSION); - F.w_u16 (THM_GROUP_VERSION); - F.close_chunk (); - - F.w_chunk (THM_CHUNK_DATA | CFS_CompressMark,m_Pixels.begin(),m_Pixels.size()*sizeof(u32)); - - F.open_chunk (THM_CHUNK_TYPE); - F.w_u32 (m_Type); - F.close_chunk (); - - F.open_chunk (THM_CHUNK_GROUPPARAM); - F.w_u32 (objects.size()); - for (SStringVecIt it=objects.begin(); it!=objects.end(); it++) - F.w_stringZ (*it); - F.close_chunk (); - - string_path fn; - if (path) FS.update_path(fn,path,m_Name.c_str()); - else FS.update_path(fn,_objects_,m_Name.c_str()); + F.open_chunk(THM_CHUNK_VERSION); + F.w_u16(THM_GROUP_VERSION); + F.close_chunk(); + + F.w_chunk(THM_CHUNK_DATA|CFS_CompressMark, m_Pixels.begin(), m_Pixels.size()*sizeof(u32)); + + F.open_chunk(THM_CHUNK_TYPE); + F.w_u32(m_Type); + F.close_chunk(); + + F.open_chunk(THM_CHUNK_GROUPPARAM); + F.w_u32(objects.size()); + for (SStringVecIt it = objects.begin(); it!=objects.end(); it++) + F.w_stringZ(*it); + F.close_chunk(); + + string_path fn; + if (path) + FS.update_path(fn, path, m_Name.c_str()); + else + FS.update_path(fn, _objects_, m_Name.c_str()); if (F.save_to(fn)) { - FS.set_file_age (fn,age?age:m_Age); - }else{ - Log ("!Can't save thumbnail:",fn); + FS.set_file_age(fn, age ? age : m_Age); + } + else + { + Log("!Can't save thumbnail:", fn); } } + //------------------------------------------------------------------------------ -void EGroupThumbnail::FillProp(PropItemVec& items) +void EGroupThumbnail::FillProp(PropItemVec &items) { - PHelper().CreateCaption (items, "Objects\\Count", AnsiString(objects.size()).c_str()); - for (SStringVecIt it=objects.begin(); it!=objects.end(); it++) - PHelper().CreateCaption (items, AnsiString().sprintf("Objects\\#%d",it-objects.begin()).c_str(),it->c_str()); + PHelper().CreateCaption(items, "Objects\\Count", AnsiString(objects.size()).c_str()); + for (SStringVecIt it = objects.begin(); it!=objects.end(); it++) + PHelper().CreateCaption(items, AnsiString().sprintf("Objects\\#%d", it-objects.begin()).c_str(), it->c_str()); } + //------------------------------------------------------------------------------ -void EGroupThumbnail::FillInfo(PropItemVec& items) +void EGroupThumbnail::FillInfo(PropItemVec &items) { - FillProp (items); + FillProp(items); } + //------------------------------------------------------------------------------ + diff --git a/src/editors/ECore/Editor/EThumbnailObject.cpp b/src/editors/ECore/Editor/EThumbnailObject.cpp index 8fffd64bb39..b1aeaf7443c 100644 --- a/src/editors/ECore/Editor/EThumbnailObject.cpp +++ b/src/editors/ECore/Editor/EThumbnailObject.cpp @@ -9,110 +9,128 @@ #define THM_OBJECT_VERSION 0x0012 //------------------------------------------------------------------------------ #define THM_CHUNK_OBJECTPARAM 0x0816 + //------------------------------------------------------------------------------ -EObjectThumbnail::EObjectThumbnail(LPCSTR src_name, bool bLoad):EImageThumbnail(src_name,ETObject) +EObjectThumbnail::EObjectThumbnail(LPCSTR src_name, bool bLoad): EImageThumbnail(src_name, ETObject) { - if (bLoad) Load(); + if (bLoad) + Load(); } + //------------------------------------------------------------------------------ EObjectThumbnail::~EObjectThumbnail() { - m_Pixels.clear(); + m_Pixels.clear(); } + //------------------------------------------------------------------------------ -void EObjectThumbnail::CreateFromData(u32* p, u32 w, u32 h, int fc, int vc) +void EObjectThumbnail::CreateFromData(u32 *p, u32 w, u32 h, int fc, int vc) { - EImageThumbnail::CreatePixels(p, w, h); - face_count = fc; - vertex_count = vc; + EImageThumbnail::CreatePixels(p, w, h); + face_count = fc; + vertex_count = vc; } + //------------------------------------------------------------------------------ bool EObjectThumbnail::Load(LPCSTR src_name, LPCSTR path) { - string_path fn; - strcpy(fn,EFS.ChangeFileExt(src_name?src_name:m_Name.c_str(),".thm").c_str()); - if (path) FS.update_path(fn,path,fn); - else FS.update_path(fn,_objects_,fn); - if (!FS.exist(fn)) return false; - - IReader* F = FS.r_open(fn); - u16 version = 0; - - R_ASSERT(F->r_chunk(THM_CHUNK_VERSION,&version)); - if( version!=THM_OBJECT_VERSION ){ - Msg ("!Thumbnail: Unsupported version."); - return false; + string_path fn; + strcpy(fn, EFS.ChangeFileExt(src_name ? src_name : m_Name.c_str(), ".thm").c_str()); + if (path) + FS.update_path(fn, path, fn); + else + FS.update_path(fn, _objects_, fn); + if (!FS.exist(fn)) + return false; + + IReader *F = FS.r_open(fn); + u16 version = 0; + + R_ASSERT(F->r_chunk(THM_CHUNK_VERSION, &version)); + if (version!=THM_OBJECT_VERSION) + { + Msg("!Thumbnail: Unsupported version."); + return false; } - IReader* D = F->open_chunk(THM_CHUNK_DATA); R_ASSERT(D); - m_Pixels.resize (THUMB_SIZE); - D->r (m_Pixels.begin(),THUMB_SIZE*sizeof(u32)); - D->close (); + IReader *D = F->open_chunk(THM_CHUNK_DATA); + R_ASSERT(D); + m_Pixels.resize(THUMB_SIZE); + D->r(m_Pixels.begin(), THUMB_SIZE*sizeof(u32)); + D->close(); + + R_ASSERT(F->find_chunk(THM_CHUNK_TYPE)); + m_Type = THMType(F->r_u32()); + R_ASSERT(m_Type==ETObject); - R_ASSERT (F->find_chunk(THM_CHUNK_TYPE)); - m_Type = THMType(F->r_u32()); - R_ASSERT (m_Type==ETObject); + R_ASSERT(F->find_chunk(THM_CHUNK_OBJECTPARAM)); + face_count = F->r_u32(); + vertex_count = F->r_u32(); - R_ASSERT (F->find_chunk(THM_CHUNK_OBJECTPARAM)); - face_count = F->r_u32(); - vertex_count = F->r_u32(); - - m_Age = FS.get_file_age(fn); + m_Age = FS.get_file_age(fn); - FS.r_close (F); + FS.r_close(F); return true; } + //------------------------------------------------------------------------------ void EObjectThumbnail::Save(int age, LPCSTR path) { - if (!Valid()) return; + if (!Valid()) + return; CMemoryWriter F; - F.open_chunk (THM_CHUNK_VERSION); - F.w_u16 (THM_OBJECT_VERSION); - F.close_chunk (); + F.open_chunk(THM_CHUNK_VERSION); + F.w_u16(THM_OBJECT_VERSION); + F.close_chunk(); - F.w_chunk (THM_CHUNK_DATA | CFS_CompressMark,m_Pixels.begin(),m_Pixels.size()*sizeof(u32)); + F.w_chunk(THM_CHUNK_DATA|CFS_CompressMark, m_Pixels.begin(), m_Pixels.size()*sizeof(u32)); - F.open_chunk (THM_CHUNK_TYPE); - F.w_u32 (m_Type); - F.close_chunk (); + F.open_chunk(THM_CHUNK_TYPE); + F.w_u32(m_Type); + F.close_chunk(); - F.open_chunk (THM_CHUNK_OBJECTPARAM); - F.w_u32 (face_count); - F.w_u32 (vertex_count); - F.close_chunk (); + F.open_chunk(THM_CHUNK_OBJECTPARAM); + F.w_u32(face_count); + F.w_u32(vertex_count); + F.close_chunk(); - string_path fn; -//. if (path) FS.update_path(fn,path,m_Name.c_str()); -//. else FS.update_path(fn,_objects_,m_Name.c_str()); + string_path fn; + //. if (path) FS.update_path(fn,path,m_Name.c_str()); + //. else FS.update_path(fn,_objects_,m_Name.c_str()); - strcpy (fn,m_Name.c_str()); + strcpy(fn, m_Name.c_str()); if (F.save_to(fn)) { - FS.set_file_age (fn,age?age:m_Age); - }else{ - Log ("!Can't save thumbnail:",fn); + FS.set_file_age(fn, age ? age : m_Age); + } + else + { + Log("!Can't save thumbnail:", fn); } } + //------------------------------------------------------------------------------ -void EObjectThumbnail::FillProp(PropItemVec& items) +void EObjectThumbnail::FillProp(PropItemVec &items) { - PHelper().CreateCaption (items, "Face Count", AnsiString(face_count).c_str()); - PHelper().CreateCaption (items, "Vertex Count", AnsiString(vertex_count).c_str()); + PHelper().CreateCaption(items, "Face Count", AnsiString(face_count).c_str()); + PHelper().CreateCaption(items, "Vertex Count", AnsiString(vertex_count).c_str()); } + //------------------------------------------------------------------------------ -void EObjectThumbnail::FillInfo(PropItemVec& items) +void EObjectThumbnail::FillInfo(PropItemVec &items) { - PHelper().CreateCaption (items, "Face Count", AnsiString(face_count).c_str()); - PHelper().CreateCaption (items, "Vertex Count", AnsiString(vertex_count).c_str()); + PHelper().CreateCaption(items, "Face Count", AnsiString(face_count).c_str()); + PHelper().CreateCaption(items, "Vertex Count", AnsiString(vertex_count).c_str()); } + //------------------------------------------------------------------------------ + diff --git a/src/editors/ECore/Editor/EThumbnailSound.cpp b/src/editors/ECore/Editor/EThumbnailSound.cpp index 92b9da685ef..03523fb6f24 100644 --- a/src/editors/ECore/Editor/EThumbnailSound.cpp +++ b/src/editors/ECore/Editor/EThumbnailSound.cpp @@ -11,164 +11,191 @@ #define THM_CHUNK_SOUNDPARAM 0x1000 #define THM_CHUNK_SOUNDPARAM2 0x1001 #define THM_CHUNK_SOUND_AI_DIST 0x1002 + //------------------------------------------------------------------------------ -ESoundThumbnail::ESoundThumbnail(LPCSTR src_name, bool bLoad):ECustomThumbnail(src_name,ETSound) +ESoundThumbnail::ESoundThumbnail(LPCSTR src_name, bool bLoad): ECustomThumbnail(src_name, ETSound) { - m_fQuality = 0.f; - m_fMinDist = 1.f; - m_fMaxDist = 300.f; - m_fMaxAIDist = 300.f; - m_fBaseVolume = 1.f; - m_uGameType = 0; - if (bLoad) Load(); + m_fQuality = 0.f; + m_fMinDist = 1.f; + m_fMaxDist = 300.f; + m_fMaxAIDist = 300.f; + m_fBaseVolume = 1.f; + m_uGameType = 0; + if (bLoad) + Load(); } + //------------------------------------------------------------------------------ -ESoundThumbnail::~ESoundThumbnail() -{ -} +ESoundThumbnail::~ESoundThumbnail() {} + //------------------------------------------------------------------------------ bool ESoundThumbnail::Load(LPCSTR src_name, LPCSTR path) { - string_path fn; - strcpy(fn,EFS.ChangeFileExt(src_name?src_name:m_Name.c_str(),".thm").c_str()); - if (path) FS.update_path(fn,path,fn); - else FS.update_path(fn,_sounds_,fn); - if (!FS.exist(fn)) return false; - - IReader* F = FS.r_open(fn); - u16 version = 0; - - R_ASSERT(F->r_chunk(THM_CHUNK_VERSION,&version)); - if( version!=THM_SOUND_VERSION ){ - Msg ("!Thumbnail: Unsupported version."); - return false; + string_path fn; + strcpy(fn, EFS.ChangeFileExt(src_name ? src_name : m_Name.c_str(), ".thm").c_str()); + if (path) + FS.update_path(fn, path, fn); + else + FS.update_path(fn, _sounds_, fn); + if (!FS.exist(fn)) + return false; + + IReader *F = FS.r_open(fn); + u16 version = 0; + + R_ASSERT(F->r_chunk(THM_CHUNK_VERSION, &version)); + if (version!=THM_SOUND_VERSION) + { + Msg("!Thumbnail: Unsupported version."); + return false; } - R_ASSERT (F->find_chunk(THM_CHUNK_TYPE)); - m_Type = THMType(F->r_u32()); - R_ASSERT (m_Type==ETSound); + R_ASSERT(F->find_chunk(THM_CHUNK_TYPE)); + m_Type = THMType(F->r_u32()); + R_ASSERT(m_Type==ETSound); - R_ASSERT (F->find_chunk(THM_CHUNK_SOUNDPARAM)); - m_fQuality = F->r_float(); - m_fMinDist = F->r_float(); - m_fMaxDist = F->r_float(); - m_uGameType = F->r_u32(); + R_ASSERT(F->find_chunk(THM_CHUNK_SOUNDPARAM)); + m_fQuality = F->r_float(); + m_fMinDist = F->r_float(); + m_fMaxDist = F->r_float(); + m_uGameType = F->r_u32(); if (F->find_chunk(THM_CHUNK_SOUNDPARAM2)) - m_fBaseVolume = F->r_float(); + m_fBaseVolume = F->r_float(); if (F->find_chunk(THM_CHUNK_SOUND_AI_DIST)) - m_fMaxAIDist= F->r_float(); + m_fMaxAIDist = F->r_float(); else - m_fMaxAIDist= m_fMaxDist; - - m_Age = FS.get_file_age(fn); + m_fMaxAIDist = m_fMaxDist; - FS.r_close (F); + m_Age = FS.get_file_age(fn); + + FS.r_close(F); return true; } + //------------------------------------------------------------------------------ void ESoundThumbnail::Save(int age, LPCSTR path) { - if (!Valid()) return; + if (!Valid()) + return; CMemoryWriter F; - F.open_chunk (THM_CHUNK_VERSION); - F.w_u16 (THM_SOUND_VERSION); - F.close_chunk (); - - F.open_chunk (THM_CHUNK_TYPE); - F.w_u32 (m_Type); - F.close_chunk (); - - F.open_chunk (THM_CHUNK_SOUNDPARAM); - F.w_float (m_fQuality); - F.w_float (m_fMinDist); - F.w_float (m_fMaxDist); - F.w_u32 (m_uGameType); - F.close_chunk (); - - F.open_chunk (THM_CHUNK_SOUNDPARAM2); - F.w_float (m_fBaseVolume); - F.close_chunk (); - - F.open_chunk (THM_CHUNK_SOUND_AI_DIST); - F.w_float (m_fMaxAIDist); - F.close_chunk (); - - string_path fn; - if (path) FS.update_path(fn,path,m_Name.c_str()); - else FS.update_path(fn,_sounds_,m_Name.c_str()); + F.open_chunk(THM_CHUNK_VERSION); + F.w_u16(THM_SOUND_VERSION); + F.close_chunk(); + + F.open_chunk(THM_CHUNK_TYPE); + F.w_u32(m_Type); + F.close_chunk(); + + F.open_chunk(THM_CHUNK_SOUNDPARAM); + F.w_float(m_fQuality); + F.w_float(m_fMinDist); + F.w_float(m_fMaxDist); + F.w_u32(m_uGameType); + F.close_chunk(); + + F.open_chunk(THM_CHUNK_SOUNDPARAM2); + F.w_float(m_fBaseVolume); + F.close_chunk(); + + F.open_chunk(THM_CHUNK_SOUND_AI_DIST); + F.w_float(m_fMaxAIDist); + F.close_chunk(); + + string_path fn; + if (path) + FS.update_path(fn, path, m_Name.c_str()); + else + FS.update_path(fn, _sounds_, m_Name.c_str()); if (F.save_to(fn)) { - FS.set_file_age (fn,age?age:m_Age); - }else{ - Log ("!Can't save thumbnail:",fn); + FS.set_file_age(fn, age ? age : m_Age); + } + else + { + Log("!Can't save thumbnail:", fn); } } + //------------------------------------------------------------------------------ #include "ai_sounds.h" -#include "PropertiesList.h" +#include "editors/xrEProps/PropertiesList.h" -bool ESoundThumbnail::OnMaxAIDistAfterEdit(PropValue* sender, float& edit_val) +bool ESoundThumbnail::OnMaxAIDistAfterEdit(PropValue *sender, float &edit_val) { - TProperties* P = sender->Owner()->Owner(); VERIFY(P); - PropItem* S = P->FindItem("Max Dist"); VERIFY(S); - FloatValue* V = dynamic_cast(S->GetFrontValue());VERIFY(V); - float max_val = V->GetValue (); - return edit_valOwner()->Owner(); + VERIFY(P); + PropItem *S = P->FindItem("Max Dist"); + VERIFY(S); + FloatValue *V = dynamic_cast(S->GetFrontValue()); + VERIFY(V); + float max_val = V->GetValue(); + return edit_val(sender);VERIFY(SV); - TProperties* P = sender->Owner()->Owner(); VERIFY(P); - PropItem* S = P->FindItem("Max AI Dist"); VERIFY(S); - bool bChanged = false; - for (PropItem::PropValueIt it=S->Values().begin(); S->Values().end() != it; ++it){ - FloatValue* CV = dynamic_cast(*it);VERIFY(CV); - CV->lim_mx = *SV->value; - if (*CV->value>CV->lim_mx){ - ELog.DlgMsg (mtInformation,"'Max AI Dist' <= 'Max Dist'. 'Max AI Dist' will be clamped."); - bChanged = true; - *CV->value = CV->lim_mx; + FloatValue *SV = dynamic_cast(sender); + VERIFY(SV); + TProperties *P = sender->Owner()->Owner(); + VERIFY(P); + PropItem *S = P->FindItem("Max AI Dist"); + VERIFY(S); + bool bChanged = false; + for (PropItem::PropValueIt it = S->Values().begin(); S->Values().end()!=it; ++it) + { + FloatValue *CV = dynamic_cast(*it); + VERIFY(CV); + CV->lim_mx = *SV->value; + if (*CV->value>CV->lim_mx) + { + ELog.DlgMsg(mtInformation, "'Max AI Dist' <= 'Max Dist'. 'Max AI Dist' will be clamped."); + bChanged = true; + *CV->value = CV->lim_mx; } if (!CV->Equal(S->Values().front())) - S->m_Flags.set(PropItem::flMixed,TRUE); + S->m_Flags.set(PropItem::flMixed, TRUE); } - if (bChanged){ - P->Modified (); - P->RefreshForm (); + if (bChanged) + { + P->Modified(); + P->RefreshForm(); } } -void ESoundThumbnail::FillProp(PropItemVec& items) -{ - FloatValue* V = 0; - PHelper().CreateFloat (items, "Quality", &m_fQuality); - PHelper().CreateFloat (items, "Min Dist", &m_fMinDist, 0.01f,1000.f); - V = PHelper().CreateFloat (items, "Max Dist", &m_fMaxDist, 0.1f,1000.f); - V->OnChangeEvent.bind (this,&ESoundThumbnail::OnMaxDistChange); - V = PHelper().CreateFloat (items, "Max AI Dist", &m_fMaxAIDist, 0.1f,1000.f); - V->OnAfterEditEvent.bind (this,&ESoundThumbnail::OnMaxAIDistAfterEdit); - PHelper().CreateFloat (items, "Base Volume", &m_fBaseVolume, 0.f,2.f); - PHelper().CreateToken32 (items, "Game Type", &m_uGameType, anomaly_type_token); +void ESoundThumbnail::FillProp(PropItemVec &items) +{ + FloatValue *V = 0; + PHelper().CreateFloat(items, "Quality", &m_fQuality); + PHelper().CreateFloat(items, "Min Dist", &m_fMinDist, 0.01f, 1000.f); + V = PHelper().CreateFloat(items, "Max Dist", &m_fMaxDist, 0.1f, 1000.f); + V->OnChangeEvent.bind(this, &ESoundThumbnail::OnMaxDistChange); + V = PHelper().CreateFloat(items, "Max AI Dist", &m_fMaxAIDist, 0.1f, 1000.f); + V->OnAfterEditEvent.bind(this, &ESoundThumbnail::OnMaxAIDistAfterEdit); + PHelper().CreateFloat(items, "Base Volume", &m_fBaseVolume, 0.f, 2.f); + PHelper().CreateToken32(items, "Game Type", &m_uGameType, anomaly_type_token); } + //------------------------------------------------------------------------------ -void ESoundThumbnail::FillInfo(PropItemVec& items) +void ESoundThumbnail::FillInfo(PropItemVec &items) { - PHelper().CreateCaption (items, "Quality", AnsiString().sprintf("%3.2f",m_fQuality).c_str()); - PHelper().CreateCaption (items, "Min Dist", AnsiString().sprintf("%3.2f",m_fMinDist).c_str()); - PHelper().CreateCaption (items, "Max Dist", AnsiString().sprintf("%3.2f",m_fMaxDist).c_str()); - PHelper().CreateCaption (items, "Max AI Dist", AnsiString().sprintf("%3.2f",m_fMaxAIDist).c_str()); - PHelper().CreateCaption (items, "Base Volume", AnsiString().sprintf("%3.2f",m_fBaseVolume).c_str()); - PHelper().CreateCaption (items, "Game Type", get_token_name(anomaly_type_token,m_uGameType)); + PHelper().CreateCaption(items, "Quality", AnsiString().sprintf("%3.2f", m_fQuality).c_str()); + PHelper().CreateCaption(items, "Min Dist", AnsiString().sprintf("%3.2f", m_fMinDist).c_str()); + PHelper().CreateCaption(items, "Max Dist", AnsiString().sprintf("%3.2f", m_fMaxDist).c_str()); + PHelper().CreateCaption(items, "Max AI Dist", AnsiString().sprintf("%3.2f", m_fMaxAIDist).c_str()); + PHelper().CreateCaption(items, "Base Volume", AnsiString().sprintf("%3.2f", m_fBaseVolume).c_str()); + PHelper().CreateCaption(items, "Game Type", get_token_name(anomaly_type_token, m_uGameType)); } + //------------------------------------------------------------------------------ + diff --git a/src/editors/ECore/Editor/EThumbnailTexture.cpp b/src/editors/ECore/Editor/EThumbnailTexture.cpp index 47f5aa11329..50805b8632c 100644 --- a/src/editors/ECore/Editor/EThumbnailTexture.cpp +++ b/src/editors/ECore/Editor/EThumbnailTexture.cpp @@ -3,215 +3,233 @@ #include "EThumbnail.h" #ifndef XR_EPROPS_EXPORTS - #include "ImageManager.h" +#include "ImageManager.h" #endif #pragma package(smart_init) //------------------------------------------------------------------------------ #define THM_TEXTURE_VERSION 0x0012 + //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -ETextureThumbnail::ETextureThumbnail(LPCSTR src_name, bool bLoad):EImageThumbnail(src_name,ETTexture) +ETextureThumbnail::ETextureThumbnail(LPCSTR src_name, bool bLoad): EImageThumbnail(src_name, ETTexture) { - if(!strchr(src_name,'\\')) + if (!strchr(src_name, '\\')) { - xr_string _name = src_name; - ImageLib.UpdateFileName (_name); - m_Name = _name.c_str(); - m_Name = ChangeFileExt(m_Name,".thm"); - } - m_bValid = false; + xr_string _name = src_name; + ImageLib.UpdateFileName(_name); + m_Name = _name.c_str(); + m_Name = ChangeFileExt(m_Name, ".thm"); + } + m_bValid = false; if (bLoad) #ifdef XR_EPROPS_EXPORTS Load(); #else - if (!Load()) - { - ImageLib.CreateTextureThumbnail(this,src_name); - } + if (!Load()) + { + ImageLib.CreateTextureThumbnail(this, src_name); + } #endif } + //------------------------------------------------------------------------------ ETextureThumbnail::~ETextureThumbnail() { - m_Pixels.clear(); + m_Pixels.clear(); } + //------------------------------------------------------------------------------ int ETextureThumbnail::MemoryUsage() { - int mem_usage = _Width()*_Height()*4; - switch (m_TexParams.fmt){ - case STextureParams::tfDXT1: - case STextureParams::tfADXT1: mem_usage/=6; break; - case STextureParams::tfDXT3: - case STextureParams::tfDXT5: mem_usage/=4; break; - case STextureParams::tf4444: - case STextureParams::tf1555: - case STextureParams::tf565: mem_usage/=2; break; - case STextureParams::tfRGBA: break; + int mem_usage = _Width()*_Height()*4; + switch (m_TexParams.fmt) + { + case STextureParams::tfDXT1: + case STextureParams::tfADXT1: mem_usage /= 6; + break; + case STextureParams::tfDXT3: + case STextureParams::tfDXT5: mem_usage /= 4; + break; + case STextureParams::tf4444: + case STextureParams::tf1555: + case STextureParams::tf565: mem_usage /= 2; + break; + case STextureParams::tfRGBA: break; } string_path fn; - FS.update_path (fn,_game_textures_,EFS.ChangeFileExt(m_Name.c_str(),".seq").c_str()); + FS.update_path(fn, _game_textures_, EFS.ChangeFileExt(m_Name.c_str(), ".seq").c_str()); if (FS.exist(fn)) { - string128 buffer; - IReader* F = FS.r_open(0,fn); - F->r_string (buffer,sizeof(buffer)); + string128 buffer; + IReader *F = FS.r_open(0, fn); + F->r_string(buffer, sizeof(buffer)); int cnt = 0; - while (!F->eof()){ - F->r_string(buffer,sizeof(buffer)); + while (!F->eof()) + { + F->r_string(buffer, sizeof(buffer)); cnt++; } - FS.r_close (F); - mem_usage *= cnt?cnt:1; + FS.r_close(F); + mem_usage *= cnt ? cnt : 1; } return mem_usage; } + //------------------------------------------------------------------------------ -void ETextureThumbnail::CreateFromData(u32* p, u32 w, u32 h) +void ETextureThumbnail::CreateFromData(u32 *p, u32 w, u32 h) { - EImageThumbnail::CreatePixels(p, w, h); + EImageThumbnail::CreatePixels(p, w, h); m_TexParams.width = w; - m_TexParams.height= h; - m_TexParams.flags.set(STextureParams::flHasAlpha,FALSE); + m_TexParams.height = h; + m_TexParams.flags.set(STextureParams::flHasAlpha, FALSE); } + //------------------------------------------------------------------------------ -bool Surface_Load(LPCSTR full_name, U32Vec& data, u32& w, u32& h, u32& a); +bool Surface_Load(LPCSTR full_name, U32Vec &data, u32 &w, u32 &h, u32 &a); bool ETextureThumbnail::Load(LPCSTR src_name, LPCSTR path) { string_path fn; - strcpy(fn,EFS.ChangeFileExt(src_name?src_name:m_Name.c_str(),".thm").c_str() ); + strcpy(fn, EFS.ChangeFileExt(src_name ? src_name : m_Name.c_str(), ".thm").c_str()); if (path) - FS.update_path(fn,path,fn); + FS.update_path(fn, path, fn); else { - FS.update_path (fn,_game_textures_,fn); + FS.update_path(fn, _game_textures_, fn); } - if (!FS.exist(fn)) return false; + if (!FS.exist(fn)) + return false; - IReader* F = FS.r_open(fn); - u16 version = 0; + IReader *F = FS.r_open(fn); + u16 version = 0; - R_ASSERT(F->r_chunk(THM_CHUNK_VERSION,&version)); - if( version!=THM_TEXTURE_VERSION ){ - Msg ("!Thumbnail: Unsupported version."); - return false; + R_ASSERT(F->r_chunk(THM_CHUNK_VERSION, &version)); + if (version!=THM_TEXTURE_VERSION) + { + Msg("!Thumbnail: Unsupported version."); + return false; } -/* - IReader* D = F->open_chunk(THM_CHUNK_DATA); R_ASSERT(D); - m_Pixels.resize (THUMB_SIZE); - D->r (m_Pixels.begin(),THUMB_SIZE*sizeof(u32)); - D->close (); -*/ + /* + IReader* D = F->open_chunk(THM_CHUNK_DATA); R_ASSERT(D); + m_Pixels.resize (THUMB_SIZE); + D->r (m_Pixels.begin(),THUMB_SIZE*sizeof(u32)); + D->close (); + */ - R_ASSERT (F->find_chunk(THM_CHUNK_TYPE)); - m_Type = THMType(F->r_u32()); - R_ASSERT (m_Type==ETTexture); + R_ASSERT(F->find_chunk(THM_CHUNK_TYPE)); + m_Type = THMType(F->r_u32()); + R_ASSERT(m_Type==ETTexture); m_TexParams.Load(*F); - m_Age = FS.get_file_age(fn); + m_Age = FS.get_file_age(fn); - FS.r_close (F); - SetValid (); + FS.r_close(F); + SetValid(); return true; } + //------------------------------------------------------------------------------ void ETextureThumbnail::Save(int age, LPCSTR path) { - if (!Valid()) return; + if (!Valid()) + return; CMemoryWriter F; - F.open_chunk (THM_CHUNK_VERSION); - F.w_u16 (THM_TEXTURE_VERSION); - F.close_chunk (); + F.open_chunk(THM_CHUNK_VERSION); + F.w_u16(THM_TEXTURE_VERSION); + F.close_chunk(); -/* - F.w_chunk (THM_CHUNK_DATA | CFS_CompressMark,m_Pixels.begin(),m_Pixels.size()*sizeof(u32)); -*/ + /* + F.w_chunk (THM_CHUNK_DATA | CFS_CompressMark,m_Pixels.begin(),m_Pixels.size()*sizeof(u32)); + */ - F.open_chunk (THM_CHUNK_TYPE); - F.w_u32 (m_Type); - F.close_chunk (); + F.open_chunk(THM_CHUNK_TYPE); + F.w_u32(m_Type); + F.close_chunk(); - m_TexParams.Save(F); + m_TexParams.Save(F); - string_path fn; + string_path fn; if (path) FS.update_path(fn, path, m_Name.c_str()); else - FS.update_path(fn, _game_textures_, m_Name.c_str()); + FS.update_path(fn, _game_textures_, m_Name.c_str()); if (F.save_to(fn)) { - FS.set_file_age (fn,age?age:m_Age); - }else{ - Log ("!Can't save thumbnail:",fn); + FS.set_file_age(fn, age ? age : m_Age); + } + else + { + Log("!Can't save thumbnail:", fn); } } + //------------------------------------------------------------------------------ -void ETextureThumbnail::FillProp(PropItemVec& items, PropValue::TOnChange on_type_change) +void ETextureThumbnail::FillProp(PropItemVec &items, PropValue::TOnChange on_type_change) { - m_TexParams.FillProp (m_SrcName.c_str(),items,on_type_change); + m_TexParams.FillProp(m_SrcName.c_str(), items, on_type_change); } + //------------------------------------------------------------------------------ -void ETextureThumbnail::FillInfo(PropItemVec& items) -{ - STextureParams& F = m_TexParams; - PHelper().CreateCaption (items, "Format", get_token_name(tfmt_token,F.fmt)); - PHelper().CreateCaption (items, "Type", get_token_name(ttype_token,F.type)); - PHelper().CreateCaption (items, "Width", shared_str().printf("%d",_Width())); - PHelper().CreateCaption (items, "Height", shared_str().printf("%d",_Height())); - PHelper().CreateCaption (items, "Alpha", _Alpha()?"on":"off"); +void ETextureThumbnail::FillInfo(PropItemVec &items) +{ + STextureParams &F = m_TexParams; + PHelper().CreateCaption(items, "Format", get_token_name(tfmt_token, F.fmt)); + PHelper().CreateCaption(items, "Type", get_token_name(ttype_token, F.type)); + PHelper().CreateCaption(items, "Width", shared_str().printf("%d", _Width())); + PHelper().CreateCaption(items, "Height", shared_str().printf("%d", _Height())); + PHelper().CreateCaption(items, "Alpha", _Alpha() ? "on" : "off"); } -BOOL ETextureThumbnail::similar(ETextureThumbnail* thm1, xr_vector& sel_params) +BOOL ETextureThumbnail::similar(ETextureThumbnail *thm1, xr_vector &sel_params) { - BOOL res = m_TexParams.similar(thm1->m_TexParams, sel_params); - /* - if(res) - { - xr_vector::iterator it = sel_params.begin(); - xr_vector::iterator it_e = sel_params.end(); - - for(;it!=it_e;++it) - { - const AnsiString& par_name = *it; - if(par_name=="Format") - { - res = (m_TexParams.fmt == thm1->m_TexParams.fmt); - }else - if(par_name=="Type") - { - res = (m_TexParams.type == thm1->m_TexParams.type); - }else - if(par_name=="Width") - { - res = (_Width()==thm1->_Width()); - }else - if(par_name=="Height") - { - res = (_Height()==thm1->_Height()); - }else - if(par_name=="Alpha") - { - res = (_Alpha()==thm1->_Alpha()); - } - if(!res) - break; - } - } -*/ + BOOL res = m_TexParams.similar(thm1->m_TexParams, sel_params); + /* + if(res) + { + xr_vector::iterator it = sel_params.begin(); + xr_vector::iterator it_e = sel_params.end(); + + for(;it!=it_e;++it) + { + const AnsiString& par_name = *it; + if(par_name=="Format") + { + res = (m_TexParams.fmt == thm1->m_TexParams.fmt); + }else + if(par_name=="Type") + { + res = (m_TexParams.type == thm1->m_TexParams.type); + }else + if(par_name=="Width") + { + res = (_Width()==thm1->_Width()); + }else + if(par_name=="Height") + { + res = (_Height()==thm1->_Height()); + }else + if(par_name=="Alpha") + { + res = (_Alpha()==thm1->_Alpha()); + } + if(!res) + break; + } + } + */ return res; } @@ -219,55 +237,58 @@ LPCSTR ETextureThumbnail::FormatString() { return m_TexParams.FormatString(); } + //------------------------------------------------------------------------------ -void ETextureThumbnail::Draw(HDC hdc, const Irect& R) +void ETextureThumbnail::Draw(HDC hdc, const Irect &R) { - if(0==m_Pixels.size()) - { - u32 image_w, image_h, image_a; - xr_string fn_img = EFS.ChangeFileExt(m_Name.c_str(),".tga"); + if (0==m_Pixels.size()) + { + u32 image_w, image_h, image_a; + xr_string fn_img = EFS.ChangeFileExt(m_Name.c_str(), ".tga"); string_path fn; - FS.update_path (fn,_textures_,fn_img.c_str()); + FS.update_path(fn, _textures_, fn_img.c_str()); - if( !FS.exist(fn) ) + if (!FS.exist(fn)) { - fn_img = EFS.ChangeFileExt(m_Name.c_str(),".dds"); - FS.update_path(fn,_game_textures_,fn_img.c_str()); + fn_img = EFS.ChangeFileExt(m_Name.c_str(), ".dds"); + FS.update_path(fn, _game_textures_, fn_img.c_str()); - if( !FS.exist( fn ) ) - { - ELog.Msg(mtError,"Can't make preview for texture '%s'.",m_Name.c_str()); - return; - } + if (!FS.exist(fn)) + { + ELog.Msg(mtError, "Can't make preview for texture '%s'.", m_Name.c_str()); + return; + } } U32Vec data; u32 w, h, a; - if (!Surface_Load(fn,data,image_w,image_h,image_a)) + if (!Surface_Load(fn, data, image_w, image_h, image_a)) { - ELog.Msg(mtError,"Can't make preview for texture '%s'.",m_Name.c_str()); - return; + ELog.Msg(mtError, "Can't make preview for texture '%s'.", m_Name.c_str()); + return; } - ImageLib.MakeThumbnailImage(this,data.begin(),image_w,image_h,image_a); - } + ImageLib.MakeThumbnailImage(this, data.begin(), image_w, image_h, image_a); + } - if (Valid()) - { + if (Valid()) + { Irect r; - r.x1 = R.x1+1; + r.x1 = R.x1+1; r.y1 = R.y1+1; - r.x2 = R.x2-1; + r.x2 = R.x2-1; r.y2 = R.y2-1; - if (_Width()!=_Height()) FHelper.FillRect(hdc,r,0x00000000); + if (_Width()!=_Height()) + FHelper.FillRect(hdc, r, 0x00000000); if (_Width()>_Height()) { - r.y2 -= r.height()-iFloor(r.height()*float(_Height())/float(_Width())); - }else + r.y2 -= r.height()-iFloor(r.height()*float(_Height())/float(_Width())); + } + else { - r.x2 -= r.width()-iFloor(r.width()*float(_Width())/float(_Height())); + r.x2 -= r.width()-iFloor(r.width()*float(_Width())/float(_Height())); } - inherited::Draw(hdc,r); + inherited::Draw(hdc, r); } } diff --git a/src/editors/ECore/Editor/EditMesh.cpp b/src/editors/ECore/Editor/EditMesh.cpp index 646a49e4265..048fe25f60a 100644 --- a/src/editors/ECore/Editor/EditMesh.cpp +++ b/src/editors/ECore/Editor/EditMesh.cpp @@ -7,12 +7,13 @@ #include "utils/xrLC_Light/itterate_adjacents.h" #include "itterate_adjacents_dynamic.h" #ifdef _EDITOR -#include "ETools.h" +#include "utils/ETools/ETools.h" #include "UI_ToolsCustom.h" #endif -CEditableMesh::~CEditableMesh(){ - Clear(); +CEditableMesh::~CEditableMesh() +{ + Clear(); #ifdef _EDITOR R_ASSERT2(0==m_RenderBuffers,"Render buffer still referenced."); #endif @@ -20,141 +21,164 @@ CEditableMesh::~CEditableMesh(){ void CEditableMesh::Construct() { - m_Box.set (0,0,0,0,0,0); - m_Flags.assign (flVisible); - m_Name = ""; + m_Box.set(0, 0, 0, 0, 0, 0); + m_Flags.assign(flVisible); + m_Name = ""; #ifdef _EDITOR m_CFModel = 0; #endif - m_Vertices = 0; - m_SmoothGroups = 0; - m_Adjs = 0; - m_Faces = 0; - m_FaceNormals = 0; - m_VertexNormals = 0; - m_SVertices = 0; - m_SVertInfl = 0; + m_Vertices = 0; + m_SmoothGroups = 0; + m_Adjs = 0; + m_Faces = 0; + m_FaceNormals = 0; + m_VertexNormals = 0; + m_SVertices = 0; + m_SVertInfl = 0; #ifdef _EDITOR m_RenderBuffers = 0; #endif - m_FNormalsRefs = 0; - m_VNormalsRefs = 0; - m_AdjsRefs = 0; - m_SVertRefs = 0; + m_FNormalsRefs = 0; + m_VNormalsRefs = 0; + m_AdjsRefs = 0; + m_SVertRefs = 0; } -void CEditableMesh::Clear() +void CEditableMesh::Clear() { #ifdef _EDITOR UnloadRenderBuffers (); #endif - UnloadAdjacency (); - UnloadCForm (); - UnloadFNormals (); - UnloadVNormals (); - UnloadSVertices (); - - VERIFY (m_FNormalsRefs==0 && m_VNormalsRefs==0 && m_AdjsRefs==0 && m_SVertRefs==0); - - xr_free (m_Vertices); - xr_free (m_Faces); - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) - xr_delete (*vm_it); - m_VMaps.clear (); - m_SurfFaces.clear (); - for (VMRefsIt ref_it=m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++) - xr_free (ref_it->pts); - m_VMRefs.clear (); + UnloadAdjacency(); + UnloadCForm(); + UnloadFNormals(); + UnloadVNormals(); + UnloadSVertices(); + + VERIFY(m_FNormalsRefs==0&&m_VNormalsRefs==0&&m_AdjsRefs==0&&m_SVertRefs==0); + + xr_free(m_Vertices); + xr_free(m_Faces); + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + xr_delete(*vm_it); + m_VMaps.clear(); + m_SurfFaces.clear(); + for (VMRefsIt ref_it = m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++) + xr_free(ref_it->pts); + m_VMRefs.clear(); } -void CEditableMesh::UnloadCForm () +void CEditableMesh::UnloadCForm() { #ifdef _EDITOR ETOOLS::destroy_model (m_CFModel); #endif } -void CEditableMesh::UnloadFNormals (bool force) +void CEditableMesh::UnloadFNormals(bool force) { - m_FNormalsRefs--; - if (force||m_FNormalsRefs<=0) { xr_free(m_FaceNormals); m_FNormalsRefs=0; } + m_FNormalsRefs--; + if (force||m_FNormalsRefs<=0) + { + xr_free(m_FaceNormals); + m_FNormalsRefs = 0; + } } -void CEditableMesh::UnloadVNormals (bool force) + +void CEditableMesh::UnloadVNormals(bool force) { - m_VNormalsRefs--; - if (force||m_VNormalsRefs<=0) { xr_free(m_VertexNormals); m_VNormalsRefs=0; } + m_VNormalsRefs--; + if (force||m_VNormalsRefs<=0) + { + xr_free(m_VertexNormals); + m_VNormalsRefs = 0; + } } -void CEditableMesh::UnloadSVertices (bool force) + +void CEditableMesh::UnloadSVertices(bool force) { - m_SVertRefs--; - if (force||m_SVertRefs<=0) { xr_free(m_SVertices); m_SVertRefs=0; } + m_SVertRefs--; + if (force||m_SVertRefs<=0) + { + xr_free(m_SVertices); + m_SVertRefs = 0; + } } -void CEditableMesh::UnloadAdjacency (bool force) + +void CEditableMesh::UnloadAdjacency(bool force) { - m_AdjsRefs--; - if (force||m_AdjsRefs<=0) { xr_delete(m_Adjs); m_AdjsRefs=0; } + m_AdjsRefs--; + if (force||m_AdjsRefs<=0) + { + xr_delete(m_Adjs); + m_AdjsRefs = 0; + } } void CEditableMesh::RecomputeBBox() { - if( 0==m_VertCount ){ - m_Box.set(0,0,0, 0,0,0); - return; + if (0==m_VertCount) + { + m_Box.set(0, 0, 0, 0, 0, 0); + return; } - m_Box.set( m_Vertices[0], m_Vertices[0] ); - for(u32 k=1; k(m_FaceCount); + m_FNormalsRefs++; + if (m_FaceNormals) + return; + m_FaceNormals = xr_alloc(m_FaceCount); // face normals - for (u32 k=0; k(m_FaceCount*3); - - // gen req - GenerateFNormals (); - GenerateAdjacency (); - - for (u32 f_i=0; f_i > iterate_adj ; - iterate_adj::recurse_tri_params p( N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount ); - iterate_adj::RecurseTri( face_adj_it - a_lst.begin(), p ); - float len = N.magnitude(); - if (len>EPS_S) - { - N.div (len); - }else - { -//. Msg ("!Invalid smooth group found (Maya type). Object: '%s'. Vertex: [%3.2f, %3.2f, %3.2f]",m_Parent->GetName(),VPUSH(m_Vertices[m_Faces[f_i].pv[k].pindex])); + m_VNormalsRefs++; + if (m_VertexNormals) + return; + m_VertexNormals = xr_alloc(m_FaceCount*3); + + // gen req + GenerateFNormals(); + GenerateAdjacency(); + + for (u32 f_i = 0; f_i> iterate_adj; + iterate_adj::recurse_tri_params p(N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount); + iterate_adj::RecurseTri(face_adj_it-a_lst.begin(), p); + float len = N.magnitude(); + if (len>EPS_S) + { + N.div(len); + } + else + { + //. Msg ("!Invalid smooth group found (Maya type). Object: '%s'. Vertex: [%3.2f, %3.2f, %3.2f]",m_Parent->GetName(),VPUSH(m_Vertices[m_Faces[f_i].pv[k].pindex])); #ifdef _EDITOR if(parent_xform) @@ -165,342 +189,370 @@ void CEditableMesh::GenerateVNormals(const Fmatrix* parent_xform) } #endif - N.set (m_FaceNormals[a_lst.front()]); - } - } - } + N.set(m_FaceNormals[a_lst.front()]); + } + } + } - UnloadFNormals (); - UnloadAdjacency (); + UnloadFNormals(); + UnloadAdjacency(); } + /* void CEditableMesh::GenerateVNormals(const Fmatrix* parent_xform) { - m_VNormalsRefs++; + m_VNormalsRefs++; if (m_VertexNormals) return; - m_VertexNormals = xr_alloc(m_FaceCount*3); - - // gen req - GenerateFNormals (); - GenerateAdjacency (); - - // vertex normals - if (m_Flags.is(flSGMask)) - { - for (u32 f_i=0; f_i(m_FaceCount*3); + + // gen req + GenerateFNormals (); + GenerateAdjacency (); + + // vertex normals + if (m_Flags.is(flSGMask)) + { + for (u32 f_i=0; f_i > iterate_adj ; - iterate_adj::recurse_tri_params p( N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount ); - iterate_adj::RecurseTri( 0, p ); + typedef itterate_adjacents< itterate_adjacents_params_dynamic > iterate_adj ; + iterate_adj::recurse_tri_params p( N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount ); + iterate_adj::RecurseTri( 0, p ); // - if (sg) - { - N.set (0,0,0); - - VERIFY(a_lst.size()); - for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) - if (sg&m_SmoothGroups[*i_it]) - N.add (m_FaceNormals[*i_it]); + if (sg) + { + N.set (0,0,0); + + VERIFY(a_lst.size()); + for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) + if (sg&m_SmoothGroups[*i_it]) + N.add (m_FaceNormals[*i_it]); float len = N.magnitude(); if (len>EPS_S) - { - N.div (len); + { + N.div (len); }else - { + { //. Msg ("!Invalid smooth group found (MAX type). Object: '%s'. Vertex: [%3.2f, %3.2f, %3.2f]",m_Parent->GetName(),VPUSH(m_Vertices[m_Faces[f_i].pv[k].pindex])); #ifdef _EDITOR - Fvector p0; + Fvector p0; p0 = m_Vertices[m_Faces[f_i].pv[k].pindex]; Tools->m_DebugDraw.AppendPoint(p0, 0xffff0000, true, true, "invalid vNORMAL"); #endif N.set (m_FaceNormals[a_lst.front()]); } - }else - { - N.set (FN); - } - } - } - }else{ - for (u32 f_i=0; f_i > iterate_adj ; - iterate_adj::recurse_tri_params p( N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount ); - iterate_adj::RecurseTri( 0, p ); + typedef itterate_adjacents< itterate_adjacents_params_dynamic > iterate_adj ; + iterate_adj::recurse_tri_params p( N, m_SmoothGroups, m_FaceNormals, a_lst, m_Faces, m_FaceCount ); + iterate_adj::RecurseTri( 0, p ); // - VERIFY (a_lst.size()); - for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) - { - if (sg != m_SmoothGroups[*i_it]) - continue; - N.add (m_FaceNormals[*i_it]); - } + VERIFY (a_lst.size()); + for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) + { + if (sg != m_SmoothGroups[*i_it]) + continue; + N.add (m_FaceNormals[*i_it]); + } float len = N.magnitude(); if (len>EPS_S) - { - N.div (len); + { + N.div (len); }else - { + { //. Msg ("!Invalid smooth group found (Maya type). Object: '%s'. Vertex: [%3.2f, %3.2f, %3.2f]",m_Parent->GetName(),VPUSH(m_Vertices[m_Faces[f_i].pv[k].pindex])); #ifdef _EDITOR - if(parent_xform) + if(parent_xform) { - Fvector p0; - parent_xform->transform_tiny(p0, m_Vertices[m_Faces[f_i].pv[k].pindex]); + Fvector p0; + parent_xform->transform_tiny(p0, m_Vertices[m_Faces[f_i].pv[k].pindex]); Tools->m_DebugDraw.AppendPoint(p0, 0xffff0000, true, true, "invalid vNORMAL"); } #endif N.set (m_FaceNormals[a_lst.front()]); } - } - else - { - N.set (FN); + } + else + { + N.set (FN); - //IntVec& a_lst=(*m_Adjs)[m_Faces[f_i].pv[k].pindex]; - //VERIFY(a_lst.size()); - //for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) - // N.add (m_FNormals[*i_it]); + //IntVec& a_lst=(*m_Adjs)[m_Faces[f_i].pv[k].pindex]; + //VERIFY(a_lst.size()); + //for (IntIt i_it=a_lst.begin(); i_it!=a_lst.end(); i_it++) + // N.add (m_FNormals[*i_it]); // float len = N.magnitude(); // if (len>EPS_S){ - // N.div (len); + // N.div (len); // }else{ // Msg ("!Invalid smooth group found (No smooth). Object: '%s'. Vertex: [%3.2f, %3.2f, %3.2f]",m_Parent->GetName(),VPUSH(m_Verts[m_Faces[f_i].pv[k].pindex])); // N.set (m_FNormals[a_lst.front()]); // } - } - } - } - } + } + } + } + } UnloadFNormals (); UnloadAdjacency (); } */ void CEditableMesh::GenerateSVertices(u32 influence) { - if (!m_Parent->IsSkeleton())return; + if (!m_Parent->IsSkeleton()) + return; m_SVertRefs++; - if (m_SVertInfl!=influence) UnloadSVertices(true); - if (m_SVertices) return; - m_SVertices = xr_alloc(m_FaceCount*3); - m_SVertInfl = influence; - -// CSMotion* active_motion=m_Parent->ResetSAnimation(); + if (m_SVertInfl!=influence) + UnloadSVertices(true); + if (m_SVertices) + return; + m_SVertices = xr_alloc(m_FaceCount*3); + m_SVertInfl = influence; + + // CSMotion* active_motion=m_Parent->ResetSAnimation(); m_Parent->CalculateAnimation(0); // generate normals - GenerateFNormals (); - GenerateVNormals (0); + GenerateFNormals(); + GenerateVNormals(0); - for (u32 f_id=0; f_idGetBoneIndexByWMap(VM.name.c_str()),VM.getW(vmpt_lst.pts[vmpt_id].index))); + wb.push_back(st_WB(m_Parent->GetBoneIndexByWMap(VM.name.c_str()), VM.getW(vmpt_lst.pts[vmpt_id].index))); if (wb.back().bone==BI_NONE) { - ELog.DlgMsg (mtError,"Can't find bone assigned to weight map %s",*VM.name); - FATAL ("Editor crashed."); + ELog.DlgMsg(mtError, "Can't find bone assigned to weight map %s", *VM.name); + FATAL("Editor crashed."); return; } - }else if(VM.type==vmtUV) - SV.uv.set (VM.getUV(vmpt_lst.pts[vmpt_id].index)); + } + else if (VM.type==vmtUV) + SV.uv.set(VM.getUV(vmpt_lst.pts[vmpt_id].index)); } VERIFY(m_SVertInfl<=4); - + wb.prepare_weights(m_SVertInfl); - SV.offs = P; - SV.norm = N; + SV.offs = P; + SV.norm = N; SV.bones.resize(wb.size()); - for (u8 k=0; k<(u8)SV.bones.size(); k++) - { - SV.bones[k].id = wb[k].bone; - SV.bones[k].w = wb[k].weight; - } + for (u8 k = 0; k<(u8)SV.bones.size(); k++) + { + SV.bones[k].id = wb[k].bone; + SV.bones[k].w = wb[k].weight; + } } - } + } // restore active motion - UnloadFNormals (); - UnloadVNormals (); + UnloadFNormals(); + UnloadVNormals(); } void CEditableMesh::GenerateAdjacency() { - m_AdjsRefs++; - if (m_Adjs) return; - m_Adjs = xr_new(); - VERIFY (m_Faces); - m_Adjs->resize (m_VertCount); -//. Log (".. Update adjacency"); - for (u32 f_id=0; f_id(); + VERIFY(m_Faces); + m_Adjs->resize(m_VertCount); + //. Log (".. Update adjacency"); + for (u32 f_id = 0; f_idsecond; - IntIt f_it = std::lower_bound(face_lst.begin(),face_lst.end(),(int)fid); - if ((f_it!=face_lst.end())&&(*f_it==(int)fid)) return sp_it->first; -//. if (std::find(face_lst.begin(),face_lst.end(),fid)!=face_lst.end()) return sp_it->first; - } + R_ASSERT(fidsecond; + IntIt f_it = std::lower_bound(face_lst.begin(), face_lst.end(), (int)fid); + if ((f_it!=face_lst.end())&&(*f_it==(int)fid)) + return sp_it->first; + //. if (std::find(face_lst.begin(),face_lst.end(),fid)!=face_lst.end()) return sp_it->first; + } return 0; } -void CEditableMesh::GetFaceTC(u32 fid, const Fvector2* tc[3]) +void CEditableMesh::GetFaceTC(u32 fid, const Fvector2 *tc[3]) { - R_ASSERT(fidgetUV(vmr.index)); + R_ASSERT(fidgetUV(vmr.index)); } } -void CEditableMesh::GetFacePT(u32 fid, const Fvector* pt[3]) +void CEditableMesh::GetFacePT(u32 fid, const Fvector *pt[3]) { - R_ASSERT(fidfirst; - if(S->m_GameMtlName=="materials\\occ" && bIgnoreOCC) - continue; - - if (bMatch2Sided){ - if (S->m_Flags.is(CSurface::sf2Sided)) - f_cnt+=sp_it->second.size()*2; - else - f_cnt+=sp_it->second.size(); - }else{ - f_cnt+=sp_it->second.size(); + CSurface*S = sp_it->first; + if (S->m_GameMtlName=="materials\\occ"&&bIgnoreOCC) + continue; + + if (bMatch2Sided) + { + if (S->m_Flags.is(CSurface::sf2Sided)) + f_cnt += sp_it->second.size()*2; + else + f_cnt += sp_it->second.size(); + } + else + { + f_cnt += sp_it->second.size(); } - } + } return f_cnt; } -float CEditableMesh::CalculateSurfaceArea(CSurface* surf, bool bMatch2Sided) +float CEditableMesh::CalculateSurfaceArea(CSurface *surf, bool bMatch2Sided) { - SurfFacesPairIt sp_it = m_SurfFaces.find(surf); - if (sp_it==m_SurfFaces.end()) return 0; - float area = 0; - IntVec& pol_lst = sp_it->second; - for (int k=0; ksecond; + for (int k = 0; kfirst->m_Flags.is(CSurface::sf2Sided)) area*=2; + if (bMatch2Sided&&sp_it->first->m_Flags.is(CSurface::sf2Sided)) + area *= 2; return area; } -float CEditableMesh::CalculateSurfacePixelArea (CSurface* surf, bool bMatch2Sided) +float CEditableMesh::CalculateSurfacePixelArea(CSurface *surf, bool bMatch2Sided) { - SurfFacesPairIt sp_it = m_SurfFaces.find(surf); - if (sp_it==m_SurfFaces.end()) return 0; - float area = 0; - IntVec& pol_lst = sp_it->second; - for (int k=0; kx,tc[1]->y,0),Fvector().set(tc[0]->x,tc[0]->y,0)); - e02.sub (Fvector().set(tc[2]->x,tc[2]->y,0),Fvector().set(tc[0]->x,tc[0]->y,0)); - area += c.crossproduct(e01,e02).magnitude()/2.f; + SurfFacesPairIt sp_it = m_SurfFaces.find(surf); + if (sp_it==m_SurfFaces.end()) + return 0; + float area = 0; + IntVec &pol_lst = sp_it->second; + for (int k = 0; kx, tc[1]->y, 0), Fvector().set(tc[0]->x, tc[0]->y, 0)); + e02.sub(Fvector().set(tc[2]->x, tc[2]->y, 0), Fvector().set(tc[0]->x, tc[0]->y, 0)); + area += c.crossproduct(e01, e02).magnitude()/2.f; } - if (bMatch2Sided&&sp_it->first->m_Flags.is(CSurface::sf2Sided)) area*=2; + if (bMatch2Sided&&sp_it->first->m_Flags.is(CSurface::sf2Sided)) + area *= 2; return area; } -int CEditableMesh::GetSurfFaceCount(CSurface* surf, bool bMatch2Sided) +int CEditableMesh::GetSurfFaceCount(CSurface *surf, bool bMatch2Sided) { - SurfFacesPairIt sp_it = m_SurfFaces.find(surf); - if (sp_it==m_SurfFaces.end()) return 0; - int f_cnt = sp_it->second.size(); - if (bMatch2Sided&&sp_it->first->m_Flags.is(CSurface::sf2Sided)) f_cnt*=2; + SurfFacesPairIt sp_it = m_SurfFaces.find(surf); + if (sp_it==m_SurfFaces.end()) + return 0; + int f_cnt = sp_it->second.size(); + if (bMatch2Sided&&sp_it->first->m_Flags.is(CSurface::sf2Sided)) + f_cnt *= 2; return f_cnt; } -void CEditableMesh::DumpAdjacency(){ - Log("Adjacency dump."); - Log("------------------------------------------------------------------------"); -/* for (u32 i=0; itype==t)&&(stricmp((*vm_it)->name.c_str(),name)==0)&&(polymap==(*vm_it)->polymap)) return vm_it-vmaps.begin(); - } - return -1; + for (VMapIt vm_it = vmaps.begin(); vm_it!=vmaps.end(); vm_it++) + { + if (((*vm_it)->type==t)&&(stricmp((*vm_it)->name.c_str(), name)==0)&&(polymap==(*vm_it)->polymap)) + return vm_it-vmaps.begin(); + } + return -1; } + //---------------------------------------------------------------------------- bool CEditableMesh::Validate() { - return true; + return true; } + //---------------------------------------------------------------------------- + diff --git a/src/editors/ECore/Editor/EditMesh.h b/src/editors/ECore/Editor/EditMesh.h index 0f195e7b5f5..fb894f22591 100644 --- a/src/editors/ECore/Editor/EditMesh.h +++ b/src/editors/ECore/Editor/EditMesh.h @@ -6,12 +6,12 @@ //---------------------------------------------------- // refs -class CSurface; -struct SRayPickInfo; +class CSurface; +struct SRayPickInfo; //struct CFrustum; -struct FSChunkDef; -class CExporter; -class CCustomObject; +struct FSChunkDef; +class CExporter; +class CCustomObject; #ifdef _EDITOR # include "pick_defs.h" @@ -20,160 +20,167 @@ class CCustomObject; #include "xrCore/Animation/Bone.hpp" #pragma pack( push,1 ) -const u8 vmtUV = 0; -const u8 vmtWeight = 1; - -struct ECORE_API st_WB{ - u16 bone; - float weight; - st_WB ():bone(BI_NONE),weight(0.f){;} - st_WB (u16 b, float w):bone(b),weight(w){;} - void set (u16 b, float w){bone=b;weight=w;} +const u8 vmtUV = 0; +const u8 vmtWeight = 1; + +struct ECORE_API st_WB{ + u16 bone; + float weight; + st_WB():bone(BI_NONE),weight(0.f){;} + st_WB(u16 b, float w):bone(b),weight(w){;} + void set(u16 b, float w){bone = b;weight = w;} }; -DEFINE_VECTOR(st_WB,WBVec,WBIt); -struct ECORE_API st_VertexWB:public WBVec{ -protected: - static bool compare_by_weight(const st_WB& a, const st_WB& b) - { - return a.weight > b.weight; // отсортировать по убыванию - } - static bool compare_by_bone(const st_WB& a, const st_WB& b) - { - return a.bone < b.bone; // отсортировать по возрастанию - } +DEFINE_VECTOR(st_WB, WBVec, WBIt); + +struct ECORE_API st_VertexWB: + +public +WBVec +{ + protected: + static bool compare_by_weight(const st_WB& a, const st_WB& b) + { + return a.weight > b.weight; // отсортировать по убыванию +} +static bool compare_by_bone(const st_WB& a, const st_WB& b) +{ + return a.bone < b.bone; // отсортировать по возрастанию +} public: - void sort_by_bone() - { - std::sort(begin(),end(),compare_by_bone); - } - void sort_by_weight() - { - std::sort(begin(),end(),compare_by_weight); - } - void prepare_weights(u32 max_influence) - { - sort_by_weight (); - // delete >max_influence weights - if (size()>max_influence) erase(begin()+max_influence,end()); - // accumulate weights - float sum_weight=0; - WBIt it; - for (it=begin(); it!=end(); it++) sum_weight+=it->weight; - // normalize weights - for (it=begin(); it!=end(); it++) it->weight/=sum_weight; -// sort_by_bone (); // need only for export (before add vertex sort_by_bone) - } +void sort_by_bone() +{ + std::sort(begin(),end(),compare_by_bone); +} +void sort_by_weight() +{ + std::sort(begin(),end(),compare_by_weight); +} +void prepare_weights(u32 max_influence) +{ + sort_by_weight (); + // delete >max_influence weights + if (size()>max_influence) erase(begin()+max_influence,end()); + // accumulate weights + float sum_weight=0; + WBIt it; + for (it=begin(); it!=end(); it++) sum_weight+=it->weight; + // normalize weights + for (it=begin(); it!=end(); it++) it->weight/=sum_weight; + // sort_by_bone (); // need only for export (before add vertex sort_by_bone) +} }; -DEFINE_VECTOR(st_VertexWB,VWBVec,VWBIt); +DEFINE_VECTOR(st_VertexWB, VWBVec, VWBIt); struct ECORE_API st_VMapPt{ - int vmap_index; // ссылка на мапу - int index; // индекс в V-мапе на uv/w - st_VMapPt(){vmap_index=-1;index=-1;} + int vmap_index; // ссылка на мапу + int index; // индекс в V-мапе на uv/w + st_VMapPt(){vmap_index = -1;index = -1;} }; // uv's class ECORE_API st_VMap{ - FloatVec vm; // u,v - координаты или weight -public: - shared_str name; // vertex uv map name + FloatVec vm; // u,v - координаты или weight + public: + shared_str name; // vertex uv map name struct{ - u8 type :2; - u8 polymap :1; - u8 dim :2; - u8 reserved:3; + u8 type:2; + u8 polymap:1; + u8 dim:2; + u8 reserved:3; }; - IntVec vindices; - IntVec pindices; -public: - st_VMap (LPCSTR nm=0, u8 t=vmtUV, bool pm=false) + IntVec vindices; + IntVec pindices; + public: + st_VMap(LPCSTR nm = 0, u8 t = vmtUV, bool pm = false) { - type = t; - polymap = pm; - name = nm; - if (t==vmtUV) dim=2; else dim=1; - } - IC const Fvector2& getUV (int idx) const {VERIFY(type==vmtUV); return (Fvector2&)vm[idx*dim];} - IC Fvector2& getUV (int idx) {VERIFY(type==vmtUV); return (Fvector2&)vm[idx*dim];} - IC const float& getW (int idx) const {VERIFY(type==vmtWeight); return vm[idx];} - IC const FloatVec& getVM () const {return vm;} - IC float* getVMdata () {return &*vm.begin();} - IC float* getVMdata (int start) {return &*(vm.begin()+start*dim);} - IC int VMdatasize () {return vm.size()*sizeof(float);} - IC int* getVIdata () {return &*vindices.begin();} - IC int VIdatasize () {return vindices.size()*sizeof(int);} - IC int* getPIdata () {return &*pindices.begin();} - IC int PIdatasize () {return pindices.size()*sizeof(int);} - IC int size () {return vm.size()/dim;} - IC void resize (int cnt) {vm.resize(cnt*dim);vindices.resize(cnt);if (polymap) pindices.resize(cnt); } - IC void appendUV (const float u, const float v) {vm.push_back(u);vm.push_back(v);} - IC void appendUV (const Fvector2& uv) {appendUV(uv.x,uv.y);} - IC void appendW (const float w) {vm.push_back(w);} - IC void appendVI (const int vi) {vindices.push_back(vi);} - IC void appendPI (const int pi) {VERIFY(polymap); pindices.push_back(pi);} - IC void copyfrom (float* src, int cnt) {resize(cnt); CopyMemory(&*vm.begin(),src,cnt*dim*4);} + type = t; + polymap = pm; + name = nm; + if (t==vmtUV) dim = 2;else dim = 1; + } + IC const Fvector2&getUV(int idx) const{VERIFY(type==vmtUV);return (Fvector2&)vm[idx*dim];} + IC Fvector2&getUV(int idx){VERIFY(type==vmtUV);return (Fvector2&)vm[idx*dim];} + IC const float& getW(int idx) const{VERIFY(type==vmtWeight);return vm[idx];} + IC const FloatVec&getVM() const{return vm;} + IC float* getVMdata(){return &*vm.begin();} + IC float* getVMdata(int start){return &*(vm.begin()+start*dim);} + IC int VMdatasize(){return vm.size()*sizeof(float);} + IC int* getVIdata(){return &*vindices.begin();} + IC int VIdatasize(){return vindices.size()*sizeof(int);} + IC int* getPIdata(){return &*pindices.begin();} + IC int PIdatasize(){return pindices.size()*sizeof(int);} + IC int size(){return vm.size()/dim;} + IC void resize(int cnt){vm.resize(cnt*dim);vindices.resize(cnt);if (polymap) pindices.resize(cnt);} + IC void appendUV(const float u, const float v){vm.push_back(u);vm.push_back(v);} + IC void appendUV(const Fvector2&uv){appendUV(uv.x, uv.y);} + IC void appendW(const float w){vm.push_back(w);} + IC void appendVI(const int vi){vindices.push_back(vi);} + IC void appendPI(const int pi){VERIFY(polymap); pindices.push_back(pi);} + IC void copyfrom(float* src, int cnt){resize(cnt); CopyMemory(&*vm.begin(), src, cnt*dim*4);} }; -struct st_VMapPtLst{ - u8 count; - st_VMapPt* pts; +struct st_VMapPtLst +{ + u8 count; + st_VMapPt *pts; }; -DEFINE_VECTOR (st_VMapPtLst,VMRefsVec,VMRefsIt); + +DEFINE_VECTOR(st_VMapPtLst, VMRefsVec, VMRefsIt); struct ECORE_API st_SVert{ - Fvector offs; - Fvector norm; - Fvector2 uv; + Fvector offs; + Fvector norm; + Fvector2 uv; struct bone{ - public: - float w; - u16 id; - bone (){w=0.f;id=BI_NONE;} - bool similar (const bone& b){return (id==b.id) && fsimilar(w,b.w,EPS_L);} + public: + float w; + u16 id; + bone(){w = 0.f;id = BI_NONE;} + bool similar(const bone&b){return (id==b.id)&&fsimilar(w, b.w, EPS_L);} }; - svector bones; + svectorbones; protected: - static bool compare_by_weight(const bone& a, const bone& b) - { - return a.w > b.w; // отсортировать по убыванию - } - static bool compare_by_bone(const bone& a, const bone& b) - { - return a.id < b.id; // отсортировать по возрастанию - } + static bool compare_by_weight(const bone&a, const bone&b) + { + return a.w>b.w; // отсортировать по убыванию + } + static bool compare_by_bone(const bone&a, const bone&b) + { + return a.id v.pindex; } - bool eq( const st_FaceVert &v ) const { return pindex == v.pindex; } + typedef st_Face type_face; + int pindex; // point index in PointList + int vmref; // vm-ref index + bool gt(const st_FaceVert&v) const{return pindex>v.pindex;} + bool eq(const st_FaceVert&v) const{return pindex==v.pindex;} }; struct ECORE_API st_Face{ - st_FaceVert pv[3]; // face vertices (P->P...) - void EdgeVerts( u8 e, st_FaceVert &v0, st_FaceVert &v1 ) const - { - VERIFY( e< 3 ); - v0 = pv[ e ]; - v1 = pv[ (e+1)%3 ]; - } + st_FaceVert pv[3]; // face vertices (P->P...) + void EdgeVerts(u8 e, st_FaceVert&v0, st_FaceVert&v1) const + { + VERIFY(e<3); + v0 = pv[e]; + v1 = pv[(e+1)%3]; + } }; // mesh options struct ECORE_API st_MeshOptions{ - int m_Reserved0; - int m_Reserved1; - st_MeshOptions (){m_Reserved0=0;m_Reserved1=0;} + int m_Reserved0; + int m_Reserved1; + st_MeshOptions(){m_Reserved0 = 0;m_Reserved1 = 0;} }; #pragma pack( pop ) -DEFINE_VECTOR (IntVec,AdjVec,AdjIt); -DEFINE_VECTOR (st_VMap*,VMapVec,VMapIt); -DEFINE_MAP (CSurface*,IntVec,SurfFaces,SurfFacesPairIt); +DEFINE_VECTOR(IntVec, AdjVec, AdjIt); +DEFINE_VECTOR(st_VMap *, VMapVec, VMapIt); +DEFINE_MAP(CSurface *, IntVec, SurfFaces, SurfFacesPairIt); //refs struct st_RenderBuffer; @@ -191,130 +198,130 @@ class CSector; DEFINE_MAP(CSurface*,RBVector,RBMap,RBMapPairIt); #endif -class ECORE_API CEditableMesh { - friend class MeshExpUtility; - friend class CEditableObject; - friend class CSectorItem; - friend class CSector; - friend class CPortalUtils; - friend class SceneBuilder; - friend class CExportSkeleton; - friend class CExportObjectOGF; - friend class TfrmEditLibrary; - friend class CExporter; - friend class CXRayObjectExport; - friend class CXRaySkinExport; - - shared_str m_Name; - - CEditableObject* m_Parent; - - void GenerateCFModel (); - void GenerateRenderBuffers(); - void UnloadCForm (); +class ECORE_API CEditableMesh{ + friendclass MeshExpUtility; + friendclass CEditableObject; + friendclass CSectorItem; + friendclass CSector; + friendclass CPortalUtils; + friendclass SceneBuilder; + friendclass CExportSkeleton; + friendclass CExportObjectOGF; + friendclass TfrmEditLibrary; + friendclass CExporter; + friendclass CXRayObjectExport; + friendclass CXRaySkinExport; + + shared_str m_Name; + + CEditableObject*m_Parent; + + void GenerateCFModel(); + void GenerateRenderBuffers(); + void UnloadCForm(); #ifdef _EDITOR void UnloadRenderBuffers (); #endif -public: - static BOOL m_bDraftMeshMode; - void GenerateFNormals (); - void GenerateVNormals (const Fmatrix* parent_xform); - void GenerateSVertices (u32 influence); - void GenerateAdjacency (); - - bool IsGeneratedSVertices(u32 influence) {return (m_SVertices && (m_SVertInfl==influence));} - - void UnloadFNormals (bool force=false); - void UnloadVNormals (bool force=false); - void UnloadSVertices (bool force=false); - void UnloadAdjacency (bool force=false); -IC Fvector* Vertices () { return m_Vertices; } // -IC st_Face* Faces () { return m_Faces; } // + some array size!!! -IC SurfFaces &Surfaces () { return m_SurfFaces; } -private: + public: + static BOOL m_bDraftMeshMode; + void GenerateFNormals(); + void GenerateVNormals(const Fmatrix*parent_xform); + void GenerateSVertices(u32 influence); + void GenerateAdjacency(); + + bool IsGeneratedSVertices(u32 influence){return (m_SVertices&&(m_SVertInfl==influence));} + + void UnloadFNormals(bool force = false); + void UnloadVNormals(bool force = false); + void UnloadSVertices(bool force = false); + void UnloadAdjacency(bool force = false); + IC Fvector*Vertices(){return m_Vertices;} // + IC st_Face*Faces(){return m_Faces;} // + some array size!!! + IC SurfFaces&Surfaces(){return m_SurfFaces;} + private: // internal variables - enum{ - flVisible = (1<<0), - flLocked = (1<<1), - flSGMask = (1<<2), - }; - Flags8 m_Flags; -public: - st_MeshOptions m_Ops; -protected: - Fbox m_Box; - - int m_FNormalsRefs; - int m_VNormalsRefs; - int m_AdjsRefs; - int m_SVertRefs; - - u32 m_SVertInfl; - - u32 m_VertCount; - u32 m_FaceCount; - - Fvector* m_Vertices; // | - AdjVec* m_Adjs; // + some array size!!! - u32* m_SmoothGroups; // | - Fvector* m_FaceNormals; // | - Fvector* m_VertexNormals; // | *3 - st_SVert* m_SVertices;// | *3 - st_Face* m_Faces; // + some array size!!! - SurfFaces m_SurfFaces; - VMapVec m_VMaps; - VMRefsVec m_VMRefs; + enum{ + flVisible = (1<<0), + flLocked = (1<<1), + flSGMask = (1<<2), + }; + Flags8 m_Flags; + public: + st_MeshOptions m_Ops; + protected: + Fbox m_Box; + + int m_FNormalsRefs; + int m_VNormalsRefs; + int m_AdjsRefs; + int m_SVertRefs; + + u32 m_SVertInfl; + + u32 m_VertCount; + u32 m_FaceCount; + + Fvector*m_Vertices; // | + AdjVec*m_Adjs; // + some array size!!! + u32*m_SmoothGroups; // | + Fvector*m_FaceNormals; // | + Fvector*m_VertexNormals; // | *3 + st_SVert*m_SVertices;// | *3 + st_Face*m_Faces; // + some array size!!! + SurfFaces m_SurfFaces; + VMapVec m_VMaps; + VMRefsVec m_VMRefs; #ifdef _EDITOR CDB::MODEL* m_CFModel; RBMap* m_RenderBuffers; #endif - void FillRenderBuffer (IntVec& face_lst, int start_face, int num_face, const CSurface* surf, LPBYTE& data); + void FillRenderBuffer(IntVec&face_lst, int start_face, int num_face, const CSurface*surf, LPBYTE&data); - void RecurseTri (int id); + void RecurseTri(int id); - // mesh optimize routine - bool OptimizeFace (st_Face& face); -public: - void RecomputeBBox (); - void OptimizeMesh (BOOL NoOpt); -public: - CEditableMesh (CEditableObject* parent){m_Parent=parent;Construct();} - CEditableMesh (CEditableMesh* source,CEditableObject* parent){m_Parent=parent;Construct();CloneFrom(source);} - virtual ~CEditableMesh (); - void Construct (); - void Clear (); - - IC void SetName (LPCSTR name){m_Name=name;} - IC shared_str Name (){return m_Name;} - void GetBox (Fbox& box){box.set(m_Box);} - CSurface* GetSurfaceByFaceID (u32 fid); - void GetFaceTC (u32 fid, const Fvector2* tc[3]); - void GetFacePT (u32 fid, const Fvector* pt[3]); - IC BOOL Visible (){return m_Flags.is(flVisible); } - IC void Show (BOOL bVisible){m_Flags.set(flVisible,bVisible);} + // mesh optimize routine + bool OptimizeFace(st_Face&face); + public: + void RecomputeBBox(); + void OptimizeMesh(BOOL NoOpt); + public: + CEditableMesh(CEditableObject*parent){m_Parent = parent;Construct();} + CEditableMesh(CEditableMesh*source, CEditableObject*parent){m_Parent = parent;Construct();CloneFrom(source);} + virtual ~CEditableMesh(); + void Construct(); + void Clear(); + + IC void SetName(LPCSTR name){m_Name = name;} + IC shared_str Name(){return m_Name;} + void GetBox(Fbox&box){box.set(m_Box);} + CSurface*GetSurfaceByFaceID(u32 fid); + void GetFaceTC(u32 fid, const Fvector2*tc[3]); + void GetFacePT(u32 fid, const Fvector*pt[3]); + IC BOOL Visible(){return m_Flags.is(flVisible);} + IC void Show(BOOL bVisible){m_Flags.set(flVisible, bVisible);} // mesh modify routine - void CloneFrom (CEditableMesh *source); - void Transform (const Fmatrix& parent); - - IC CEditableObject* Parent (){ return m_Parent; } - IC u32 GetFCount (){ return m_FaceCount; } - IC const st_Face* GetFaces (){ return m_Faces; } - IC const u32* GetSmoothGroups (){ return m_SmoothGroups; } - IC const Fvector* GetVertices (){ return m_Vertices; } - IC u32 GetVCount (){ return m_VertCount; } - IC const VMapVec& GetVMaps (){ return m_VMaps; } - IC const VMRefsVec& GetVMRefs (){ return m_VMRefs; } - IC const SurfFaces& GetSurfFaces (){ return m_SurfFaces; } - IC const Fvector* GetFNormals (){ VERIFY(0!=m_FaceNormals); return m_FaceNormals; } - IC const Fvector* GetVNormals (){ VERIFY(0!=m_VertexNormals); return m_VertexNormals; } - IC const st_SVert* GetSVertices (){ VERIFY(0!=m_SVertices);return m_SVertices; } - + void CloneFrom(CEditableMesh*source); + void Transform(const Fmatrix&parent); + + IC CEditableObject*Parent(){return m_Parent;} + IC u32 GetFCount(){return m_FaceCount;} + IC const st_Face*GetFaces(){return m_Faces;} + IC const u32*GetSmoothGroups(){return m_SmoothGroups;} + IC const Fvector*GetVertices(){return m_Vertices;} + IC u32 GetVCount(){return m_VertCount;} + IC const VMapVec&GetVMaps(){return m_VMaps;} + IC const VMRefsVec&GetVMRefs(){return m_VMRefs;} + IC const SurfFaces&GetSurfFaces(){return m_SurfFaces;} + IC const Fvector*GetFNormals(){VERIFY(0!=m_FaceNormals);return m_FaceNormals;} + IC const Fvector*GetVNormals(){VERIFY(0!=m_VertexNormals);return m_VertexNormals;} + IC const st_SVert*GetSVertices(){VERIFY(0!=m_SVertices);return m_SVertices;} + // pick routine - bool RayPick (float& dist, const Fvector& start, const Fvector& dir, const Fmatrix& inv_parent, SRayPickInfo* pinf = NULL); + bool RayPick(float& dist, const Fvector&start, const Fvector&dir, const Fmatrix&inv_parent, SRayPickInfo*pinf = NULL); #ifdef _EDITOR void RayQuery (SPickQuery& pinf); void RayQuery (const Fmatrix& parent, const Fmatrix& inv_parent, SPickQuery& pinf); @@ -327,27 +334,27 @@ IC SurfFaces &Surfaces () { return m_SurfFaces; } #endif // render routine - void Render (const Fmatrix& parent, CSurface* S); - void RenderSkeleton (const Fmatrix& parent, CSurface* S); - void RenderList (const Fmatrix& parent, u32 color, bool bEdge, IntVec& fl); - void RenderSelection (const Fmatrix& parent, CSurface* s, u32 color); - void RenderEdge (const Fmatrix& parent, CSurface* s, u32 color); + void Render(const Fmatrix&parent, CSurface*S); + void RenderSkeleton(const Fmatrix&parent, CSurface*S); + void RenderList(const Fmatrix&parent, u32 color, bool bEdge, IntVec&fl); + void RenderSelection(const Fmatrix&parent, CSurface*s, u32 color); + void RenderEdge(const Fmatrix&parent, CSurface*s, u32 color); // statistics methods - int GetFaceCount (bool bMatch2Sided=true, bool bIgnoreOCC=true); - int GetVertexCount (){return m_VertCount;} - int GetSurfFaceCount (CSurface* surf, bool bMatch2Sided=true); - float CalculateSurfaceArea (CSurface* surf, bool bMatch2Sided); - float CalculateSurfacePixelArea(CSurface* surf, bool bMatch2Sided); + int GetFaceCount(bool bMatch2Sided = true, bool bIgnoreOCC = true); + int GetVertexCount(){return m_VertCount;} + int GetSurfFaceCount(CSurface*surf, bool bMatch2Sided = true); + float CalculateSurfaceArea(CSurface*surf, bool bMatch2Sided); + float CalculateSurfacePixelArea(CSurface*surf, bool bMatch2Sided); // IO - routine - void SaveMesh (IWriter&); - bool LoadMesh (IReader&); + void SaveMesh(IWriter&); + bool LoadMesh(IReader&); // debug - void DumpAdjacency (); + void DumpAdjacency(); - // convert + // convert #ifdef _MAX_EXPORT void FlipFaces (); TriObject* ExtractTriObject (INode *node, int &deleteIt); @@ -355,12 +362,12 @@ IC SurfFaces &Surfaces () { return m_SurfFaces; } bool Convert (CExporter* exporter); #endif - int FindSimilarUV (st_VMap* vmap, Fvector2& _uv); - int FindSimilarWeight (st_VMap* vmap, float _w); - int FindVMapByName (VMapVec& vmaps, const char* name, u8 t, bool polymap); - void RebuildVMaps (); + int FindSimilarUV(st_VMap*vmap, Fvector2&_uv); + int FindSimilarWeight(st_VMap*vmap, float _w); + int FindVMapByName(VMapVec&vmaps, const char* name, u8 t, bool polymap); + void RebuildVMaps(); - bool Validate (); + bool Validate(); }; //---------------------------------------------------- #endif /*_INCDEF_EditableMesh_H_*/ diff --git a/src/editors/ECore/Editor/EditMeshIO.cpp b/src/editors/ECore/Editor/EditMeshIO.cpp index a85748a2656..45c233a9ac2 100644 --- a/src/editors/ECore/Editor/EditMeshIO.cpp +++ b/src/editors/ECore/Editor/EditMeshIO.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------- // file: StaticMesh.cpp //---------------------------------------------------- - + #include "stdafx.h" #pragma hdrstop @@ -25,193 +25,203 @@ #define EMESH_CHUNK_VMAPS_2 0x1012 #define EMESH_CHUNK_SG 0x1013 -void CEditableMesh::SaveMesh(IWriter& F) +void CEditableMesh::SaveMesh(IWriter &F) { - F.open_chunk (EMESH_CHUNK_VERSION); - F.w_u16 (EMESH_CURRENT_VERSION); - F.close_chunk (); + F.open_chunk(EMESH_CHUNK_VERSION); + F.w_u16(EMESH_CURRENT_VERSION); + F.close_chunk(); - F.open_chunk (EMESH_CHUNK_MESHNAME); - F.w_stringZ (m_Name); - F.close_chunk (); + F.open_chunk(EMESH_CHUNK_MESHNAME); + F.w_stringZ(m_Name); + F.close_chunk(); - F.w_chunk (EMESH_CHUNK_BBOX,&m_Box, sizeof(m_Box)); - F.w_chunk (EMESH_CHUNK_FLAGS,&m_Flags,1); - F.w_chunk (EMESH_CHUNK_BOP,&m_Ops, sizeof(m_Ops)); + F.w_chunk(EMESH_CHUNK_BBOX, &m_Box, sizeof(m_Box)); + F.w_chunk(EMESH_CHUNK_FLAGS, &m_Flags, 1); + F.w_chunk(EMESH_CHUNK_BOP, &m_Ops, sizeof(m_Ops)); - F.open_chunk (EMESH_CHUNK_VERTS); - F.w_u32 (m_VertCount); - F.w (m_Vertices, m_VertCount*sizeof(Fvector)); + F.open_chunk(EMESH_CHUNK_VERTS); + F.w_u32(m_VertCount); + F.w(m_Vertices, m_VertCount*sizeof(Fvector)); - F.close_chunk (); + F.close_chunk(); - F.open_chunk (EMESH_CHUNK_FACES); - F.w_u32 (m_FaceCount); - F.w (m_Faces, m_FaceCount*sizeof(st_Face)); - F.close_chunk (); + F.open_chunk(EMESH_CHUNK_FACES); + F.w_u32(m_FaceCount); + F.w(m_Faces, m_FaceCount*sizeof(st_Face)); + F.close_chunk(); if (GetSmoothGroups()) { - F.open_chunk (EMESH_CHUNK_SG); - F.w (GetSmoothGroups(), m_FaceCount*sizeof(u32)); - F.close_chunk (); + F.open_chunk(EMESH_CHUNK_SG); + F.w(GetSmoothGroups(), m_FaceCount*sizeof(u32)); + F.close_chunk(); } - F.open_chunk (EMESH_CHUNK_VMREFS); - F.w_u32 (m_VMRefs.size()); - for (VMRefsIt r_it=m_VMRefs.begin(); r_it!=m_VMRefs.end(); r_it++) + F.open_chunk(EMESH_CHUNK_VMREFS); + F.w_u32(m_VMRefs.size()); + for (VMRefsIt r_it = m_VMRefs.begin(); r_it!=m_VMRefs.end(); r_it++) { - int sz = r_it->count; VERIFY(sz<=255); - F.w_u8 ((u8)sz); - F.w (r_it->pts, sizeof(st_VMapPt)*sz); + int sz = r_it->count; + VERIFY(sz<=255); + F.w_u8((u8)sz); + F.w(r_it->pts, sizeof(st_VMapPt)*sz); } - F.close_chunk (); + F.close_chunk(); - F.open_chunk (EMESH_CHUNK_SFACE); - F.w_u16 ((u16)m_SurfFaces.size()); /* surface polygon count*/ - for (SurfFacesPairIt plp_it=m_SurfFaces.begin(); plp_it!=m_SurfFaces.end(); plp_it++) + F.open_chunk(EMESH_CHUNK_SFACE); + F.w_u16((u16)m_SurfFaces.size()); /* surface polygon count*/ + for (SurfFacesPairIt plp_it = m_SurfFaces.begin(); plp_it!=m_SurfFaces.end(); plp_it++) { - F.w_stringZ (plp_it->first->_Name()); /* surface name*/ - IntVec& pol_lst = plp_it->second; - F.w_u32 (pol_lst.size()); /* surface-polygon indices*/ - F.w (&*pol_lst.begin(), sizeof(int)*pol_lst.size()); + F.w_stringZ(plp_it->first->_Name()); /* surface name*/ + IntVec &pol_lst = plp_it->second; + F.w_u32(pol_lst.size()); /* surface-polygon indices*/ + F.w(&*pol_lst.begin(), sizeof(int)*pol_lst.size()); } - F.close_chunk (); + F.close_chunk(); - F.open_chunk (EMESH_CHUNK_VMAPS_2); - F.w_u32 (m_VMaps.size()); - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + F.open_chunk(EMESH_CHUNK_VMAPS_2); + F.w_u32(m_VMaps.size()); + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) { - F.w_stringZ ((*vm_it)->name); - F.w_u8 ((*vm_it)->dim); - F.w_u8 ((u8)(*vm_it)->polymap); - F.w_u8 ((*vm_it)->type); - F.w_u32 ((*vm_it)->size()); - F.w ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); - F.w ((*vm_it)->getVIdata(), (*vm_it)->VIdatasize()); - if ((*vm_it)->polymap) - F.w ((*vm_it)->getPIdata(), (*vm_it)->PIdatasize()); + F.w_stringZ((*vm_it)->name); + F.w_u8((*vm_it)->dim); + F.w_u8((u8)(*vm_it)->polymap); + F.w_u8((*vm_it)->type); + F.w_u32((*vm_it)->size()); + F.w((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); + F.w((*vm_it)->getVIdata(), (*vm_it)->VIdatasize()); + if ((*vm_it)->polymap) + F.w((*vm_it)->getPIdata(), (*vm_it)->PIdatasize()); } - F.close_chunk (); + F.close_chunk(); } -bool CEditableMesh::LoadMesh(IReader& F){ - u32 version=0; +bool CEditableMesh::LoadMesh(IReader &F) +{ + u32 version = 0; - R_ASSERT(F.r_chunk(EMESH_CHUNK_VERSION,&version)); - if (version!=EMESH_CURRENT_VERSION){ - ELog.DlgMsg( mtError, "CEditableMesh: unsuported file version. Mesh can't load."); + R_ASSERT(F.r_chunk(EMESH_CHUNK_VERSION, &version)); + if (version!=EMESH_CURRENT_VERSION) + { + ELog.DlgMsg(mtError, "CEditableMesh: unsuported file version. Mesh can't load."); return false; } R_ASSERT(F.find_chunk(EMESH_CHUNK_MESHNAME)); - F.r_stringZ (m_Name); + F.r_stringZ(m_Name); - R_ASSERT(F.r_chunk(EMESH_CHUNK_BBOX,&m_Box)); - R_ASSERT(F.r_chunk(EMESH_CHUNK_FLAGS,&m_Flags)); - F.r_chunk(EMESH_CHUNK_BOP,&m_Ops); + R_ASSERT(F.r_chunk(EMESH_CHUNK_BBOX, &m_Box)); + R_ASSERT(F.r_chunk(EMESH_CHUNK_FLAGS, &m_Flags)); + F.r_chunk(EMESH_CHUNK_BOP, &m_Ops); R_ASSERT(F.find_chunk(EMESH_CHUNK_VERTS)); - m_VertCount = F.r_u32(); - if (m_VertCount<3){ - Log ("!CEditableMesh: Vertices<3."); - return false; + m_VertCount = F.r_u32(); + if (m_VertCount<3) + { + Log("!CEditableMesh: Vertices<3."); + return false; } - m_Vertices = xr_alloc(m_VertCount); - F.r (m_Vertices, m_VertCount*sizeof(Fvector)); + m_Vertices = xr_alloc(m_VertCount); + F.r(m_Vertices, m_VertCount*sizeof(Fvector)); R_ASSERT(F.find_chunk(EMESH_CHUNK_FACES)); - m_FaceCount = F.r_u32(); - m_Faces = xr_alloc(m_FaceCount); - if (m_FaceCount==0){ - Log ("!CEditableMesh: Faces==0."); - return false; + m_FaceCount = F.r_u32(); + m_Faces = xr_alloc(m_FaceCount); + if (m_FaceCount==0) + { + Log("!CEditableMesh: Faces==0."); + return false; } - F.r (m_Faces, m_FaceCount*sizeof(st_Face)); + F.r(m_Faces, m_FaceCount*sizeof(st_Face)); - m_SmoothGroups = xr_alloc(m_FaceCount); - Memory.mem_fill32 (m_SmoothGroups,m_Flags.is(flSGMask)?0:u32(-1),m_FaceCount); - u32 sg_chunk_size = F.find_chunk(EMESH_CHUNK_SG); - if (sg_chunk_size){ - VERIFY (m_FaceCount*sizeof(u32)==sg_chunk_size); - F.r (m_SmoothGroups, m_FaceCount*sizeof(u32)); - } + m_SmoothGroups = xr_alloc(m_FaceCount); + Memory.mem_fill32(m_SmoothGroups, m_Flags.is(flSGMask) ? 0 : u32(-1), m_FaceCount); + u32 sg_chunk_size = F.find_chunk(EMESH_CHUNK_SG); + if (sg_chunk_size) + { + VERIFY(m_FaceCount*sizeof(u32)==sg_chunk_size); + F.r(m_SmoothGroups, m_FaceCount*sizeof(u32)); + } R_ASSERT(F.find_chunk(EMESH_CHUNK_VMREFS)); - m_VMRefs.resize (F.r_u32()); - int sz_vmpt = sizeof(st_VMapPt); - for (VMRefsIt r_it=m_VMRefs.begin(); r_it!=m_VMRefs.end(); r_it++){ - r_it->count = F.r_u8(); - r_it->pts = xr_alloc(r_it->count); - F.r (r_it->pts, sz_vmpt*r_it->count); + m_VMRefs.resize(F.r_u32()); + int sz_vmpt = sizeof(st_VMapPt); + for (VMRefsIt r_it = m_VMRefs.begin(); r_it!=m_VMRefs.end(); r_it++) + { + r_it->count = F.r_u8(); + r_it->pts = xr_alloc(r_it->count); + F.r(r_it->pts, sz_vmpt*r_it->count); } R_ASSERT(F.find_chunk(EMESH_CHUNK_SFACE)); string128 surf_name; - u32 sface_cnt = F.r_u16(); // surface-face count - for (u32 sp_i=0; sp_iFindSurfaceByName(surf_name, &surf_id); VERIFY(surf); - IntVec& face_lst = m_SurfFaces[surf]; - face_lst.resize (F.r_u32()); + CSurface*surf = m_Parent->FindSurfaceByName(surf_name, &surf_id); + VERIFY(surf); + IntVec &face_lst = m_SurfFaces[surf]; + face_lst.resize(F.r_u32()); if (face_lst.empty()) { - Log ("!Empty surface found: %s",surf->_Name()); - return false; + Log("!Empty surface found: %s", surf->_Name()); + return false; } - F.r (&*face_lst.begin(), face_lst.size()*sizeof(int)); - std::sort (face_lst.begin(),face_lst.end()); + F.r(&*face_lst.begin(), face_lst.size()*sizeof(int)); + std::sort(face_lst.begin(), face_lst.end()); } - if(F.find_chunk(EMESH_CHUNK_VMAPS_2)) - { - m_VMaps.resize (F.r_u32()); - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + if (F.find_chunk(EMESH_CHUNK_VMAPS_2)) + { + m_VMaps.resize(F.r_u32()); + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) { - *vm_it = xr_new(); - F.r_stringZ ((*vm_it)->name); - (*vm_it)->dim = F.r_u8(); - (*vm_it)->polymap=F.r_u8(); - (*vm_it)->type = F.r_u8(); - (*vm_it)->resize(F.r_u32()); - F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); - F.r ((*vm_it)->getVIdata(), (*vm_it)->VIdatasize()); - if ((*vm_it)->polymap) - F.r ((*vm_it)->getPIdata(), (*vm_it)->PIdatasize()); - } - }else - { - if(F.find_chunk(EMESH_CHUNK_VMAPS_1)) - { - m_VMaps.resize (F.r_u32()); - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) - { - *vm_it = xr_new(); - F.r_stringZ ((*vm_it)->name); - (*vm_it)->dim = F.r_u8(); - (*vm_it)->type = F.r_u8(); - (*vm_it)->resize(F.r_u32()); - F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize() ); - } - }else - { - R_ASSERT(F.find_chunk(EMESH_CHUNK_VMAPS_0)); - m_VMaps.resize (F.r_u32()); - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) - { - *vm_it = xr_new(); - F.r_stringZ ((*vm_it)->name); - (*vm_it)->dim = 2; - (*vm_it)->type = vmtUV; - (*vm_it)->resize(F.r_u32()); - F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize() ); - } - } - // update vmaps - RebuildVMaps(); - } + *vm_it = xr_new(); + F.r_stringZ((*vm_it)->name); + (*vm_it)->dim = F.r_u8(); + (*vm_it)->polymap = F.r_u8(); + (*vm_it)->type = F.r_u8(); + (*vm_it)->resize(F.r_u32()); + F.r((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); + F.r((*vm_it)->getVIdata(), (*vm_it)->VIdatasize()); + if ((*vm_it)->polymap) + F.r((*vm_it)->getPIdata(), (*vm_it)->PIdatasize()); + } + } + else + { + if (F.find_chunk(EMESH_CHUNK_VMAPS_1)) + { + m_VMaps.resize(F.r_u32()); + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + { + *vm_it = xr_new(); + F.r_stringZ((*vm_it)->name); + (*vm_it)->dim = F.r_u8(); + (*vm_it)->type = F.r_u8(); + (*vm_it)->resize(F.r_u32()); + F.r((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); + } + } + else + { + R_ASSERT(F.find_chunk(EMESH_CHUNK_VMAPS_0)); + m_VMaps.resize(F.r_u32()); + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + { + *vm_it = xr_new(); + F.r_stringZ((*vm_it)->name); + (*vm_it)->dim = 2; + (*vm_it)->type = vmtUV; + (*vm_it)->resize(F.r_u32()); + F.r((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); + } + } + // update vmaps + RebuildVMaps(); + } #ifdef _EDITOR if (!EPrefs->object_flags.is(epoDeffLoadRB)) @@ -228,10 +238,12 @@ bool CEditableMesh::LoadMesh(IReader& F){ if (!EPrefs->object_flags.is(epoDeffLoadCF)) GenerateCFModel(); #endif - OptimizeMesh (false); - RebuildVMaps (); + OptimizeMesh(false); + RebuildVMaps(); - return true; + return true; } + //---------------------------------------------------- + diff --git a/src/editors/ECore/Editor/EditMeshModify.cpp b/src/editors/ECore/Editor/EditMeshModify.cpp index 3c219037f40..08f22a327e4 100644 --- a/src/editors/ECore/Editor/EditMeshModify.cpp +++ b/src/editors/ECore/Editor/EditMeshModify.cpp @@ -7,312 +7,345 @@ #include "EditMesh.h" #include "EditObject.h" + //---------------------------------------------------- -void CEditableMesh::Transform(const Fmatrix& parent) +void CEditableMesh::Transform(const Fmatrix &parent) { - // transform position - for(u32 k=0; ksize(); - for (int k=0; kgetUV(k); - if (uv.similar(_uv)) - return k; - } - return -1; + int sz = vmap->size(); + for (int k = 0; kgetUV(k); + if (uv.similar(_uv)) + return k; + } + return -1; } -int CEditableMesh::FindSimilarWeight(st_VMap* vmap, float _w) +int CEditableMesh::FindSimilarWeight(st_VMap *vmap, float _w) { - int sz = vmap->size(); - for (int k=0; kgetW(k); - if (fsimilar(w,_w)) return k; - } - return -1; + int sz = vmap->size(); + for (int k = 0; kgetW(k); + if (fsimilar(w, _w)) + return k; + } + return -1; } void CEditableMesh::RebuildVMaps() { -//. Log ("Rebuilding VMaps..."); - IntVec m_VertVMap; - m_VertVMap.resize(m_VertCount,-1); - VMapVec nVMaps; - VMRefsVec nVMRefs; - // refs copy to new - { - nVMRefs.resize(m_VMRefs.size()); - for (VMRefsIt o_it=m_VMRefs.begin(),n_it=nVMRefs.begin(); o_it!=m_VMRefs.end(); o_it++,n_it++){ - n_it->count = o_it->count; - n_it->pts = xr_alloc(n_it->count); - } - } - - for (u32 f_id=0; f_idvmap_index]; - switch (vmap->type){ - case vmtUV:{ - int& pm=m_VertVMap[F.pv[k].pindex]; - if (-1==pm){ // point map - pm=F.pv[k].vmref; - int vm_idx=FindVMapByName(nVMaps,vmap->name.c_str(),vmap->type,false); - if (-1==vm_idx){ - nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,false)); - vm_idx=nVMaps.size()-1; - } - st_VMap* nVMap=nVMaps[vm_idx]; - -// int uv_idx = FindSimilarUV(nVMap,vmap->getUV(pt_it->index)); -// if (uv_idx==-1){ -// uv_idx = nVMap->size(); -// nVMap->appendUV(vmap->getUV(pt_it->index)); -// nVMap->appendVI(F.pv[k].pindex); -// } - - nVMap->appendUV(vmap->getUV(o_pt_it->index)); - nVMap->appendVI(F.pv[k].pindex); - n_pt_it->index = nVMap->size()-1; - n_pt_it->vmap_index=vm_idx; - } - else{ // poly map - int vm_idx=FindVMapByName(nVMaps,vmap->name.c_str(),vmap->type,true); - if (-1==vm_idx){ - nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,true)); - vm_idx=nVMaps.size()-1; - } - st_VMap* nVMapPM=nVMaps[vm_idx]; - -// int uv_idx = FindSimilarUV(nVMapPM,vmap->getUV(pt_it->index)); -// if (uv_idx==-1){ -// uv_idx = nVMapPM->size(); -// nVMapPM->appendUV(vmap->getUV(pt_it->index)); -// nVMapPM->appendVI(F.pv[k].pindex); -// nVMapPM->appendPI(f_it-m_Faces.begin()); -// } -// n_pt_it->index = uv_idx; - - nVMapPM->appendUV(vmap->getUV(o_pt_it->index)); - nVMapPM->appendVI(F.pv[k].pindex); - nVMapPM->appendPI(f_id); - n_pt_it->index = nVMapPM->size()-1; - n_pt_it->vmap_index=vm_idx; - } - }break; - case vmtWeight:{ - int vm_idx=FindVMapByName(nVMaps,vmap->name.c_str(),vmap->type,false); - if (-1==vm_idx){ - nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,false)); - vm_idx=nVMaps.size()-1; - } - st_VMap* nWMap=nVMaps[vm_idx]; - nWMap->appendW (vmap->getW(o_pt_it->index)); - nWMap->appendVI (F.pv[k].pindex); - n_pt_it->index = nWMap->size()-1; - n_pt_it->vmap_index=vm_idx; - }break; - } - } - } - } - for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) - xr_delete(*vm_it); - - m_VMaps.clear(); - m_VMaps=nVMaps; - // clear refs - for (VMRefsIt ref_it=m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++) - xr_free (ref_it->pts); - m_VMRefs.clear(); - m_VMRefs = nVMRefs; + //. Log ("Rebuilding VMaps..."); + IntVec m_VertVMap; + m_VertVMap.resize(m_VertCount, -1); + VMapVec nVMaps; + VMRefsVec nVMRefs; + // refs copy to new + { + nVMRefs.resize(m_VMRefs.size()); + for (VMRefsIt o_it = m_VMRefs.begin(), n_it = nVMRefs.begin(); o_it!=m_VMRefs.end(); o_it++,n_it++) + { + n_it->count = o_it->count; + n_it->pts = xr_alloc(n_it->count); + } + } + + for (u32 f_id = 0; f_idvmap_index]; + switch (vmap->type) + { + case vmtUV: + { + int &pm = m_VertVMap[F.pv[k].pindex]; + if (-1==pm) + { // point map + pm = F.pv[k].vmref; + int vm_idx = FindVMapByName(nVMaps, vmap->name.c_str(), vmap->type, false); + if (-1==vm_idx) + { + nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,false)); + vm_idx = nVMaps.size()-1; + } + st_VMap*nVMap = nVMaps[vm_idx]; + + // int uv_idx = FindSimilarUV(nVMap,vmap->getUV(pt_it->index)); + // if (uv_idx==-1){ + // uv_idx = nVMap->size(); + // nVMap->appendUV(vmap->getUV(pt_it->index)); + // nVMap->appendVI(F.pv[k].pindex); + // } + + nVMap->appendUV(vmap->getUV(o_pt_it->index)); + nVMap->appendVI(F.pv[k].pindex); + n_pt_it->index = nVMap->size()-1; + n_pt_it->vmap_index = vm_idx; + } + else + { // poly map + int vm_idx = FindVMapByName(nVMaps, vmap->name.c_str(), vmap->type, true); + if (-1==vm_idx) + { + nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,true)); + vm_idx = nVMaps.size()-1; + } + st_VMap*nVMapPM = nVMaps[vm_idx]; + + // int uv_idx = FindSimilarUV(nVMapPM,vmap->getUV(pt_it->index)); + // if (uv_idx==-1){ + // uv_idx = nVMapPM->size(); + // nVMapPM->appendUV(vmap->getUV(pt_it->index)); + // nVMapPM->appendVI(F.pv[k].pindex); + // nVMapPM->appendPI(f_it-m_Faces.begin()); + // } + // n_pt_it->index = uv_idx; + + nVMapPM->appendUV(vmap->getUV(o_pt_it->index)); + nVMapPM->appendVI(F.pv[k].pindex); + nVMapPM->appendPI(f_id); + n_pt_it->index = nVMapPM->size()-1; + n_pt_it->vmap_index = vm_idx; + } + } + break; + case vmtWeight: + { + int vm_idx = FindVMapByName(nVMaps, vmap->name.c_str(), vmap->type, false); + if (-1==vm_idx) + { + nVMaps.push_back(xr_new(vmap->name.c_str(),vmap->type,false)); + vm_idx = nVMaps.size()-1; + } + st_VMap*nWMap = nVMaps[vm_idx]; + nWMap->appendW(vmap->getW(o_pt_it->index)); + nWMap->appendVI(F.pv[k].pindex); + n_pt_it->index = nWMap->size()-1; + n_pt_it->vmap_index = vm_idx; + } + break; + } + } + } + } + for (VMapIt vm_it = m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++) + xr_delete(*vm_it); + + m_VMaps.clear(); + m_VMaps = nVMaps; + // clear refs + for (VMRefsIt ref_it = m_VMRefs.begin(); ref_it!=m_VMRefs.end(); ref_it++) + xr_free(ref_it->pts); + m_VMRefs.clear(); + m_VMRefs = nVMRefs; } #define MX 25 #define MY 15 #define MZ 25 -static Fvector VMmin, VMscale; -static U32Vec VM[MX+1][MY+1][MZ+1]; -static Fvector VMeps; - -static FvectorVec m_NewPoints; -bool CEditableMesh::OptimizeFace(st_Face& face){ - Fvector points[3]; - int mface[3]; - int k; - - for (k=0; k<3; k++){ - points[k].set(m_Vertices[face.pv[k].pindex]); - mface[k] = -1; +static Fvector VMmin, VMscale; +static U32Vec VM[MX+1][MY+1][MZ+1]; +static Fvector VMeps; + +static FvectorVec m_NewPoints; + +bool CEditableMesh::OptimizeFace(st_Face &face) +{ + Fvector points[3]; + int mface[3]; + int k; + + for (k = 0; k<3; k++) + { + points[k].set(m_Vertices[face.pv[k].pindex]); + mface[k] = -1; } - // get similar vert idx list - for (k=0; k<3; k++){ - U32Vec* vl; - int ix,iy,iz; - ix = iFloor(float(points[k].x-VMmin.x)/VMscale.x*MX); - iy = iFloor(float(points[k].y-VMmin.y)/VMscale.y*MY); - iz = iFloor(float(points[k].z-VMmin.z)/VMscale.z*MZ); - vl = &(VM[ix][iy][iz]); - for(U32It it=vl->begin();it!=vl->end(); it++){ - FvectorIt v = m_NewPoints.begin()+(*it); - if( v->similar(points[k],EPS) ) + // get similar vert idx list + for (k = 0; k<3; k++) + { + U32Vec *vl; + int ix, iy, iz; + ix = iFloor(float(points[k].x-VMmin.x)/VMscale.x*MX); + iy = iFloor(float(points[k].y-VMmin.y)/VMscale.y*MY); + iz = iFloor(float(points[k].z-VMmin.z)/VMscale.z*MZ); + vl = &(VM[ix][iy][iz]); + for (U32It it = vl->begin(); it!=vl->end(); it++) + { + FvectorIt v = m_NewPoints.begin()+(*it); + if (v->similar(points[k], EPS)) mface[k] = *it; - } - } - for(k=0; k<3; k++ ){ - if( mface[k] == -1 ){ - mface[k] = m_NewPoints.size(); - m_NewPoints.push_back( points[k] ); - int ix,iy,iz; - ix = iFloor(float(points[k].x-VMmin.x)/VMscale.x*MX); - iy = iFloor(float(points[k].y-VMmin.y)/VMscale.y*MY); - iz = iFloor(float(points[k].z-VMmin.z)/VMscale.z*MZ); - VM[ix][iy][iz].push_back(mface[k]); - int ixE,iyE,izE; - ixE = iFloor(float(points[k].x+VMeps.x-VMmin.x)/VMscale.x*MX); - iyE = iFloor(float(points[k].y+VMeps.y-VMmin.y)/VMscale.y*MY); - izE = iFloor(float(points[k].z+VMeps.z-VMmin.z)/VMscale.z*MZ); - if (ixE!=ix) - VM[ixE][iy][iz].push_back(mface[k]); - if (iyE!=iy) - VM[ix][iyE][iz].push_back(mface[k]); - if (izE!=iz) - VM[ix][iy][izE].push_back(mface[k]); - if ((ixE!=ix)&&(iyE!=iy)) - VM[ixE][iyE][iz].push_back(mface[k]); - if ((ixE!=ix)&&(izE!=iz)) - VM[ixE][iy][izE].push_back(mface[k]); - if ((iyE!=iy)&&(izE!=iz)) - VM[ix][iyE][izE].push_back(mface[k]); - if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) - VM[ixE][iyE][izE].push_back(mface[k]); - } - } - - if ((mface[0]==mface[1])||(mface[1]==mface[2])||(mface[0]==mface[2])){ - Msg("!Optimize: Invalid face found. Removed."); + } + } + for (k = 0; k<3; k++) + { + if (mface[k]==-1) + { + mface[k] = m_NewPoints.size(); + m_NewPoints.push_back(points[k]); + int ix, iy, iz; + ix = iFloor(float(points[k].x-VMmin.x)/VMscale.x*MX); + iy = iFloor(float(points[k].y-VMmin.y)/VMscale.y*MY); + iz = iFloor(float(points[k].z-VMmin.z)/VMscale.z*MZ); + VM[ix][iy][iz].push_back(mface[k]); + int ixE, iyE, izE; + ixE = iFloor(float(points[k].x+VMeps.x-VMmin.x)/VMscale.x*MX); + iyE = iFloor(float(points[k].y+VMeps.y-VMmin.y)/VMscale.y*MY); + izE = iFloor(float(points[k].z+VMeps.z-VMmin.z)/VMscale.z*MZ); + if (ixE!=ix) + VM[ixE][iy][iz].push_back(mface[k]); + if (iyE!=iy) + VM[ix][iyE][iz].push_back(mface[k]); + if (izE!=iz) + VM[ix][iy][izE].push_back(mface[k]); + if ((ixE!=ix)&&(iyE!=iy)) + VM[ixE][iyE][iz].push_back(mface[k]); + if ((ixE!=ix)&&(izE!=iz)) + VM[ixE][iy][izE].push_back(mface[k]); + if ((iyE!=iy)&&(izE!=iz)) + VM[ix][iyE][izE].push_back(mface[k]); + if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) + VM[ixE][iyE][izE].push_back(mface[k]); + } + } + + if ((mface[0]==mface[1])||(mface[1]==mface[2])||(mface[0]==mface[2])) + { + Msg("!Optimize: Invalid face found. Removed."); return false; - }else{ - face.pv[0].pindex = mface[0]; - face.pv[1].pindex = mface[1]; - face.pv[2].pindex = mface[2]; + } + else + { + face.pv[0].pindex = mface[0]; + face.pv[1].pindex = mface[1]; + face.pv[2].pindex = mface[2]; return true; - } + } } void CEditableMesh::OptimizeMesh(BOOL NoOpt) { - if (!NoOpt){ + if (!NoOpt) + { #ifdef _EDITOR UnloadRenderBuffers (); UnloadCForm (); #endif - UnloadFNormals (true); - UnloadVNormals (true); - UnloadSVertices (true); - UnloadAdjacency (true); - - // clear static data - for (int x=0; x(m_VertCount); - Memory.mem_copy (m_Vertices,&*m_NewPoints.begin(),m_NewPoints.size()*sizeof(Fvector)); - - if (i_del_face){ - st_Face* old_faces = m_Faces; - u32* old_sg = m_SmoothGroups; - - m_Faces = xr_alloc (m_FaceCount-i_del_face); - m_SmoothGroups = xr_alloc (m_FaceCount-i_del_face); - - u32 new_dk = 0; - for (u32 dk=0; dksecond; - for (int k=0; k(m_VertCount); + Memory.mem_copy(m_Vertices, &*m_NewPoints.begin(), m_NewPoints.size()*sizeof(Fvector)); + + if (i_del_face) + { + st_Face*old_faces = m_Faces; + u32 *old_sg = m_SmoothGroups; + + m_Faces = xr_alloc(m_FaceCount-i_del_face); + m_SmoothGroups = xr_alloc(m_FaceCount-i_del_face); + + u32 new_dk = 0; + for (u32 dk = 0; dksecond; + for (int k = 0; k(int)dk) - { - --f; - }else if (f==(int)dk) - { + { + --f; + } + else if (f==(int)dk) + { pol_lst.erase(pol_lst.begin()+k); --k; } } } - continue; - } -//. -----in plugin -//. new_dk++; + continue; + } + //. -----in plugin + //. new_dk++; - m_Faces[new_dk] = old_faces[dk]; - m_SmoothGroups[new_dk] = old_sg[dk]; + m_Faces[new_dk] = old_faces[dk]; + m_SmoothGroups[new_dk] = old_sg[dk]; -//. -----in editors - ++new_dk; + //. -----in editors + ++new_dk; } - m_FaceCount = m_FaceCount-i_del_face; - xr_free (old_faces); - xr_free (old_sg); - } - } + m_FaceCount = m_FaceCount-i_del_face; + xr_free(old_faces); + xr_free(old_sg); + } + } } + diff --git a/src/editors/ECore/Editor/EditMeshPick.cpp b/src/editors/ECore/Editor/EditMeshPick.cpp index de573801bfc..5ad26c77db6 100644 --- a/src/editors/ECore/Editor/EditMeshPick.cpp +++ b/src/editors/ECore/Editor/EditMeshPick.cpp @@ -7,30 +7,31 @@ #include "EditMesh.h" #include "EditObject.h" -#include "cl_collector.h" +#include "editors/ECore/Engine/cl_collector.h" #include "ui_main.h" #include "pick_defs.h" -#include "../ETools/ETools.h" +#include "utils/ETools/ETools.h" /* void CEditableMesh::CHullPickFaces(PlaneVec& pl, Fmatrix& parent, U32Vec& fl){ - u32 i=0; - Fvector p; + u32 i=0; + Fvector p; vector inside(m_Points.size(),true); for(FvectorIt v_it=m_Points.begin();v_it!=m_Points.end();v_it++){ parent.transform_tiny(p,*v_it); for(PlaneIt p_it=pl.begin(); p_it!=pl.end(); p_it++) - if (p_it->classify(p)>EPS_L) { inside[v_it-m_Points.begin()]=false; break; } + if (p_it->classify(p)>EPS_L) { inside[v_it-m_Points.begin()]=false; break; } } for(FaceIt f_it=m_Faces.begin();f_it!=m_Faces.end();f_it++,i++) - if (inside[f_it->pv[0].pindex]&&inside[f_it->pv[1].pindex]&&inside[f_it->pv[2].pindex]) fl.push_back(i); + if (inside[f_it->pv[0].pindex]&&inside[f_it->pv[1].pindex]&&inside[f_it->pv[2].pindex]) fl.push_back(i); } */ //---------------------------------------------------- -static IntVec sml_processed; -static Fvector sml_normal; -static float m_fSoftAngle; +static IntVec sml_processed; +static Fvector sml_normal; +static float m_fSoftAngle; + //---------------------------------------------------- //---------------------------------------------------- @@ -38,87 +39,98 @@ static float m_fSoftAngle; //---------------------------------------------------- void CEditableMesh::GenerateCFModel() { - UnloadCForm (); - // Collect faces - CDB::Collector* CL = ETOOLS::create_collector(); - // double sided - for (SurfFacesPairIt sp_it=m_SurfFaces.begin(); sp_it!=m_SurfFaces.end(); sp_it++){ - IntVec& face_lst = sp_it->second; - for (IntIt it=face_lst.begin(); it!=face_lst.end(); it++){ - st_Face& F = m_Faces[*it]; - ETOOLS::collector_add_face_d(CL,m_Vertices[F.pv[0].pindex],m_Vertices[F.pv[1].pindex],m_Vertices[F.pv[2].pindex], *it); - if (sp_it->first->m_Flags.is(CSurface::sf2Sided)) - ETOOLS::collector_add_face_d(CL,m_Vertices[F.pv[2].pindex],m_Vertices[F.pv[1].pindex],m_Vertices[F.pv[0].pindex], *it); - } - } - m_CFModel = ETOOLS::create_model_cl(CL); - ETOOLS::destroy_collector(CL); + UnloadCForm(); + // Collect faces + CDB::Collector *CL = ETOOLS::create_collector(); + // double sided + for (SurfFacesPairIt sp_it = m_SurfFaces.begin(); sp_it!=m_SurfFaces.end(); sp_it++) + { + IntVec &face_lst = sp_it->second; + for (IntIt it = face_lst.begin(); it!=face_lst.end(); it++) + { + st_Face&F = m_Faces[*it]; + ETOOLS::collector_add_face_d(CL, m_Vertices[F.pv[0].pindex], m_Vertices[F.pv[1].pindex], m_Vertices[F.pv[2].pindex], *it); + if (sp_it->first->m_Flags.is(CSurface::sf2Sided)) + ETOOLS::collector_add_face_d(CL, m_Vertices[F.pv[2].pindex], m_Vertices[F.pv[1].pindex], m_Vertices[F.pv[0].pindex], *it); + } + } + m_CFModel = ETOOLS::create_model_cl(CL); + ETOOLS::destroy_collector(CL); } -void CEditableMesh::RayQuery(SPickQuery& pinf) +void CEditableMesh::RayQuery(SPickQuery &pinf) { - if (!m_CFModel) GenerateCFModel(); -//* - ETOOLS::ray_query (m_CFModel, pinf.m_Start, pinf.m_Direction, pinf.m_Dist); - for (int r=0; rinf.range+EPS_L:UI->ZFar();// (bugs: не всегда выбирает) //S ???? - - ETOOLS::ray_options (CDB::OPT_ONLYNEAREST | CDB::OPT_CULL); - ETOOLS::ray_query_m (inv_parent, m_CFModel, start, direction, _sqrt_flt_max); - - if (ETOOLS::r_count()){ - CDB::RESULT* I = ETOOLS::r_begin (); - if (I->rangeSetRESULT (m_CFModel,I); - pinf->e_obj = m_Parent; - pinf->e_mesh = this; - pinf->pt.mul (direction,pinf->inf.range); - pinf->pt.add (start); + if (!m_Flags.is(flVisible)) + return false; + + if (!m_CFModel) + GenerateCFModel(); + //. float m_r = pinf?pinf->inf.range+EPS_L:UI->ZFar();// (bugs: не всегда выбирает) //S ???? + + ETOOLS::ray_options(CDB::OPT_ONLYNEAREST|CDB::OPT_CULL); + ETOOLS::ray_query_m(inv_parent, m_CFModel, start, direction, _sqrt_flt_max); + + if (ETOOLS::r_count()) + { + CDB::RESULT *I = ETOOLS::r_begin(); + if (I->rangeSetRESULT(m_CFModel, I); + pinf->e_obj = m_Parent; + pinf->e_mesh = this; + pinf->pt.mul(direction, pinf->inf.range); + pinf->pt.add(start); } distance = I->range; return true; - } + } } - return false; + return false; } + //---------------------------------------------------- #ifdef _EDITOR bool CEditableMesh::CHullPickMesh(PlaneVec& pl, const Fmatrix& parent) @@ -138,13 +150,13 @@ bool CEditableMesh::CHullPickMesh(PlaneVec& pl, const Fmatrix& parent) void CEditableMesh::RecurseTri(int id) { - // Check if triangle already processed +// Check if triangle already processed if (std::find(sml_processed.begin(),sml_processed.end(),id)!=sml_processed.end()) return; sml_processed.push_back(id); - // recurse +// recurse for (int k=0; k<3; k++){ IntVec& PL = (*m_Adjs)[m_Faces[id].pv[k].pindex]; for (IntIt pl_it=PL.begin(); pl_it!=PL.end(); pl_it++){ @@ -231,4 +243,3 @@ void CEditableMesh::FrustumPickFaces(const CFrustum& frustum, const Fmatrix& par #endif // - diff --git a/src/editors/ECore/Editor/EditMeshRender.cpp b/src/editors/ECore/Editor/EditMeshRender.cpp index 114fa9c31e4..682c948ecab 100644 --- a/src/editors/ECore/Editor/EditMeshRender.cpp +++ b/src/editors/ECore/Editor/EditMeshRender.cpp @@ -9,348 +9,416 @@ #include "EditMesh.h" #include "EditObject.h" #include "ui_main.h" -#include "d3dutils.h" +#include "D3DUtils.h" #include "render.h" //---------------------------------------------------- #define F_LIM (10000) #define V_LIM (F_LIM*3) + //---------------------------------------------------- void CEditableMesh::GenerateRenderBuffers() { -// CTimer T; -// T.Start(); -/* - CMemoryWriter F; - m_Parent->PrepareOGF(F,false,this); - IReader R (F.pointer(), F.size()); - m_Visual = ::Render->Models->Create(GetName(),&R); -// Log ("Time: ",T.GetElapsed_sec()); -// string_path fn; -// strconcat (fn,"_alexmx_\\",GetName(),".ogf"); -// FS.update_path (fn,_import_,fn); -// F.save_to (fn); - return; -*/ - if (m_RenderBuffers) return; - m_RenderBuffers = xr_new(); - - GenerateVNormals (0); - - VERIFY (m_VertexNormals); - - for (SurfFacesPairIt sp_it=m_SurfFaces.begin(); sp_it!=m_SurfFaces.end(); sp_it++){ - IntVec& face_lst = sp_it->second; - CSurface* _S = sp_it->first; - int num_verts=face_lst.size()*3; + // CTimer T; + // T.Start(); + /* + CMemoryWriter F; + m_Parent->PrepareOGF(F,false,this); + IReader R (F.pointer(), F.size()); + m_Visual = ::Render->Models->Create(GetName(),&R); + // Log ("Time: ",T.GetElapsed_sec()); + // string_path fn; + // strconcat (fn,"_alexmx_\\",GetName(),".ogf"); + // FS.update_path (fn,_import_,fn); + // F.save_to (fn); + return; + */ + if (m_RenderBuffers) + return; + m_RenderBuffers = xr_new(); + + GenerateVNormals(0); + + VERIFY(m_VertexNormals); + + for (SurfFacesPairIt sp_it = m_SurfFaces.begin(); sp_it!=m_SurfFaces.end(); sp_it++) + { + IntVec &face_lst = sp_it->second; + CSurface*_S = sp_it->first; + int num_verts = face_lst.size()*3; RBVector rb_vec; - int v_cnt=num_verts; - int start_face=0; + int v_cnt = num_verts; + int start_face = 0; int num_face; - VERIFY3 (v_cnt,"Empty surface arrive.",_S->_Name()); - do{ - rb_vec.push_back (st_RenderBuffer(0,(v_cntm_Flags.is(CSurface::sf2Sided)) rb.dwNumVertex *= 2; - num_face = (v_cnt_FVF())*rb.dwNumVertex; - R_ASSERT2 (buf_size,"Empty buffer size or bad FVF."); - u8* bytes = 0; - IDirect3DVertexBuffer9* pVB=0; -// IDirect3DIndexBuffer9* pIB=0; - R_CHK(HW.pDevice->CreateVertexBuffer(buf_size, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &pVB, 0)); -// R_CHK(HW.pDevice->CreateIndexBuffer(i_cnt*sizeof(u16),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pIB,NULL)); - rb.pGeom.create (_S->_FVF(),pVB,0); - - R_CHK (pVB->Lock(0,0,(LPVOID*)&bytes,0)); - FillRenderBuffer (face_lst,start_face,num_face,_S,bytes); - pVB->Unlock (); - - v_cnt -= V_LIM; - start_face += (_S->m_Flags.is(CSurface::sf2Sided))?rb.dwNumVertex/6:rb.dwNumVertex/3; - }while(v_cnt>0); - if (num_verts>0) m_RenderBuffers->insert(mk_pair(_S,rb_vec)); + VERIFY3(v_cnt, "Empty surface arrive.", _S->_Name()); + do + { + rb_vec.push_back(st_RenderBuffer(0, (v_cntm_Flags.is(CSurface::sf2Sided)) + rb.dwNumVertex *= 2; + num_face = (v_cnt_FVF())*rb.dwNumVertex; + R_ASSERT2(buf_size, "Empty buffer size or bad FVF."); + u8 *bytes = 0; + IDirect3DVertexBuffer9 *pVB = 0; + // IDirect3DIndexBuffer9* pIB=0; + R_CHK(HW.pDevice->CreateVertexBuffer(buf_size, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &pVB, 0)); + // R_CHK(HW.pDevice->CreateIndexBuffer(i_cnt*sizeof(u16),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pIB,NULL)); + rb.pGeom.create(_S->_FVF(), pVB, 0); + + R_CHK(pVB->Lock(0, 0, (LPVOID*)&bytes, 0)); + FillRenderBuffer(face_lst, start_face, num_face, _S, bytes); + pVB->Unlock(); + + v_cnt -= V_LIM; + start_face += (_S->m_Flags.is(CSurface::sf2Sided)) ? rb.dwNumVertex/6 : rb.dwNumVertex/3; + } while (v_cnt>0); + if (num_verts>0) + m_RenderBuffers->insert(mk_pair(_S, rb_vec)); } UnloadVNormals(); } + //---------------------------------------------------- void CEditableMesh::UnloadRenderBuffers() { - if (m_RenderBuffers){ - for (RBMapPairIt rbmp_it=m_RenderBuffers->begin(); rbmp_it!=m_RenderBuffers->end(); rbmp_it++){ - for(RBVecIt rb_it=rbmp_it->second.begin(); rb_it!=rbmp_it->second.end(); rb_it++) - if (rb_it->pGeom){ - _RELEASE (rb_it->pGeom->vb); - _RELEASE (rb_it->pGeom->ib); + if (m_RenderBuffers) + { + for (RBMapPairIt rbmp_it = m_RenderBuffers->begin(); rbmp_it!=m_RenderBuffers->end(); rbmp_it++) + { + for (RBVecIt rb_it = rbmp_it->second.begin(); rb_it!=rbmp_it->second.end(); rb_it++) + if (rb_it->pGeom) + { + _RELEASE(rb_it->pGeom->vb); + _RELEASE(rb_it->pGeom->ib); rb_it->pGeom.destroy(); } } - xr_delete (m_RenderBuffers); + xr_delete(m_RenderBuffers); } } + //---------------------------------------------------- -void CEditableMesh::FillRenderBuffer(IntVec& face_lst, int start_face, int num_face, const CSurface* surf, LPBYTE& src_data) +void CEditableMesh::FillRenderBuffer(IntVec &face_lst, int start_face, int num_face, const CSurface *surf, LPBYTE &src_data) { - LPBYTE data = src_data; - u32 dwFVF = surf->_FVF(); - u32 dwTexCnt = ((dwFVF&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); - for (int fl_i=start_face; fl_i_FVF(); + u32 dwTexCnt = ((dwFVF&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); + for (int fl_i = start_face; fl_itype!=vmtUV){ - offs++; + sz = sizeof(Fvector2); + int offs = 0; + for (int t = 0; t<(int)dwTexCnt; t++) + { + VERIFY2((t+offs)<(int)m_VMRefs[fv.vmref].count, "- VMap layer index out of range"); + st_VMapPt&vm_pt = m_VMRefs[fv.vmref].pts[t+offs]; + if (m_VMaps[vm_pt.vmap_index]->type!=vmtUV) + { + offs++; t--; continue; } - VERIFY2 (vm_pt.vmap_indexsize(),"- VMap point index out of range"); - CopyMemory(data,&vmap->getUV(vm_pt.index),sz); data+=sz; -// Msg("%3.2f, %3.2f",vmap->getUV(vm_pt.index).x,vmap->getUV(vm_pt.index).y); + VERIFY2(vm_pt.vmap_indexsize(), "- VMap point index out of range"); + CopyMemory(data, &vmap->getUV(vm_pt.index), sz); + data += sz; + // Msg("%3.2f, %3.2f",vmap->getUV(vm_pt.index).x,vmap->getUV(vm_pt.index).y); } } - if (surf->m_Flags.is(CSurface::sf2Sided)){ - for (int k=2; k>=0; k--){ - st_FaceVert& fv = face.pv[k]; - Fvector& PN = m_VertexNormals[f_index*3+k]; + if (surf->m_Flags.is(CSurface::sf2Sided)) + { + for (int k = 2; k>=0; k--) + { + st_FaceVert&fv = face.pv[k]; + Fvector &PN = m_VertexNormals[f_index*3+k]; int sz; - if (dwFVF&D3DFVF_XYZ){ - sz=sizeof(Fvector); - VERIFY2(fv.pindextype!=vmtUV){ + sz = sizeof(Fvector2); + int offs = 0; + for (int t = 0; t<(int)dwTexCnt; t++) + { + VERIFY2((t+offs)<(int)m_VMRefs[fv.vmref].count, "- VMap layer index out of range"); + st_VMapPt&vm_pt = m_VMRefs[fv.vmref].pts[t]; + if (m_VMaps[vm_pt.vmap_index]->type!=vmtUV) + { offs++; t--; continue; } - VERIFY2(vm_pt.vmap_indexsize(),"- VMap point index out of range"); - CopyMemory(data,&vmap->getUV(vm_pt.index),sz); data+=sz; + VERIFY2(vm_pt.vmap_indexsize(), "- VMap point index out of range"); + CopyMemory(data, &vmap->getUV(vm_pt.index), sz); + data += sz; -// Msg("%3.2f, %3.2f",vmap->getUV(vm_pt.index).x,vmap->getUV(vm_pt.index).y); + // Msg("%3.2f, %3.2f",vmap->getUV(vm_pt.index).x,vmap->getUV(vm_pt.index).y); } } } } } + //---------------------------------------------------- -void CEditableMesh::Render(const Fmatrix& parent, CSurface* S) +void CEditableMesh::Render(const Fmatrix &parent, CSurface *S) { - if (0==m_RenderBuffers) GenerateRenderBuffers(); + if (0==m_RenderBuffers) + GenerateRenderBuffers(); // visibility test - if (!m_Flags.is(flVisible)) return; + if (!m_Flags.is(flVisible)) + return; // frustum test - Fbox bb; bb.set(m_Box); + Fbox bb; + bb.set(m_Box); bb.xform(parent); - if (!::Render->occ_visible(bb)) return; + if (!::Render->occ_visible(bb)) + return; // render RBMapPairIt rb_pair = m_RenderBuffers->find(S); - if (rb_pair!=m_RenderBuffers->end()){ - RBVector& rb_vec = rb_pair->second; - for (RBVecIt rb_it=rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) - EDevice.DP(D3DPT_TRIANGLELIST,rb_it->pGeom,0,rb_it->dwNumVertex/3); + if (rb_pair!=m_RenderBuffers->end()) + { + RBVector &rb_vec = rb_pair->second; + for (RBVecIt rb_it = rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) + EDevice.DP(D3DPT_TRIANGLELIST, rb_it->pGeom, 0, rb_it->dwNumVertex/3); } } + //---------------------------------------------------- #define MAX_VERT_COUNT 0xFFFF static Fvector RB[MAX_VERT_COUNT]; -static RB_cnt=0; +static RB_cnt += +0; -void CEditableMesh::RenderList(const Fmatrix& parent, u32 color, bool bEdge, IntVec& fl) +void CEditableMesh::RenderList(const Fmatrix &parent, u32 color, bool bEdge, IntVec &fl) { -// if (!m_Visible) return; -// if (!m_LoadState.is(LS_RBUFFERS)) CreateRenderBuffers(); - - if (fl.size()==0) return; - RCache.set_xform_world(parent); - EDevice.RenderNearer(0.0006); - RB_cnt = 0; - if (bEdge){ - EDevice.SetShader(EDevice.m_WireShader); - EDevice.SetRS(D3DRS_FILLMODE,D3DFILL_WIREFRAME); - }else - EDevice.SetShader(EDevice.m_SelectionShader); - for (IntIt dw_it=fl.begin(); dw_it!=fl.end(); ++dw_it) + // if (!m_Visible) return; + // if (!m_LoadState.is(LS_RBUFFERS)) CreateRenderBuffers(); + + if (fl.size()==0) + return; + RCache.set_xform_world(parent); + EDevice.RenderNearer(0.0006); + RB_cnt = 0; + if (bEdge) + { + EDevice.SetShader(EDevice.m_WireShader); + EDevice.SetRS(D3DRS_FILLMODE, D3DFILL_WIREFRAME); + } + else + EDevice.SetShader(EDevice.m_SelectionShader); + for (IntIt dw_it = fl.begin(); dw_it!=fl.end(); ++dw_it) { - st_Face& face = m_Faces[*dw_it]; - for (int k=0; k<3; ++k) - RB[RB_cnt++].set(m_Vertices[face.pv[k].pindex]); + st_Face&face = m_Faces[*dw_it]; + for (int k = 0; k<3; ++k) + RB[RB_cnt++].set(m_Vertices[face.pv[k].pindex]); - if (RB_cnt==MAX_VERT_COUNT) + if (RB_cnt==MAX_VERT_COUNT) { - DU_impl.DrawPrimitiveL(D3DPT_TRIANGLELIST,RB_cnt/3,RB,RB_cnt,color,true,false); - RB_cnt = 0; + DU_impl.DrawPrimitiveL(D3DPT_TRIANGLELIST, RB_cnt/3, RB, RB_cnt, color, true, false); + RB_cnt = 0; } } - if (RB_cnt) - DU_impl.DrawPrimitiveL(D3DPT_TRIANGLELIST,RB_cnt/3,RB,RB_cnt,color,true,false); + if (RB_cnt) + DU_impl.DrawPrimitiveL(D3DPT_TRIANGLELIST, RB_cnt/3, RB, RB_cnt, color, true, false); if (bEdge) - EDevice.SetRS(D3DRS_FILLMODE,EDevice.dwFillMode); + EDevice.SetRS(D3DRS_FILLMODE, EDevice.dwFillMode); - EDevice.ResetNearer(); + EDevice.ResetNearer(); } + //---------------------------------------------------- -void CEditableMesh::RenderSelection(const Fmatrix& parent, CSurface* s, u32 color) +void CEditableMesh::RenderSelection(const Fmatrix &parent, CSurface *s, u32 color) { - if (0==m_RenderBuffers) GenerateRenderBuffers(); -// if (!m_Visible) return; - Fbox bb; bb.set(m_Box); + if (0==m_RenderBuffers) + GenerateRenderBuffers(); + // if (!m_Visible) return; + Fbox bb; + bb.set(m_Box); bb.xform(parent); - if (!::Render->occ_visible(bb)) return; + if (!::Render->occ_visible(bb)) + return; // render - RCache.set_xform_world(parent); - if (s){ + RCache.set_xform_world(parent); + if (s) + { SurfFacesPairIt sp_it = m_SurfFaces.find(s); - if (sp_it!=m_SurfFaces.end()) RenderList(parent,color,false,sp_it->second); - }else{ - EDevice.SetRS(D3DRS_TEXTUREFACTOR, color); - for (RBMapPairIt p_it=m_RenderBuffers->begin(); p_it!=m_RenderBuffers->end(); p_it++){ - RBVector& rb_vec = p_it->second; - for (RBVecIt rb_it=rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) - EDevice.DP(D3DPT_TRIANGLELIST,rb_it->pGeom,0,rb_it->dwNumVertex/3); + if (sp_it!=m_SurfFaces.end()) + RenderList(parent, color, false, sp_it->second); + } + else + { + EDevice.SetRS(D3DRS_TEXTUREFACTOR, color); + for (RBMapPairIt p_it = m_RenderBuffers->begin(); p_it!=m_RenderBuffers->end(); p_it++) + { + RBVector &rb_vec = p_it->second; + for (RBVecIt rb_it = rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) + EDevice.DP(D3DPT_TRIANGLELIST, rb_it->pGeom, 0, rb_it->dwNumVertex/3); } - EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); + EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); } } + //---------------------------------------------------- -void CEditableMesh::RenderEdge(const Fmatrix& parent, CSurface* s, u32 color) +void CEditableMesh::RenderEdge(const Fmatrix &parent, CSurface *s, u32 color) { - if (0==m_RenderBuffers) GenerateRenderBuffers(); -// if (!m_Visible) return; - RCache.set_xform_world(parent); - EDevice.SetShader(EDevice.m_WireShader); - EDevice.RenderNearer(0.001); + if (0==m_RenderBuffers) + GenerateRenderBuffers(); + // if (!m_Visible) return; + RCache.set_xform_world(parent); + EDevice.SetShader(EDevice.m_WireShader); + EDevice.RenderNearer(0.001); // render - EDevice.SetRS(D3DRS_FILLMODE,D3DFILL_WIREFRAME); - if (s){ + EDevice.SetRS(D3DRS_FILLMODE, D3DFILL_WIREFRAME); + if (s) + { SurfFacesPairIt sp_it = m_SurfFaces.find(s); - if (sp_it!=m_SurfFaces.end()) RenderList(parent,color,true,sp_it->second); - }else{ - EDevice.SetRS(D3DRS_TEXTUREFACTOR, color); - for (RBMapPairIt p_it=m_RenderBuffers->begin(); p_it!=m_RenderBuffers->end(); p_it++){ - RBVector& rb_vec = p_it->second; - for (RBVecIt rb_it=rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) - EDevice.DP(D3DPT_TRIANGLELIST,rb_it->pGeom,0,rb_it->dwNumVertex/3); + if (sp_it!=m_SurfFaces.end()) + RenderList(parent, color, true, sp_it->second); + } + else + { + EDevice.SetRS(D3DRS_TEXTUREFACTOR, color); + for (RBMapPairIt p_it = m_RenderBuffers->begin(); p_it!=m_RenderBuffers->end(); p_it++) + { + RBVector &rb_vec = p_it->second; + for (RBVecIt rb_it = rb_vec.begin(); rb_it!=rb_vec.end(); rb_it++) + EDevice.DP(D3DPT_TRIANGLELIST, rb_it->pGeom, 0, rb_it->dwNumVertex/3); } - EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); + EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); } - EDevice.SetRS(D3DRS_FILLMODE,EDevice.dwFillMode); + EDevice.SetRS(D3DRS_FILLMODE, EDevice.dwFillMode); EDevice.ResetNearer(); } + //---------------------------------------------------- #define SKEL_MAX_FACE_COUNT 10000 + struct svertRender { - Fvector P; - Fvector N; - Fvector2 uv; + Fvector P; + Fvector N; + Fvector2 uv; }; -void CEditableMesh::RenderSkeleton(const Fmatrix&, CSurface* S) + +void CEditableMesh::RenderSkeleton(const Fmatrix &, CSurface *S) { if (false==IsGeneratedSVertices(RENDER_SKELETON_LINKS)) - GenerateSVertices(RENDER_SKELETON_LINKS); - - R_ASSERT2(m_SVertices,"SVertices empty!"); - SurfFacesPairIt sp_it = m_SurfFaces.find(S); R_ASSERT(sp_it!=m_SurfFaces.end()); - IntVec& face_lst = sp_it->second; - _VertexStream* Stream = &RCache.Vertex; - u32 vBase; - - svertRender* pv = (svertRender*)Stream->Lock(SKEL_MAX_FACE_COUNT*3,m_Parent->vs_SkeletonGeom->vb_stride,vBase); - Fvector P0,N0,P1,N1; - - int f_cnt=0; - for (IntIt i_it=face_lst.begin(); i_it!=face_lst.end(); i_it++) + GenerateSVertices(RENDER_SKELETON_LINKS); + + R_ASSERT2(m_SVertices, "SVertices empty!"); + SurfFacesPairIt sp_it = m_SurfFaces.find(S); + R_ASSERT(sp_it!=m_SurfFaces.end()); + IntVec &face_lst = sp_it->second; + _VertexStream *Stream = &RCache.Vertex; + u32 vBase; + + svertRender *pv = (svertRender*)Stream->Lock(SKEL_MAX_FACE_COUNT*3, m_Parent->vs_SkeletonGeom->vb_stride, vBase); + Fvector P0, N0, P1, N1; + + int f_cnt = 0; + for (IntIt i_it = face_lst.begin(); i_it!=face_lst.end(); i_it++) { - for (int k=0; k<3; k++,pv++) + for (int k = 0; k<3; k++,pv++) { - st_SVert& SV = m_SVertices[*i_it*3+k]; - pv->uv.set (SV.uv); - float total = SV.bones[0].w; + st_SVert&SV = m_SVertices[*i_it*3+k]; + pv->uv.set(SV.uv); + float total = SV.bones[0].w; - const Fmatrix& M = m_Parent->m_Bones[SV.bones[0].id]->_RenderTransform(); - M.transform_tiny (pv->P,SV.offs); - M.transform_dir (pv->N,SV.norm); + const Fmatrix &M = m_Parent->m_Bones[SV.bones[0].id]->_RenderTransform(); + M.transform_tiny(pv->P, SV.offs); + M.transform_dir(pv->N, SV.norm); - Fvector P,N; + Fvector P, N; - for (u8 cnt=1; cnt<(u8)SV.bones.size(); cnt++) + for (u8 cnt = 1; cnt<(u8)SV.bones.size(); cnt++) { - total += SV.bones[cnt].w; - const Fmatrix& M = m_Parent->m_Bones[SV.bones[cnt].id]->_RenderTransform(); - M.transform_tiny (P,SV.offs); - M.transform_dir (N,SV.norm); - pv->P.lerp (pv->P,P,SV.bones[cnt].w/total); - pv->N.lerp (pv->N,N,SV.bones[cnt].w/total); + total += SV.bones[cnt].w; + const Fmatrix &M = m_Parent->m_Bones[SV.bones[cnt].id]->_RenderTransform(); + M.transform_tiny(P, SV.offs); + M.transform_dir(N, SV.norm); + pv->P.lerp(pv->P, P, SV.bones[cnt].w/total); + pv->N.lerp(pv->N, N, SV.bones[cnt].w/total); } } f_cnt++; if (S->m_Flags.is(CSurface::sf2Sided)) { - pv->P.set((pv-1)->P); pv->N.invert((pv-1)->N); pv->uv.set((pv-1)->uv); pv++; - pv->P.set((pv-3)->P); pv->N.invert((pv-3)->N); pv->uv.set((pv-3)->uv); pv++; - pv->P.set((pv-5)->P); pv->N.invert((pv-5)->N); pv->uv.set((pv-5)->uv); pv++; - f_cnt++; + pv->P.set((pv-1)->P); + pv->N.invert((pv-1)->N); + pv->uv.set((pv-1)->uv); + pv++; + pv->P.set((pv-3)->P); + pv->N.invert((pv-3)->N); + pv->uv.set((pv-3)->uv); + pv++; + pv->P.set((pv-5)->P); + pv->N.invert((pv-5)->N); + pv->uv.set((pv-5)->uv); + pv++; + f_cnt++; } if (f_cnt>=SKEL_MAX_FACE_COUNT-1) { - Stream->Unlock (f_cnt*3,m_Parent->vs_SkeletonGeom->vb_stride); - EDevice.DP (D3DPT_TRIANGLELIST,m_Parent->vs_SkeletonGeom,vBase,f_cnt); - pv = (svertRender*)Stream->Lock(SKEL_MAX_FACE_COUNT*3,m_Parent->vs_SkeletonGeom->vb_stride,vBase); - f_cnt = 0; + Stream->Unlock(f_cnt*3, m_Parent->vs_SkeletonGeom->vb_stride); + EDevice.DP(D3DPT_TRIANGLELIST, m_Parent->vs_SkeletonGeom, vBase, f_cnt); + pv = (svertRender*)Stream->Lock(SKEL_MAX_FACE_COUNT*3, m_Parent->vs_SkeletonGeom->vb_stride, vBase); + f_cnt = 0; } } - Stream->Unlock (f_cnt*3,m_Parent->vs_SkeletonGeom->vb_stride); - if (f_cnt) - EDevice.DP (D3DPT_TRIANGLELIST,m_Parent->vs_SkeletonGeom,vBase,f_cnt); + Stream->Unlock(f_cnt*3, m_Parent->vs_SkeletonGeom->vb_stride); + if (f_cnt) + EDevice.DP(D3DPT_TRIANGLELIST, m_Parent->vs_SkeletonGeom, vBase, f_cnt); } + //---------------------------------------------------- diff --git a/src/editors/ECore/Editor/EditObject.cpp b/src/editors/ECore/Editor/EditObject.cpp index f366445b5f4..ec14bf6b974 100644 --- a/src/editors/ECore/Editor/EditObject.cpp +++ b/src/editors/ECore/Editor/EditObject.cpp @@ -11,13 +11,13 @@ #include "EditMesh.h" #ifdef _EDITOR - #include "motion.h" - #include "bone.h" - #include "ImageManager.h" +#include "xrCore/Animation/Motion.hpp" +#include "xrCore/Animation/Bone.hpp" +#include "ImageManager.h" #endif // mimimal bounding box size -float g_MinBoxSize = 0.05f; +float g_MinBoxSize = 0.05f; #ifdef _EDITOR void CSurface::CreateImageData() @@ -35,86 +35,91 @@ void CSurface::RemoveImageData() #endif CEditableObject::CEditableObject(LPCSTR name): - m_physics_shell(0), + m_physics_shell(0), m_object_xform(0) { - m_LibName = name; + m_LibName = name; - m_objectFlags.zero (); - m_ObjectVersion = 0; + m_objectFlags.zero(); + m_ObjectVersion = 0; #ifdef _EDITOR vs_SkeletonGeom = 0; #endif - m_BBox.invalidate(); + m_BBox.invalidate(); m_LoadState.zero(); m_ActiveSMotion = 0; - t_vPosition.set (0.f,0.f,0.f); - t_vScale.set (1.f,1.f,1.f); - t_vRotate.set (0.f,0.f,0.f); + t_vPosition.set(0.f, 0.f, 0.f); + t_vScale.set(1.f, 1.f, 1.f); + t_vRotate.set(0.f, 0.f, 0.f); + + a_vPosition.set(0.f, 0.f, 0.f); + a_vRotate.set(0.f, 0.f, 0.f); - a_vPosition.set (0.f,0.f,0.f); - a_vRotate.set (0.f,0.f,0.f); + bOnModified = false; - bOnModified = false; + m_RefCount = 0; - m_RefCount = 0; + m_LODShader = 0; - m_LODShader = 0; - - m_CreateName = "unknown"; - m_CreateTime = 0; - m_ModifName = "unknown"; - m_ModifTime = 0; + m_CreateName = "unknown"; + m_CreateTime = 0; + m_ModifName = "unknown"; + m_ModifTime = 0; } CEditableObject::~CEditableObject() { ClearGeometry(); } + //---------------------------------------------------- void CEditableObject::VerifyMeshNames() { - int idx=0; - string1024 nm,pref; - for(EditMeshIt m_def=m_Meshes.begin();m_def!=m_Meshes.end();m_def++){ - strcpy (pref,(*m_def)->m_Name.size()?(*m_def)->m_Name.c_str():"mesh"); - _Trim (pref); - strcpy (nm,pref); - while (FindMeshByName(nm,*m_def)) - sprintf(nm,"%s%2d",pref,idx++); + int idx = 0; + string1024 nm, pref; + for (EditMeshIt m_def = m_Meshes.begin(); m_def!=m_Meshes.end(); m_def++) + { + strcpy(pref, (*m_def)->m_Name.size() ? (*m_def)->m_Name.c_str() : "mesh"); + _Trim(pref); + strcpy(nm, pref); + while (FindMeshByName(nm, *m_def)) + sprintf(nm, "%s%2d", pref, idx++); (*m_def)->SetName(nm); } } -bool CEditableObject::ContainsMesh(const CEditableMesh* m) +bool CEditableObject::ContainsMesh(const CEditableMesh *m) { VERIFY(m); - for(EditMeshIt m_def=m_Meshes.begin();m_def!=m_Meshes.end();m_def++) - if (m==(*m_def)) return true; + for (EditMeshIt m_def = m_Meshes.begin(); m_def!=m_Meshes.end(); m_def++) + if (m==(*m_def)) + return true; return false; } -CEditableMesh* CEditableObject::FindMeshByName (const char* name, CEditableMesh* Ignore) +CEditableMesh *CEditableObject::FindMeshByName(const char *name, CEditableMesh *Ignore) { - for(EditMeshIt m=m_Meshes.begin();m!=m_Meshes.end();m++) - if ((Ignore!=(*m))&&(stricmp((*m)->Name().c_str(),name)==0)) return (*m); + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + if ((Ignore!=(*m))&&(stricmp((*m)->Name().c_str(), name)==0)) + return (*m); return 0; } -void CEditableObject::ClearGeometry () +void CEditableObject::ClearGeometry() { #ifdef _EDITOR OnDeviceDestroy(); #endif if (!m_Meshes.empty()) - for(EditMeshIt m=m_Meshes.begin(); m!=m_Meshes.end();m++)xr_delete(*m); + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + xr_delete(*m); if (!m_Surfaces.empty()) - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) + for (SurfaceIt s_it = m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) xr_delete(*s_it); m_Meshes.clear(); m_Surfaces.clear(); @@ -131,188 +136,215 @@ void CEditableObject::ClearGeometry () int CEditableObject::GetFaceCount(bool bMatch2Sided, bool bIgnoreOCC) { - int cnt=0; - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) - cnt+=(*m)->GetFaceCount(bMatch2Sided, bIgnoreOCC); - return cnt; + int cnt = 0; + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + cnt += (*m)->GetFaceCount(bMatch2Sided, bIgnoreOCC); + return cnt; } -int CEditableObject::GetSurfFaceCount(const char* surf_name){ - int cnt=0; - CSurface* surf = FindSurfaceByName(surf_name); - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) - cnt+=(*m)->GetSurfFaceCount(surf); - return cnt; +int CEditableObject::GetSurfFaceCount(const char *surf_name) +{ + int cnt = 0; + CSurface*surf = FindSurfaceByName(surf_name); + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + cnt += (*m)->GetSurfFaceCount(surf); + return cnt; } -int CEditableObject::GetVertexCount(){ - int cnt=0; - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) - cnt+=(*m)->GetVertexCount(); - return cnt; +int CEditableObject::GetVertexCount() +{ + int cnt = 0; + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + cnt += (*m)->GetVertexCount(); + return cnt; } void CEditableObject::UpdateBox() { - VERIFY (!m_Meshes.empty()); - EditMeshIt m = m_Meshes.begin(); + VERIFY(!m_Meshes.empty()); + EditMeshIt m = m_Meshes.begin(); m_BBox.invalidate(); - for(; m!=m_Meshes.end(); ++m) - { + for (; m!=m_Meshes.end(); ++m) + { Fbox meshbox; (*m)->GetBox(meshbox); - for(int i=0; i<8; ++i) - { + for (int i = 0; i<8; ++i) + { Fvector pt; meshbox.getpoint(i, pt); m_BBox.modify(pt); } } } + //---------------------------------------------------- -void CEditableObject::RemoveMesh(CEditableMesh* mesh){ - EditMeshIt m_it = std::find(m_Meshes.begin(),m_Meshes.end(),mesh); +void CEditableObject::RemoveMesh(CEditableMesh *mesh) +{ + EditMeshIt m_it = std::find(m_Meshes.begin(), m_Meshes.end(), mesh); VERIFY(m_it!=m_Meshes.end()); - m_Meshes.erase(m_it); + m_Meshes.erase(m_it); xr_delete(mesh); } -void CEditableObject::TranslateToWorld(const Fmatrix& parent) +void CEditableObject::TranslateToWorld(const Fmatrix &parent) { - EditMeshIt m = m_Meshes.begin(); - for(;m!=m_Meshes.end();m++) (*m)->Transform( parent ); + EditMeshIt m = m_Meshes.begin(); + for (; m!=m_Meshes.end(); m++) + (*m)->Transform(parent); #ifdef _EDITOR OnDeviceDestroy(); #endif - UpdateBox(); + UpdateBox(); } -CSurface* CEditableObject::FindSurfaceByName(const char* surf_name, int* s_id){ - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) - if (stricmp((*s_it)->_Name(),surf_name)==0){ if (s_id) *s_id=s_it-m_Surfaces.begin(); return *s_it;} +CSurface *CEditableObject::FindSurfaceByName(const char *surf_name, int *s_id) +{ + for (SurfaceIt s_it = m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) + if (stricmp((*s_it)->_Name(), surf_name)==0) + { + if (s_id) + *s_id = s_it-m_Surfaces.begin(); + return *s_it; + } return 0; } -LPCSTR CEditableObject::GenerateSurfaceName(const char* base_name) +LPCSTR CEditableObject::GenerateSurfaceName(const char *base_name) { - static string1024 nm; - strcpy(nm, base_name); - if (FindSurfaceByName(nm)){ - DWORD idx=0; - do{ - sprintf(nm,"%s_%d",base_name,idx); - idx++; - }while(FindSurfaceByName(nm)); - } - return nm; + static string1024 nm; + strcpy(nm, base_name); + if (FindSurfaceByName(nm)) + { + DWORD idx = 0; + do + { + sprintf(nm, "%s_%d", base_name, idx); + idx++; + } while (FindSurfaceByName(nm)); + } + return nm; } bool CEditableObject::VerifyBoneParts() { - U8Vec b_use(BoneCount(),0); - for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++) - for (int i=0; ibones.size()); i++){ - int idx = FindBoneByNameIdx(bp_it->bones[i].c_str()); - if (idx==-1){ - bp_it->bones.erase(bp_it->bones.begin()+i); - i--; - }else{ - b_use[idx]++; + U8Vec b_use(BoneCount(), 0); + for (BPIt bp_it = m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++) + for (int i = 0; ibones.size()); i++) + { + int idx = FindBoneByNameIdx(bp_it->bones[i].c_str()); + if (idx==-1) + { + bp_it->bones.erase(bp_it->bones.begin()+i); + i--; + } + else + { + b_use[idx]++; } } - for (U8It u_it=b_use.begin(); u_it!=b_use.end(); u_it++) - if (*u_it!=1) return false; + for (U8It u_it = b_use.begin(); u_it!=b_use.end(); u_it++) + if (*u_it!=1) + return false; return true; } -void CEditableObject::PrepareOGFDesc(ogf_desc& desc) +void CEditableObject::PrepareOGFDesc(ogf_desc &desc) { - string512 tmp; - desc.source_file = m_LibName.c_str(); - desc.create_name = m_CreateName.c_str(); - desc.create_time = m_CreateTime; - desc.modif_name = m_ModifName.c_str(); - desc.modif_time = m_ModifTime; - desc.build_name = strconcat(sizeof(tmp),tmp,"\\\\",Core.CompName,"\\",Core.UserName); - ctime (&desc.build_time); + string512 tmp; + desc.source_file = m_LibName.c_str(); + desc.create_name = m_CreateName.c_str(); + desc.create_time = m_CreateTime; + desc.modif_name = m_ModifName.c_str(); + desc.modif_time = m_ModifTime; + desc.build_name = strconcat(sizeof(tmp), tmp, "\\\\", Core.CompName, "\\", Core.UserName); + ctime(&desc.build_time); } void CEditableObject::SetVersionToCurrent(BOOL bCreate, BOOL bModif) { - string512 tmp; - if (bCreate){ - m_CreateName = strconcat(sizeof(tmp),tmp,"\\\\",Core.CompName,"\\",Core.UserName); - m_CreateTime = time(NULL); - } - if (bModif){ - m_ModifName = strconcat(sizeof(tmp),tmp,"\\\\",Core.CompName,"\\",Core.UserName); - m_ModifTime = time(NULL); - } + string512 tmp; + if (bCreate) + { + m_CreateName = strconcat(sizeof(tmp), tmp, "\\\\", Core.CompName, "\\", Core.UserName); + m_CreateTime = time(NULL); + } + if (bModif) + { + m_ModifName = strconcat(sizeof(tmp), tmp, "\\\\", Core.CompName, "\\", Core.UserName); + m_ModifTime = time(NULL); + } } -void CEditableObject::GetFaceWorld(const Fmatrix& parent, CEditableMesh* M, int idx, Fvector* verts) +void CEditableObject::GetFaceWorld(const Fmatrix &parent, CEditableMesh *M, int idx, Fvector *verts) { - const Fvector* PT[3]; - M->GetFacePT(idx, PT); - parent.transform_tiny(verts[0],*PT[0]); - parent.transform_tiny(verts[1],*PT[1]); - parent.transform_tiny(verts[2],*PT[2]); + const Fvector *PT[3]; + M->GetFacePT(idx, PT); + parent.transform_tiny(verts[0], *PT[0]); + parent.transform_tiny(verts[1], *PT[1]); + parent.transform_tiny(verts[2], *PT[2]); } void CEditableObject::Optimize() { - for(EditMeshIt m_def=m_Meshes.begin();m_def!=m_Meshes.end();m_def++){ - (*m_def)->OptimizeMesh (false); - (*m_def)->RebuildVMaps (); + for (EditMeshIt m_def = m_Meshes.begin(); m_def!=m_Meshes.end(); m_def++) + { + (*m_def)->OptimizeMesh(false); + (*m_def)->RebuildVMaps(); } } bool CEditableObject::Validate() { - bool bRes = true; - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) - if (false==(*s_it)->Validate()){ - Msg("!Invalid surface found: Object [%s], Surface [%s].",GetName(),(*s_it)->_Name()); - bRes=false; + bool bRes = true; + for (SurfaceIt s_it = m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) + if (false==(*s_it)->Validate()) + { + Msg("!Invalid surface found: Object [%s], Surface [%s].", GetName(), (*s_it)->_Name()); + bRes = false; } - for(EditMeshIt m_def=m_Meshes.begin();m_def!=m_Meshes.end();m_def++) - if (false==(*m_def)->Validate()){ - Msg("!Invalid mesh found: Object [%s], Mesh [%s].",m_LibName.c_str(),(*m_def)->Name().c_str()); - bRes=false; + for (EditMeshIt m_def = m_Meshes.begin(); m_def!=m_Meshes.end(); m_def++) + if (false==(*m_def)->Validate()) + { + Msg("!Invalid mesh found: Object [%s], Mesh [%s].", m_LibName.c_str(), (*m_def)->Name().c_str()); + bRes = false; } return bRes; } + //---------------------------------------------------------------------------- //#ifdef DEBUG -LPCSTR CEditableObject::LL_BoneName_dbg(u16 ID) +LPCSTR CEditableObject::LL_BoneName_dbg(u16 ID) { - return GetBone( ID )->Name().c_str(); + return GetBone(ID)->Name().c_str(); } //#endif -CBoneInstance& CEditableObject::LL_GetBoneInstance(u16 bone_id) +CBoneInstance &CEditableObject::LL_GetBoneInstance(u16 bone_id) { return *GetBone(bone_id); } -CBoneData& CEditableObject::LL_GetData(u16 bone_id) + +CBoneData &CEditableObject::LL_GetData(u16 bone_id) { - VERIFY(false); - static CBoneData dummy_bone_data(0); - return dummy_bone_data; + VERIFY(false); + static CBoneData dummy_bone_data(0); + return dummy_bone_data; } -Fmatrix& CEditableObject::LL_GetTransform_R(u16 bone_id) +Fmatrix &CEditableObject::LL_GetTransform_R(u16 bone_id) { - // VERIFY(false); - // static Fmatrix dummy_matrix; + // VERIFY(false); + // static Fmatrix dummy_matrix; return GetBone(bone_id)->_RenderTransform(); } -Fobb& CEditableObject::LL_GetBox(u16 bone_id) + +Fobb &CEditableObject::LL_GetBox(u16 bone_id) { - VERIFY(false); - static Fobb dummy_box; + VERIFY(false); + static Fobb dummy_box; return dummy_box; } + diff --git a/src/editors/ECore/Editor/EditObject.h b/src/editors/ECore/Editor/EditObject.h index c5e2103ebca..f156e046779 100644 --- a/src/editors/ECore/Editor/EditObject.h +++ b/src/editors/ECore/Editor/EditObject.h @@ -3,33 +3,34 @@ #include "xrCore/Animation/Bone.hpp" #include "xrCore/Animation/Motion.hpp" -#ifdef _EDITOR -# include "xrServerEntities/PropertiesListTypes.h" -# include "xrCore/MaterialLib/GameMtlLib.h" -# include "pick_defs.h" +#ifdef _EDITOR +#include "xrServerEntities/PropertiesListTypes.h" +#include "xrEngine/GameMtlLib.h" +#include "pick_defs.h" #endif -# include "Include/xrRender/kinematics.h" -#include "physicsshellholdereditorbase.h" +#include "Include/xrRender/Kinematics.h" + +#include "PhysicsShellHolderEditorBase.h" //---------------------------------------------------- -struct SRayPickInfo; -class CEditableMesh; -class CFrustum; -class CCustomMotion; -class CBone; -class Shader; -class Mtl; -class CExporter; -class CMayaTranslator; -struct st_ObjectDB; -struct SXRShaderData; -struct ogf_desc; -class CCustomObject; +struct SRayPickInfo; +class CEditableMesh; +class CFrustum; +class CCustomMotion; +class CBone; +class Shader; +class Mtl; +class CExporter; +class CMayaTranslator; +struct st_ObjectDB; +struct SXRShaderData; +struct ogf_desc; +class CCustomObject; #ifndef _EDITOR - class PropValue; - #define ref_shader LPVOID +class PropValue; +#define ref_shader LPVOID #endif #define LOD_SHADER_NAME "details\\lod" @@ -43,48 +44,48 @@ class SSimpleImage; class ECORE_API CSurface { - u32 m_GameMtlID; - ref_shader m_Shader; - enum ERTFlags{ - rtValidShader = (1<<0), - }; -public: - enum EFlags{ - sf2Sided = (1<<0), + u32 m_GameMtlID; + ref_shader m_Shader; + enum ERTFlags{ + rtValidShader = (1<<0), + }; + public: + enum EFlags{ + sf2Sided = (1<<0), }; - shared_str m_Name; - shared_str m_Texture; // - shared_str m_VMap; // - shared_str m_ShaderName; - shared_str m_ShaderXRLCName; - shared_str m_GameMtlName; - Flags32 m_Flags; - u32 m_dwFVF; + shared_str m_Name; + shared_str m_Texture; // + shared_str m_VMap; // + shared_str m_ShaderName; + shared_str m_ShaderXRLCName; + shared_str m_GameMtlName; + Flags32 m_Flags; + u32 m_dwFVF; #ifdef _MAX_EXPORT u32 mid; Mtl* mtl; #endif - Flags32 m_RTFlags; - u32 tag; - SSimpleImage* m_ImageData; -public: - CSurface () - { - m_GameMtlName="default"; - m_ImageData = 0; - m_Shader = 0; - m_RTFlags.zero (); - m_Flags.zero (); - m_dwFVF = 0; + Flags32 m_RTFlags; + u32 tag; + SSimpleImage*m_ImageData; + public: + CSurface() + { + m_GameMtlName = "default"; + m_ImageData = 0; + m_Shader = 0; + m_RTFlags.zero(); + m_Flags.zero(); + m_dwFVF = 0; #ifdef _MAX_EXPORT mtl = 0; mid = 0; #endif - tag = 0; - } - IC bool Validate () + tag = 0; + } + IC bool Validate() { - return (0!=xr_strlen(m_Texture))&&(0!=xr_strlen(m_ShaderName)); + return (0!=xr_strlen(m_Texture))&&(0!=xr_strlen(m_ShaderName)); } #ifdef _EDITOR ~CSurface (){R_ASSERT(!m_Shader);xr_delete(m_ImageData);} @@ -93,27 +94,27 @@ class ECORE_API CSurface IC bool _StrictB2F () {return _Shader()?_Shader()->E[0]->flags.bStrictB2F:false;} IC ref_shader _Shader () {if (!m_RTFlags.is(rtValidShader)) OnDeviceCreate(); return m_Shader;} #endif - IC LPCSTR _Name ()const {return *m_Name;} - IC LPCSTR _ShaderName ()const {return *m_ShaderName;} - IC LPCSTR _GameMtlName ()const {return *m_GameMtlName;} - IC LPCSTR _ShaderXRLCName ()const {return *m_ShaderXRLCName;} - IC LPCSTR _Texture ()const {return *m_Texture;} - IC LPCSTR _VMap ()const {return *m_VMap;} - IC u32 _FVF ()const {return m_dwFVF;} - IC void SetName (LPCSTR name){m_Name=name;} - IC void SetShader (LPCSTR name) - { - R_ASSERT2(name&&name[0],"Empty shader name."); - m_ShaderName=name; + IC LPCSTR _Name()const{return *m_Name;} + IC LPCSTR _ShaderName()const{return *m_ShaderName;} + IC LPCSTR _GameMtlName()const{return *m_GameMtlName;} + IC LPCSTR _ShaderXRLCName()const{return *m_ShaderXRLCName;} + IC LPCSTR _Texture()const{return *m_Texture;} + IC LPCSTR _VMap()const{return *m_VMap;} + IC u32 _FVF()const{return m_dwFVF;} + IC void SetName(LPCSTR name){m_Name = name;} + IC void SetShader(LPCSTR name) + { + R_ASSERT2(name&&name[0], "Empty shader name."); + m_ShaderName = name; #ifdef _EDITOR OnDeviceDestroy(); #endif - } - IC void SetShaderXRLC (LPCSTR name){m_ShaderXRLCName=name;} - IC void SetGameMtl (LPCSTR name){m_GameMtlName=name;} - IC void SetFVF (u32 fvf){m_dwFVF=fvf;} - IC void SetTexture (LPCSTR name){string512 buf; xr_strcpy(buf, sizeof(buf), name); if(strext(buf)) *strext(buf)=0; m_Texture=buf;} - IC void SetVMap (LPCSTR name){m_VMap=name;} + } + IC void SetShaderXRLC(LPCSTR name){m_ShaderXRLCName = name;} + IC void SetGameMtl(LPCSTR name){m_GameMtlName = name;} + IC void SetFVF(u32 fvf){m_dwFVF = fvf;} + IC void SetTexture(LPCSTR name){string512 buf; xr_strcpy(buf, sizeof(buf), name);if(strext(buf))*strext(buf) = 0; m_Texture = buf;} + IC void SetVMap(LPCSTR name){m_VMap = name;} #ifdef _EDITOR IC u32 _GameMtl ()const {return GMLib.GetMaterialID (*m_GameMtlName);} IC void OnDeviceCreate () @@ -133,215 +134,219 @@ class ECORE_API CSurface #endif }; -DEFINE_VECTOR (CSurface*,SurfaceVec,SurfaceIt); -DEFINE_VECTOR (CEditableMesh*,EditMeshVec,EditMeshIt); -DEFINE_VECTOR (COMotion*,OMotionVec,OMotionIt); -DEFINE_VECTOR (CSMotion*,SMotionVec,SMotionIt); +DEFINE_VECTOR(CSurface *, SurfaceVec, SurfaceIt); +DEFINE_VECTOR(CEditableMesh *, EditMeshVec, EditMeshIt); +DEFINE_VECTOR(COMotion *, OMotionVec, OMotionIt); +DEFINE_VECTOR(CSMotion *, SMotionVec, SMotionIt); struct ECORE_API SBonePart{ - shared_str alias; - RStringVec bones; + shared_str alias; + RStringVec bones; }; -DEFINE_VECTOR(SBonePart,BPVec,BPIt); +DEFINE_VECTOR(SBonePart, BPVec, BPIt); -const u32 FVF_SV = D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_NORMAL; +const u32 FVF_SV = D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_NORMAL; class ECORE_API CEditableObject: -public IKinematics, -public CPhysicsShellHolderEditorBase + +public +IKinematics +, +public +CPhysicsShellHolderEditorBase { - friend class CSceneObject; - friend class CEditableMesh; + friend class CSceneObject; + friend class CEditableMesh; friend class TfrmPropertiesEObject; friend class CSector; friend class TUI_ControlSectorAdd; - friend class ELibrary; - friend class TfrmEditLibrary; - friend class MeshExpUtility; + friend class ELibrary; + friend class TfrmEditLibrary; + friend class MeshExpUtility; #ifdef _EDITOR ref_geom vs_SkeletonGeom; #endif -// desc - shared_str m_CreateName; - time_t m_CreateTime; - shared_str m_ModifName; - time_t m_ModifTime; - -// general - xr_string m_ClassScript; - - SurfaceVec m_Surfaces; - EditMeshVec m_Meshes; - - ref_shader m_LODShader; - - // skeleton - BoneVec m_Bones; - SMotionVec m_SMotions; - BPVec m_BoneParts; - CSMotion* m_ActiveSMotion; - CPhysicsShell* m_physics_shell; - Fmatrix* m_object_xform; -public: - SAnimParams m_SMParam; - xr_vector m_SMotionRefs; - shared_str m_LODs; -public: - // options - Flags32 m_objectFlags; - enum{ - eoDynamic = (1<<0), - eoProgressive = (1<<1), - eoUsingLOD = (1<<2), - eoHOM = (1<<3), - eoMultipleUsage = (1<<4), - eoSoundOccluder = (1<<5), - eoHQExport = (1<<6), - eoFORCE32 = u32(-1) - }; - IC BOOL IsDynamic (){return m_objectFlags.is(eoDynamic);} - IC BOOL IsStatic (){return !m_objectFlags.is(eoSoundOccluder)&&!m_objectFlags.is(eoDynamic)&&!m_objectFlags.is(eoHOM)&&!m_objectFlags.is(eoMultipleUsage);} - IC BOOL IsMUStatic (){return !m_objectFlags.is(eoSoundOccluder)&&!m_objectFlags.is(eoDynamic)&&!m_objectFlags.is(eoHOM)&&m_objectFlags.is(eoMultipleUsage);} -private: - // bounding volume - Fbox m_BBox; -public: - // temp variable for actor - Fvector a_vPosition; - Fvector a_vRotate; + // desc + shared_str m_CreateName; + time_t m_CreateTime; + shared_str m_ModifName; + time_t m_ModifTime; - // temp variables for transformation - Fvector t_vPosition; - Fvector t_vScale; - Fvector t_vRotate; + // general + xr_string m_ClassScript; - bool bOnModified; - IC bool IsModified (){return bOnModified;} - IC void Modified (){bOnModified=true;} + SurfaceVec m_Surfaces; + EditMeshVec m_Meshes; - AnsiString m_LoadName; - int m_RefCount; -protected: - int m_ObjectVersion; - - void ClearGeometry (); - - void PrepareBones (); - void DefferedLoadRP (); - void DefferedUnloadRP (); + ref_shader m_LODShader; - void __stdcall OnChangeTransform (PropValue* prop); - void __stdcall OnChangeShader (PropValue* prop); + // skeleton + BoneVec m_Bones; + SMotionVec m_SMotions; + BPVec m_BoneParts; + CSMotion* m_ActiveSMotion; + CPhysicsShell* m_physics_shell; + Fmatrix* m_object_xform; + public: + SAnimParams m_SMParam; + xr_vector m_SMotionRefs; + shared_str m_LODs; + public: + // options + Flags32 m_objectFlags; + enum{ + eoDynamic = (1<<0), + eoProgressive = (1<<1), + eoUsingLOD = (1<<2), + eoHOM = (1<<3), + eoMultipleUsage = (1<<4), + eoSoundOccluder = (1<<5), + eoHQExport = (1<<6), + eoFORCE32 = u32(-1) +}; +IC BOOL IsDynamic (){return m_objectFlags.is(eoDynamic);} +IC BOOL IsStatic (){return !m_objectFlags.is(eoSoundOccluder)&&!m_objectFlags.is(eoDynamic)&&!m_objectFlags.is(eoHOM)&&!m_objectFlags.is(eoMultipleUsage);} +IC BOOL IsMUStatic (){return !m_objectFlags.is(eoSoundOccluder)&&!m_objectFlags.is(eoDynamic)&&!m_objectFlags.is(eoHOM)&&m_objectFlags.is(eoMultipleUsage);} +private: +// bounding volume +Fbox m_BBox; public: - enum{ - LS_RBUFFERS = (1<<0), - }; - Flags32 m_LoadState; +// temp variable for actor +Fvector a_vPosition; +Fvector a_vRotate; - AnsiString m_LibName; -public: - // constructor/destructor methods - CEditableObject (LPCSTR name); - virtual ~CEditableObject (); +// temp variables for transformation +Fvector t_vPosition; +Fvector t_vScale; +Fvector t_vRotate; - LPCSTR GetName (){ return m_LibName.c_str();} +bool bOnModified; +IC bool IsModified (){return bOnModified;} +IC void Modified (){bOnModified=true;} - void SetVersionToCurrent (BOOL bCreate, BOOL bModif); +AnsiString m_LoadName; +int m_RefCount; +protected: +int m_ObjectVersion; - void Optimize (); +void ClearGeometry (); - IC EditMeshIt FirstMesh () {return m_Meshes.begin();} - IC EditMeshIt LastMesh () {return m_Meshes.end();} - IC EditMeshVec& Meshes () {return m_Meshes; } - IC int MeshCount () {return m_Meshes.size();} - IC void AppendMesh (CEditableMesh* M){m_Meshes.push_back(M);} - IC SurfaceVec& Surfaces () {return m_Surfaces;} - IC SurfaceIt FirstSurface () {return m_Surfaces.begin();} - IC SurfaceIt LastSurface () {return m_Surfaces.end();} - IC int SurfaceCount () {return m_Surfaces.size();} - IC int Version () {return m_ObjectVersion;} +void PrepareBones (); +void DefferedLoadRP (); +void DefferedUnloadRP (); - // LOD - xr_string GetLODTextureName (); - LPCSTR GetLODShaderName (){return LOD_SHADER_NAME;} - void GetLODFrame (int frame, Fvector p[4], Fvector2 t[4], const Fmatrix* parent=0); +void __stdcall OnChangeTransform (PropValue* prop); +void __stdcall OnChangeShader (PropValue* prop); +public: +enum{ + LS_RBUFFERS = (1<<0), +}; +Flags32 m_LoadState; - // skeleton - IC BPIt FirstBonePart () {return m_BoneParts.begin();} - IC BPIt LastBonePart () {return m_BoneParts.end();} - IC BPVec& BoneParts () {return m_BoneParts;} - IC int BonePartCount () {return m_BoneParts.size();} - IC BPIt BonePart (CBone* B); - - IC BoneIt FirstBone () {return m_Bones.begin();} - IC BoneIt LastBone () {return m_Bones.end();} - IC BoneVec& Bones () {return m_Bones;} - IC int BoneCount ()const {return m_Bones.size();} - shared_str BoneNameByID (int id); - int GetRootBoneID (); - int PartIDByName (LPCSTR name); - IC CBone* GetBone (u32 idx){VERIFY(idx_LTransform(); } - virtual ICF const Fmatrix& LL_GetTransform(u16 bone_id) const { return GetBone( bone_id )->_LTransform(); } - virtual ICF Fmatrix& LL_GetTransform_R(u16 bone_id); - virtual Fobb& LL_GetBox(u16 bone_id); - virtual void LL_GetBindTransform(xr_vector& matrices) { VERIFY(false); } - virtual int LL_GetBoneGroups(xr_vector >& groups) { VERIFY(false); return 0; } +virtual u16 LL_BoneCount()const { return (u16)BoneCount(); } +virtual u16 LL_VisibleBoneCount() { VERIFY(false); return 0; } +virtual ICF Fmatrix& LL_GetTransform(u16 bone_id) { return GetBone( bone_id )->_LTransform(); } +virtual ICF const Fmatrix& LL_GetTransform(u16 bone_id) const { return GetBone( bone_id )->_LTransform(); } +virtual ICF Fmatrix& LL_GetTransform_R(u16 bone_id); +virtual Fobb& LL_GetBox(u16 bone_id); +virtual void LL_GetBindTransform(xr_vector& matrices) { VERIFY(false); } +virtual int LL_GetBoneGroups(xr_vector >& groups) { VERIFY(false); return 0; } - virtual u16 LL_GetBoneRoot() { u16 root_id = (u16)GetRootBoneID(); VERIFY( root_id < u16(-1) ); return root_id; } - virtual void LL_SetBoneRoot(u16 bone_id) { VERIFY(false); } +virtual u16 LL_GetBoneRoot() { u16 root_id = (u16)GetRootBoneID(); VERIFY( root_id < u16(-1) ); return root_id; } +virtual void LL_SetBoneRoot(u16 bone_id) { VERIFY(false); } - virtual BOOL LL_GetBoneVisible(u16 bone_id) { return TRUE; } - virtual void LL_SetBoneVisible(u16 bone_id, BOOL val, BOOL bRecursive) { VERIFY(false); } - virtual u64 LL_GetBonesVisible() { return u64(-1); } - virtual void LL_SetBonesVisible(u64 mask) { VERIFY(false); } +virtual BOOL LL_GetBoneVisible(u16 bone_id) { return TRUE; } +virtual void LL_SetBoneVisible(u16 bone_id, BOOL val, BOOL bRecursive) { VERIFY(false); } +virtual u64 LL_GetBonesVisible() { return u64(-1); } +virtual void LL_SetBonesVisible(u64 mask) { VERIFY(false); } - // Main functionality - virtual void CalculateBones(BOOL bForceExact = FALSE) { } // Recalculate skeleton - virtual void CalculateBones_Invalidate() { } - virtual void Callback(UpdateCallback C, void* Param) { VERIFY(false); } +// Main functionality +virtual void CalculateBones(BOOL bForceExact = FALSE) { } // Recalculate skeleton +virtual void CalculateBones_Invalidate() { } +virtual void Callback(UpdateCallback C, void* Param) { VERIFY(false); } - // Callback: data manipulation - virtual void SetUpdateCallback(UpdateCallback pCallback) { VERIFY(false); } - virtual void SetUpdateCallbackParam(void* pCallbackParam) { VERIFY(false); } +// Callback: data manipulation +virtual void SetUpdateCallback(UpdateCallback pCallback) { VERIFY(false); } +virtual void SetUpdateCallbackParam(void* pCallbackParam) { VERIFY(false); } - virtual UpdateCallback GetUpdateCallback() { VERIFY(false); return 0; } - virtual void* GetUpdateCallbackParam() { VERIFY(false); return 0; } - //UpdateCallback Update_Callback; - //void* Update_Callback_Param; - virtual IRenderVisual* dcast_RenderVisual() { return 0; } - virtual IKinematicsAnimated* dcast_PKinematicsAnimated() { VERIFY(false); return 0; } +virtual UpdateCallback GetUpdateCallback() { VERIFY(false); return 0; } +virtual void* GetUpdateCallbackParam() { VERIFY(false); return 0; } +//UpdateCallback Update_Callback; +//void* Update_Callback_Param; +virtual IRenderVisual* dcast_RenderVisual() { return 0; } +virtual IKinematicsAnimated* dcast_PKinematicsAnimated() { VERIFY(false); return 0; } - // debug +// debug #ifdef DEBUG virtual void DebugRender (Fmatrix& XFORM) {VERIFY(false);} virtual shared_str getDebugName () {return m_ModifName;} #endif private: - virtual IKinematics* ObjectKinematics () { return this;} +virtual IKinematics* ObjectKinematics () { return this;} }; //---------------------------------------------------- @@ -547,13 +552,3 @@ virtual const IBoneData& GetBoneData(u16 bone_id) const { return #endif /*_INCDEF_EditObject_H_*/ - - - - - - - - - - diff --git a/src/editors/ECore/Editor/EditObjectEditor.cpp b/src/editors/ECore/Editor/EditObjectEditor.cpp index 65eadebe9fb..b929df99e7a 100644 --- a/src/editors/ECore/Editor/EditObjectEditor.cpp +++ b/src/editors/ECore/Editor/EditObjectEditor.cpp @@ -3,67 +3,67 @@ #include "EditObject.h" #include "EditMesh.h" -#include "motion.h" -#include "bone.h" +#include "xrCore/Animation/Motion.hpp" +#include "xrCore/Animation/Bone.hpp" #include "ExportSkeleton.h" #include "ExportObjectOGF.h" -#include "d3dutils.h" +#include "D3DUtils.h" #include "ui_main.h" #include "render.h" -#include "../../xrServerEntities/PropertiesListHelper.h" -#include "ResourceManager.h" +#include "xrServerEntities/PropertiesListHelper.h" +#include "Layers/xrRender/ResourceManager.h" #include "ImageManager.h" -const float tex_w = LOD_SAMPLE_COUNT*LOD_IMAGE_SIZE; -const float tex_h = 1*LOD_IMAGE_SIZE; -const float half_p_x= 0.5f*(1.f/tex_w); -const float half_p_y= 0.5f*(1.f/tex_h); -const float offs_x = 1.f/tex_w; -const float offs_y = 1.f/tex_h; - -static Fvector LOD_pos[4]={ - {-1.0f+offs_x, 1.0f-offs_y, 0.0f}, - { 1.0f-offs_x, 1.0f-offs_y, 0.0f}, - { 1.0f-offs_x,-1.0f+offs_y, 0.0f}, - {-1.0f+offs_x,-1.0f+offs_y, 0.0f} +const float tex_w = LOD_SAMPLE_COUNT*LOD_IMAGE_SIZE; +const float tex_h = 1*LOD_IMAGE_SIZE; +const float half_p_x = 0.5f*(1.f/tex_w); +const float half_p_y = 0.5f*(1.f/tex_h); +const float offs_x = 1.f/tex_w; +const float offs_y = 1.f/tex_h; + +static Fvector LOD_pos[4] = { + {-1.0f+offs_x, 1.0f-offs_y, 0.0f}, + {1.0f-offs_x, 1.0f-offs_y, 0.0f}, + {1.0f-offs_x,-1.0f+offs_y, 0.0f}, + {-1.0f+offs_x,-1.0f+offs_y, 0.0f} }; -static FVF::LIT LOD[4]={ - {{-1.0f, 1.0f, 0.0f}, 0xFFFFFFFF, {0.0f,0.0f}}, // F 0 - {{ 1.0f, 1.0f, 0.0f}, 0xFFFFFFFF, {0.0f,0.0f}}, // F 1 - {{ 1.0f,-1.0f, 0.0f}, 0xFFFFFFFF, {0.0f,0.0f}}, // F 2 - {{-1.0f,-1.0f, 0.0f}, 0xFFFFFFFF, {0.0f,0.0f}}, // F 3 +static FVF::LIT LOD[4] = { + {{-1.0f, 1.0f, 0.0f}, 0xFFFFFFFF,{0.0f,0.0f}}, // F 0 + {{1.0f, 1.0f, 0.0f}, 0xFFFFFFFF,{0.0f,0.0f}}, // F 1 + {{1.0f,-1.0f, 0.0f}, 0xFFFFFFFF,{0.0f,0.0f}}, // F 2 + {{-1.0f,-1.0f, 0.0f}, 0xFFFFFFFF,{0.0f,0.0f}}, // F 3 }; bool CEditableObject::Reload() { - ClearGeometry(); + ClearGeometry(); return Load(m_LoadName.c_str()); } -bool CEditableObject::RayPick(float& dist, const Fvector& S, const Fvector& D, const Fmatrix& inv_parent, SRayPickInfo* pinf) +bool CEditableObject::RayPick(float &dist, const Fvector &S, const Fvector &D, const Fmatrix &inv_parent, SRayPickInfo *pinf) { - bool picked = false; - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) - if( (*m)->RayPick( dist, S, D, inv_parent, pinf ) ) + bool picked = false; + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) + if ((*m)->RayPick(dist, S, D, inv_parent, pinf)) picked = true; - return picked; + return picked; } -void CEditableObject::RayQuery(SPickQuery& pinf) +void CEditableObject::RayQuery(SPickQuery &pinf) { - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) (*m)->RayQuery(pinf); } -void CEditableObject::RayQuery(const Fmatrix& parent, const Fmatrix& inv_parent, SPickQuery& pinf) +void CEditableObject::RayQuery(const Fmatrix &parent, const Fmatrix &inv_parent, SPickQuery &pinf) { - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) (*m)->RayQuery(parent, inv_parent, pinf); } -void CEditableObject::BoxQuery(const Fmatrix& parent, const Fmatrix& inv_parent, SPickQuery& pinf) +void CEditableObject::BoxQuery(const Fmatrix &parent, const Fmatrix &inv_parent, SPickQuery &pinf) { - for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++) + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); m++) (*m)->BoxQuery(parent, inv_parent, pinf); } @@ -85,230 +85,259 @@ bool CEditableObject::BoxPick(CCustomObject* obj, const Fbox& box, const Fmatrix } #endif -extern float ssaLIMIT; -extern float g_fSCREEN; +extern float ssaLIMIT; +extern float g_fSCREEN; static const float ssaLim = 64.f*64.f/(640*480); -void CEditableObject::Render(const Fmatrix& parent, int priority, bool strictB2F){ + +void CEditableObject::Render(const Fmatrix &parent, int priority, bool strictB2F) +{ if (!(m_LoadState.is(LS_RBUFFERS))) - DefferedLoadRP(); + DefferedLoadRP(); - Fvector v; + Fvector v; float r; - Fbox bb; - bb.xform (m_BBox,parent); - bb.getsphere (v,r); + Fbox bb; + bb.xform(m_BBox, parent); + bb.getsphere(v, r); - if (EPrefs->object_flags.is(epoDrawLOD)&&(m_objectFlags.is(eoUsingLOD)&&(CalcSSA(v,r)object_flags.is(epoDrawLOD)&&(m_objectFlags.is(eoUsingLOD)&&(CalcSSA(v, r)_Priority(); + int pr = (*s_it)->_Priority(); bool strict = (*s_it)->_StrictB2F(); - + if ((priority==pr)&&(strictB2F==strict)) { EDevice.SetShader((*s_it)->_Shader()); - for (EditMeshIt _M=m_Meshes.begin(); _M!=m_Meshes.end(); _M++) + for (EditMeshIt _M = m_Meshes.begin(); _M!=m_Meshes.end(); _M++) if (IsSkeleton()) - (*_M)->RenderSkeleton (parent,*s_it); + (*_M)->RenderSkeleton(parent, *s_it); else - (*_M)->Render (parent,*s_it); + (*_M)->Render(parent, *s_it); } } } } } -void CEditableObject::RenderSingle(const Fmatrix& parent) +void CEditableObject::RenderSingle(const Fmatrix &parent) { - for (int i=0; i<4; i++){ - Render(parent, i, false); - Render(parent, i, true); + for (int i = 0; i<4; i++) + { + Render(parent, i, false); + Render(parent, i, true); } } -void CEditableObject::RenderAnimation(const Fmatrix&){ -} +void CEditableObject::RenderAnimation(const Fmatrix &) {} -void CEditableObject::RenderEdge(const Fmatrix& parent, CEditableMesh* mesh, CSurface* surf, u32 color) +void CEditableObject::RenderEdge(const Fmatrix &parent, CEditableMesh *mesh, CSurface *surf, u32 color) { - if (!(m_LoadState.is(LS_RBUFFERS))) DefferedLoadRP(); + if (!(m_LoadState.is(LS_RBUFFERS))) + DefferedLoadRP(); EDevice.SetShader(EDevice.m_WireShader); - if(mesh) mesh->RenderEdge(parent, surf, color); - else for(EditMeshIt _M = m_Meshes.begin();_M!=m_Meshes.end();_M++) + if (mesh) + mesh->RenderEdge(parent, surf, color); + else + for (EditMeshIt _M = m_Meshes.begin(); _M!=m_Meshes.end(); _M++) (*_M)->RenderEdge(parent, surf, color); } -void CEditableObject::RenderSelection(const Fmatrix& parent, CEditableMesh* mesh, CSurface* surf, u32 color) +void CEditableObject::RenderSelection(const Fmatrix &parent, CEditableMesh *mesh, CSurface *surf, u32 color) { - if (!(m_LoadState.is(LS_RBUFFERS))) DefferedLoadRP(); + if (!(m_LoadState.is(LS_RBUFFERS))) + DefferedLoadRP(); RCache.set_xform_world(parent); EDevice.SetShader(EDevice.m_SelectionShader); EDevice.RenderNearer(0.0005); - if(mesh) mesh->RenderSelection(parent, surf, color); - else for(EditMeshIt _M = m_Meshes.begin();_M!=m_Meshes.end();_M++) - (*_M)->RenderSelection(parent, surf, color); + if (mesh) + mesh->RenderSelection(parent, surf, color); + else + for (EditMeshIt _M = m_Meshes.begin(); _M!=m_Meshes.end(); _M++) + (*_M)->RenderSelection(parent, surf, color); EDevice.ResetNearer(); } -IC static void CalculateLODTC(int frame, int w_cnt, int h_cnt, Fvector2& lt, Fvector2& rb) +IC static + +void CalculateLODTC(int frame, int w_cnt, int h_cnt, Fvector2 <, Fvector2 &rb) { - Fvector2 ts; - ts.set (1.f/(float)w_cnt,1.f/(float)h_cnt); - lt.x = (frame%w_cnt+0)*ts.x+half_p_x; - lt.y = (frame/w_cnt+0)*ts.y+half_p_y; - rb.x = (frame%w_cnt+1)*ts.x-half_p_x; - rb.y = (frame/w_cnt+1)*ts.y-half_p_y; + Fvector2 ts; + ts.set(1.f/(float)w_cnt, 1.f/(float)h_cnt); + lt.x = (frame%w_cnt+0)*ts.x+half_p_x; + lt.y = (frame/w_cnt+0)*ts.y+half_p_y; + rb.x = (frame%w_cnt+1)*ts.x-half_p_x; + rb.y = (frame/w_cnt+1)*ts.y-half_p_y; } -void CEditableObject::GetLODFrame(int frame, Fvector p[4], Fvector2 t[4], const Fmatrix* parent) +void CEditableObject::GetLODFrame(int frame, Fvector p[4], Fvector2 t[4], const Fmatrix *parent) { - R_ASSERT(m_objectFlags.is(eoUsingLOD)); - Fvector P,S; - m_BBox.get_CD (P,S); - float r = _max(S.x,S.z);//sqrtf(S.x*S.x+S.z*S.z); - Fmatrix T,matrix,rot; - T.scale (r,S.y,r); + R_ASSERT(m_objectFlags.is(eoUsingLOD)); + Fvector P, S; + m_BBox.get_CD(P, S); + float r = _max(S.x, S.z);//sqrtf(S.x*S.x+S.z*S.z); + Fmatrix T, matrix, rot; + T.scale(r, S.y, r); T.translate_over(P); - if (parent) - T.mulA_43(*parent); + if (parent) + T.mulA_43(*parent); - float angle = frame*(PI_MUL_2/float(LOD_SAMPLE_COUNT)); + float angle = frame*(PI_MUL_2/float(LOD_SAMPLE_COUNT)); rot.rotateY(-angle); - matrix.mul(T,rot); + matrix.mul(T, rot); Fvector2 lt, rb; - CalculateLODTC(frame,LOD_SAMPLE_COUNT,1,lt,rb); + CalculateLODTC(frame,LOD_SAMPLE_COUNT, 1, lt, rb); t[0].set(lt); - t[1].set(rb.x,lt.y); + t[1].set(rb.x, lt.y); t[2].set(rb); - t[3].set(lt.x,rb.y); - matrix.transform_tiny(p[0],LOD_pos[0]); - matrix.transform_tiny(p[1],LOD_pos[1]); - matrix.transform_tiny(p[2],LOD_pos[2]); - matrix.transform_tiny(p[3],LOD_pos[3]); + t[3].set(lt.x, rb.y); + matrix.transform_tiny(p[0], LOD_pos[0]); + matrix.transform_tiny(p[1], LOD_pos[1]); + matrix.transform_tiny(p[2], LOD_pos[2]); + matrix.transform_tiny(p[3], LOD_pos[3]); } -void CEditableObject::RenderLOD(const Fmatrix& parent) +void CEditableObject::RenderLOD(const Fmatrix &parent) { Fvector C; - C.sub (parent.c,EDevice.m_Camera.GetPosition()); C.y = 0; - float m = C.magnitude(); - if (mmax_dot){ - max_dot = dot; + if (dot>max_dot) + { + max_dot = dot; max_frame = frame; } } - { - Fvector p[4]; - Fvector2 t[4]; - GetLODFrame(max_frame,p,t); - for (int i=0; i<4; i++){ LOD[i].p.set(p[i]); LOD[i].t.set(t[i]); } - RCache.set_xform_world(parent); - EDevice.SetShader (m_LODShader?m_LODShader:EDevice.m_WireShader); - DU_impl.DrawPrimitiveLIT (D3DPT_TRIANGLEFAN, 2, LOD, 4, true, false); + { + Fvector p[4]; + Fvector2 t[4]; + GetLODFrame(max_frame, p, t); + for (int i = 0; i<4; i++) + { + LOD[i].p.set(p[i]); + LOD[i].t.set(t[i]); + } + RCache.set_xform_world(parent); + EDevice.SetShader(m_LODShader ? m_LODShader : EDevice.m_WireShader); + DU_impl.DrawPrimitiveLIT(D3DPT_TRIANGLEFAN, 2, LOD, 4, true, false); } } xr_string CEditableObject::GetLODTextureName() { - string512 nm; strcpy (nm,m_LibName.c_str()); _ChangeSymbol(nm,'\\','_'); - xr_string l_name; - l_name = xr_string("lod_")+nm; + string512 nm; + strcpy(nm, m_LibName.c_str()); + _ChangeSymbol(nm, '\\', '_'); + xr_string l_name; + l_name = xr_string("lod_")+nm; return ImageLib.UpdateFileName(l_name); } -void CEditableObject::OnDeviceCreate() -{ -} +void CEditableObject::OnDeviceCreate() {} void CEditableObject::OnDeviceDestroy() { - DefferedUnloadRP(); + DefferedUnloadRP(); } void CEditableObject::DefferedLoadRP() { - if (m_LoadState.is(LS_RBUFFERS)) return; + if (m_LoadState.is(LS_RBUFFERS)) + return; // skeleton - if (IsSkeleton()) - vs_SkeletonGeom.create(FVF_SV,RCache.Vertex.Buffer(),RCache.Index.Buffer()); + if (IsSkeleton()) + vs_SkeletonGeom.create(FVF_SV, RCache.Vertex.Buffer(), RCache.Index.Buffer()); -//*/ - // создать LOD shader - xr_string l_name = GetLODTextureName(); + //*/ + // создать LOD shader + xr_string l_name = GetLODTextureName(); xr_string fname = xr_string(l_name)+xr_string(".dds"); m_LODShader.destroy(); -// if (FS.exist(_game_textures_,fname.c_str())) + // if (FS.exist(_game_textures_,fname.c_str())) if (m_objectFlags.is(eoUsingLOD)) - m_LODShader.create(GetLODShaderName(),l_name.c_str()); - m_LoadState.set(LS_RBUFFERS,TRUE); + m_LODShader.create(GetLODShaderName(), l_name.c_str()); + m_LoadState.set(LS_RBUFFERS, TRUE); } + void CEditableObject::DefferedUnloadRP() { - if (!(m_LoadState.is(LS_RBUFFERS))) return; + if (!(m_LoadState.is(LS_RBUFFERS))) + return; // skeleton - vs_SkeletonGeom.destroy(); + vs_SkeletonGeom.destroy(); // удалить буфера - for (EditMeshIt _M=m_Meshes.begin(); _M!=m_Meshes.end(); _M++) - if (*_M) (*_M)->GenerateRenderBuffers(); - // удалить shaders - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) + for (EditMeshIt _M = m_Meshes.begin(); _M!=m_Meshes.end(); _M++) + if (*_M) + (*_M)->GenerateRenderBuffers(); + // удалить shaders + for (SurfaceIt s_it = m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) (*s_it)->OnDeviceDestroy(); // LOD m_LODShader.destroy(); - m_LoadState.set(LS_RBUFFERS,FALSE); + m_LoadState.set(LS_RBUFFERS, FALSE); } + void CEditableObject::EvictObject() { - EditMeshIt m = m_Meshes.begin(); - for(;m!=m_Meshes.end();m++){ - (*m)->UnloadCForm (); - (*m)->UnloadVNormals (true); - (*m)->UnloadSVertices (true); - (*m)->UnloadFNormals (true); + EditMeshIt m = m_Meshes.begin(); + for (; m!=m_Meshes.end(); m++) + { + (*m)->UnloadCForm(); + (*m)->UnloadVNormals(true); + (*m)->UnloadSVertices(true); + (*m)->UnloadFNormals(true); } - DefferedUnloadRP (); + DefferedUnloadRP(); } //bool CEditableObject::PrepareOGF(IWriter& F, u8 infl, bool gen_tb, CEditableMesh* mesh) @@ -353,33 +382,39 @@ void CEditableObject::EvictObject() //} //--------------------------------------------------------------------------- -void __fastcall CEditableObject::OnChangeTransform(PropValue*) +void __fastcall CEditableObject::OnChangeTransform(PropValue *) { - UI->RedrawScene(); + UI->RedrawScene(); } + //--------------------------------------------------------------------------- -//. #include "../../xrEngine/blenders/Blender.h" -IC BOOL BE (BOOL A, BOOL B) +//#include "Layers/xrRender/blenders/Blender.h" +IC BOOL BE(BOOL A, BOOL B) { bool a = !!A; bool b = !!B; return a==b; } + bool CEditableObject::CheckShaderCompatible() { - bool bRes = true; - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) + bool bRes = true; + for (SurfaceIt s_it = m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) { - IBlender* B = EDevice.Resources->_FindBlender(*(*s_it)->m_ShaderName); - Shader_xrLC* C = EDevice.ShaderXRLC.Get(*(*s_it)->m_ShaderXRLCName); - if (!B||!C){ - ELog.Msg (mtError,"Object '%s': invalid or missing shader [E:'%s', C:'%s']",GetName(),(*s_it)->_ShaderName(),(*s_it)->_ShaderXRLCName()); - bRes = false; - }else{ - if (!BE(B->canBeLMAPped(),!C->flags.bLIGHT_Vertex)){ - ELog.Msg (mtError,"Object '%s': engine shader '%s' non compatible with compiler shader '%s'",GetName(),(*s_it)->_ShaderName(),(*s_it)->_ShaderXRLCName()); - bRes = false; + IBlender *B = EDevice.Resources->_FindBlender(*(*s_it)->m_ShaderName); + Shader_xrLC *C = EDevice.ShaderXRLC.Get(*(*s_it)->m_ShaderXRLCName); + if (!B||!C) + { + ELog.Msg(mtError, "Object '%s': invalid or missing shader [E:'%s', C:'%s']", GetName(), (*s_it)->_ShaderName(), (*s_it)->_ShaderXRLCName()); + bRes = false; + } + else + { + if (!BE(B->canBeLMAPped(), !C->flags.bLIGHT_Vertex)) + { + ELog.Msg(mtError, "Object '%s': engine shader '%s' non compatible with compiler shader '%s'", GetName(), (*s_it)->_ShaderName(), (*s_it)->_ShaderXRLCName()); + bRes = false; } } } @@ -468,58 +503,57 @@ void CEditableObject::DeleteBone(CBone* bone) #endif //--------------------------------------------------------------------------- -BPIt CEditableObject::BonePart(CBone* B) +BPIt CEditableObject::BonePart(CBone *B) { - BPIt it = FirstBonePart(); - BPIt it_e = LastBonePart(); - for( ;it!=it_e; ++it) + BPIt it = FirstBonePart(); + BPIt it_e = LastBonePart(); + for (; it!=it_e; ++it) { - RStringVec::iterator iit = (*it).bones.begin(); - RStringVec::iterator iit_e = (*it).bones.end(); - for( ;iit!=iit_e; ++iit) + RStringVec::iterator iit = (*it).bones.begin(); + RStringVec::iterator iit_e = (*it).bones.end(); + for (; iit!=iit_e; ++iit) { - if(*iit==B->Name()) - return it; + if (*iit==B->Name()) + return it; } } return it_e; } -void CEditableObject::RenameBone(CBone* bone, LPCSTR new_name) +void CEditableObject::RenameBone(CBone *bone, LPCSTR new_name) { - BPIt bpit = BonePart(bone); - RStringVec::iterator iit = (*bpit).bones.begin(); - RStringVec::iterator iit_e = (*bpit).bones.end(); + BPIt bpit = BonePart(bone); + RStringVec::iterator iit = (*bpit).bones.begin(); + RStringVec::iterator iit_e = (*bpit).bones.end(); - for( ;iit!=iit_e; ++iit) + for (; iit!=iit_e; ++iit) { - if(*iit==bone->Name()) + if (*iit==bone->Name()) { *iit = new_name; break; } } - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); ++b_it) + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); ++b_it) { - CBone* B = *b_it; - if(B->ParentName()==bone->Name()) - B->SetParentName(new_name); + CBone *B = *b_it; + if (B->ParentName()==bone->Name()) + B->SetParentName(new_name); } - for (SMotionIt s_it=m_SMotions.begin(); s_it!=m_SMotions.end(); ++s_it) + for (SMotionIt s_it = m_SMotions.begin(); s_it!=m_SMotions.end(); ++s_it) { - CSMotion* M = *s_it; - for(BoneMotionIt bm_it=M->BoneMotions().begin(); bm_it!=M->BoneMotions().end(); ++bm_it) + CSMotion *M = *s_it; + for (BoneMotionIt bm_it = M->BoneMotions().begin(); bm_it!=M->BoneMotions().end(); ++bm_it) { - if(bm_it->name == bone->Name()) + if (bm_it->name==bone->Name()) bm_it->name = new_name; } - } - bone->SetName(new_name); - + bone->SetName(new_name); + Modified(); } diff --git a/src/editors/ECore/Editor/EditObjectIO.cpp b/src/editors/ECore/Editor/EditObjectIO.cpp index c30597a7508..4e12222bfb1 100644 --- a/src/editors/ECore/Editor/EditObjectIO.cpp +++ b/src/editors/ECore/Editor/EditObjectIO.cpp @@ -10,11 +10,11 @@ #include "xrCore/Animation/Bone.hpp" #include "xrCore/Animation/Motion.hpp" - #include "exportskeleton.h" - #include "exportobjectOGF.h" +#include "exportskeleton.h" +#include "exportobjectOGF.h" #ifdef _EDITOR - #include "Shader.h" +#include "Layers/xrRender/Shader.h" bool CEditableObject::Load(const char* fname) { @@ -38,165 +38,167 @@ bool CEditableObject::Load(const char* fname) } #endif -bool CEditableObject::Save(const char* fname) +bool CEditableObject::Save(const char *fname) { - if (IsModified()) - { + if (IsModified()) + { // update transform matrix - Fmatrix mTransform, mScale, mTranslate, mRotate; - if ( !fsimilar(t_vRotate.magnitude(),0)|| - !fsimilar(t_vScale.magnitude(),1.73205f)|| - !fsimilar(t_vPosition.magnitude(),0)) + Fmatrix mTransform, mScale, mTranslate, mRotate; + if (!fsimilar(t_vRotate.magnitude(), 0)|| + !fsimilar(t_vScale.magnitude(), 1.73205f)|| + !fsimilar(t_vPosition.magnitude(), 0)) { - mRotate.setHPB (t_vRotate.y, t_vRotate.x, t_vRotate.z); - mScale.scale (t_vScale); - mTranslate.translate (t_vPosition); - mTransform.mul (mTranslate,mRotate); - mTransform.mulB_43 (mScale); - TranslateToWorld (mTransform); - t_vRotate.set (0,0,0); - t_vPosition.set (0,0,0); - t_vScale.set (1,1,1); + mRotate.setHPB(t_vRotate.y, t_vRotate.x, t_vRotate.z); + mScale.scale(t_vScale); + mTranslate.translate(t_vPosition); + mTransform.mul(mTranslate, mRotate); + mTransform.mulB_43(mScale); + TranslateToWorld(mTransform); + t_vRotate.set(0, 0, 0); + t_vPosition.set(0, 0, 0); + t_vScale.set(1, 1, 1); } } // save object - IWriter* F = FS.w_open(fname); - if (F) - { - F->open_chunk (EOBJ_CHUNK_OBJECT_BODY); - Save (*F); - F->close_chunk (); - - FS.w_close (F); - - m_LoadName = fname; - m_ObjectVersion = (int)FS.get_file_age(fname); - VERIFY3 (m_ObjectVersion>0,"Invalid file age:",fname); - return true; - }else{ - return false; + IWriter *F = FS.w_open(fname); + if (F) + { + F->open_chunk(EOBJ_CHUNK_OBJECT_BODY); + Save(*F); + F->close_chunk(); + + FS.w_close(F); + + m_LoadName = fname; + m_ObjectVersion = (int)FS.get_file_age(fname); + VERIFY3(m_ObjectVersion>0, "Invalid file age:", fname); + return true; + } + else + { + return false; } } -void CEditableObject::Save(IWriter& F) +void CEditableObject::Save(IWriter &F) { - F.open_chunk (EOBJ_CHUNK_VERSION); - F.w_u16 (EOBJ_CURRENT_VERSION); - F.close_chunk (); + F.open_chunk(EOBJ_CHUNK_VERSION); + F.w_u16(EOBJ_CURRENT_VERSION); + F.close_chunk(); - F.open_chunk (EOBJ_CHUNK_CLASSSCRIPT); - F.w_stringZ (m_ClassScript); - F.close_chunk (); + F.open_chunk(EOBJ_CHUNK_CLASSSCRIPT); + F.w_stringZ(m_ClassScript); + F.close_chunk(); - F.open_chunk (EOBJ_CHUNK_LODS); - F.w_stringZ (m_LODs); - F.close_chunk (); + F.open_chunk(EOBJ_CHUNK_LODS); + F.w_stringZ(m_LODs); + F.close_chunk(); - F.w_chunk (EOBJ_CHUNK_FLAGS,&m_objectFlags.flags,sizeof(m_objectFlags.flags)); + F.w_chunk(EOBJ_CHUNK_FLAGS, &m_objectFlags.flags, sizeof(m_objectFlags.flags)); // meshes - F.open_chunk (EOBJ_CHUNK_EDITMESHES); - int count = 0; + F.open_chunk(EOBJ_CHUNK_EDITMESHES); + int count = 0; - for(EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); ++m) - { - F.open_chunk(count); - ++count; + for (EditMeshIt m = m_Meshes.begin(); m!=m_Meshes.end(); ++m) + { + F.open_chunk(count); + ++count; (*m)->SaveMesh(F); F.close_chunk(); } - F.close_chunk (); + F.close_chunk(); - // surfaces - F.open_chunk (EOBJ_CHUNK_SURFACES3); - F.w_u32 (m_Surfaces.size()); + // surfaces + F.open_chunk(EOBJ_CHUNK_SURFACES3); + F.w_u32(m_Surfaces.size()); - for (SurfaceIt sf_it=m_Surfaces.begin(); sf_it!=m_Surfaces.end(); ++sf_it) - { - F.w_stringZ ((*sf_it)->_Name ()); - F.w_stringZ ((*sf_it)->_ShaderName ()); - F.w_stringZ ((*sf_it)->_ShaderXRLCName ()); - F.w_stringZ ((*sf_it)->_GameMtlName ()); - F.w_stringZ ((*sf_it)->_Texture ()); - F.w_stringZ ((*sf_it)->_VMap ()); - F.w_u32 ((*sf_it)->m_Flags.get ()); - F.w_u32 ((*sf_it)->_FVF ()); - F.w_u32 (1); + for (SurfaceIt sf_it = m_Surfaces.begin(); sf_it!=m_Surfaces.end(); ++sf_it) + { + F.w_stringZ((*sf_it)->_Name()); + F.w_stringZ((*sf_it)->_ShaderName()); + F.w_stringZ((*sf_it)->_ShaderXRLCName()); + F.w_stringZ((*sf_it)->_GameMtlName()); + F.w_stringZ((*sf_it)->_Texture()); + F.w_stringZ((*sf_it)->_VMap()); + F.w_u32((*sf_it)->m_Flags.get()); + F.w_u32((*sf_it)->_FVF()); + F.w_u32(1); } - F.close_chunk (); + F.close_chunk(); // bones - if (!m_Bones.empty()){ - F.open_chunk (EOBJ_CHUNK_BONES2); - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); ++b_it) - { - F.open_chunk (b_it-m_Bones.begin()); - (*b_it)->Save (F); - F.close_chunk (); + if (!m_Bones.empty()) + { + F.open_chunk(EOBJ_CHUNK_BONES2); + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); ++b_it) + { + F.open_chunk(b_it-m_Bones.begin()); + (*b_it)->Save(F); + F.close_chunk(); } - F.close_chunk (); + F.close_chunk(); } // skeleton motions if (!m_SMotions.empty()) { - F.open_chunk (EOBJ_CHUNK_SMOTIONS); - F.w_u32 (m_SMotions.size()); - - for (SMotionIt s_it=m_SMotions.begin(); s_it!=m_SMotions.end(); ++s_it) - (*s_it)->Save(F); + F.open_chunk(EOBJ_CHUNK_SMOTIONS); + F.w_u32(m_SMotions.size()); + + for (SMotionIt s_it = m_SMotions.begin(); s_it!=m_SMotions.end(); ++s_it) + (*s_it)->Save(F); - F.close_chunk (); + F.close_chunk(); } // skeleton motions refs if (m_SMotionRefs.size()) { - F.open_chunk (EOBJ_CHUNK_SMOTIONS3); - F.w_u32 (m_SMotionRefs.size()); + F.open_chunk(EOBJ_CHUNK_SMOTIONS3); + F.w_u32(m_SMotionRefs.size()); - for(u32 i=0; ialias); - F.w_u32 (bp_it->bones.size()); - - for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); ++s_it) - F.w_stringZ(s_it->c_str()); + { + F.open_chunk(EOBJ_CHUNK_BONEPARTS2); + F.w_u32(m_BoneParts.size()); + for (BPIt bp_it = m_BoneParts.begin(); bp_it!=m_BoneParts.end(); ++bp_it) + { + F.w_stringZ(bp_it->alias); + F.w_u32(bp_it->bones.size()); + for (RStringVecIt s_it = bp_it->bones.begin(); s_it!=bp_it->bones.end(); ++s_it) + F.w_stringZ(s_it->c_str()); } - F.close_chunk (); + F.close_chunk(); } if (IsDynamic()) - { - F.open_chunk (EOBJ_CHUNK_ACTORTRANSFORM); - F.w_fvector3 (a_vPosition); - F.w_fvector3 (a_vRotate); - F.close_chunk (); + { + F.open_chunk(EOBJ_CHUNK_ACTORTRANSFORM); + F.w_fvector3(a_vPosition); + F.w_fvector3(a_vRotate); + F.close_chunk(); } - F.open_chunk (EOBJ_CHUNK_DESC); - F.w_stringZ (m_CreateName.c_str()); - F.w (&m_CreateTime,sizeof(m_CreateTime)); - F.w_stringZ (m_ModifName.c_str()); - F.w (&m_ModifTime,sizeof(m_ModifTime)); - F.close_chunk (); + F.open_chunk(EOBJ_CHUNK_DESC); + F.w_stringZ(m_CreateName.c_str()); + F.w(&m_CreateTime, sizeof(m_CreateTime)); + F.w_stringZ(m_ModifName.c_str()); + F.w(&m_ModifTime, sizeof(m_ModifTime)); + F.close_chunk(); // set modif desc - SetVersionToCurrent (FALSE, TRUE); + SetVersionToCurrent(FALSE, TRUE); - bOnModified = false; + bOnModified = false; } #if defined(_EDITOR) || defined(_MAYA_EXPORT) @@ -224,7 +226,7 @@ bool CEditableObject::Load(IReader& F) if (F.find_chunk (EOBJ_CHUNK_LODS)) F.r_stringZ (m_LODs); - // surfaces +// surfaces if (F.find_chunk(EOBJ_CHUNK_SURFACES3)) { u32 cnt = F.r_u32(); @@ -280,14 +282,14 @@ bool CEditableObject::Load(IReader& F) (*s_it)->SetShaderXRLC ("default"); } - // surfaces xrlc part +// surfaces xrlc part if(F.find_chunk(EOBJ_CHUNK_SURFACES_XRLC)) for (s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ F.r_stringZ(buf); (*s_it)->SetShaderXRLC(buf.c_str()); } } - // Load meshes +// Load meshes IReader* OBJ = F.open_chunk(EOBJ_CHUNK_EDITMESHES); if(OBJ) { @@ -309,7 +311,7 @@ bool CEditableObject::Load(IReader& F) OBJ->close(); } - // bones +// bones if (bRes){ IReader* B_CHUNK = F.open_chunk(EOBJ_CHUNK_BONES2); if (B_CHUNK) @@ -333,7 +335,7 @@ bool CEditableObject::Load(IReader& F) PrepareBones(); } - // skeleton motions +// skeleton motions if (F.find_chunk(EOBJ_CHUNK_SMOTIONS)) { m_SMotions.resize(F.r_u32()); @@ -347,7 +349,7 @@ bool CEditableObject::Load(IReader& F) m_SMotions.clear(); break; } - // resort bone_mots +// resort bone_mots (*s_it)->SortBonesBySkeleton(m_Bones); } } @@ -377,7 +379,7 @@ bool CEditableObject::Load(IReader& F) } } - // bone parts +// bone parts if (bRes){ if (F.find_chunk(EOBJ_CHUNK_BONEPARTS)){ m_BoneParts.resize(F.r_u32()); @@ -477,4 +479,3 @@ bool CEditableObject::ExportOBJ(LPCSTR fn) //------------------------------------------------------------------------------ #endif - diff --git a/src/editors/ECore/Editor/EditObjectImport.cpp b/src/editors/ECore/Editor/EditObjectImport.cpp index 5cd92aa64ad..b55cdb923cd 100644 --- a/src/editors/ECore/Editor/EditObjectImport.cpp +++ b/src/editors/ECore/Editor/EditObjectImport.cpp @@ -10,15 +10,16 @@ #include "LW_SHADERDEF.h" #include "EditMesh.h" -extern "C" { -#include "utils/LWO/lwo2.h" -}; +extern "C" +{ +#include "utils/LWO/lwo2.h" }; #ifdef _EDITOR - #include "ResourceManager.h" - - extern "C" __declspec(dllimport) lwObject* LWOImportObject(char* filename); - extern "C" __declspec(dllimport) void LWOCloseFile(lwObject* object); +#include "Layers/xrRender/ResourceManager.h" + +#include "xrCore/Platform.h" +extern "C" XR_IMPORT lwObject* LWOImportObject(char* filename); +extern "C" XR_IMPORT void LWOCloseFile(lwObject* object); #endif #ifdef _LW_EXPORT @@ -81,7 +82,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) gmName = "default"; } #endif - // fill texture layers + // fill texture layers u32 textureCount = 0; for (st_lwTexture* Itx = lwSurf->color.tex; Itx; Itx = Itx->next) { @@ -97,7 +98,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) } if (cidx != -1) { - // get textures + // get textures for (st_lwClip* lwClip = lwObj->clip; lwClip; lwClip = lwClip->next) { if (cidx == lwClip->index && lwClip->type == ID_STIL) @@ -115,7 +116,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) string256 textureName; _splitpath(tname, nullptr, nullptr, textureName, nullptr); surf->SetTexture(EFS.AppendFolderToName(textureName, 256, 1, true)); - // get vmap refs + // get vmap refs surf->SetVMap(Itx->param.imap.vmap_name); } } @@ -148,13 +149,13 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) mesh->SetName(lwLayer->name ? lwLayer->name : ""); auto bbox = lwLayer->bbox; mesh->m_Box.set(bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], bbox[5]); - // parse mesh(lwo-layer) data + // parse mesh(lwo-layer) data if (lwLayer->nvmaps == 0) { ELog.DlgMsg(mtError, "Import LWO: Mesh layer must contain UV map!"); goto importFailed; } - // XXX nitrocaster: incompatible with multithreaded import + // XXX nitrocaster: incompatible with multithreaded import static xr_map vmIndices; vmIndices.clear(); int vmIndex = 0; @@ -172,7 +173,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) mesh->m_VMaps.push_back(new st_VMap(lwVmap->name, vmtUV, !!lwVmap->perpoly)); st_VMap* vmap = mesh->m_VMaps.back(); vmap->copyfrom(*lwVmap->val, lwVmap->nverts); - // flip uv + // flip uv for (int uvIndex = 0; uvIndex < vmap->size(); uvIndex++) { Fvector2& uv = vmap->getUV(uvIndex); @@ -202,7 +203,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) case ID_RGBA: ELog.Msg(mtError, "Found 'RGBA' VMAP. Import failed."); goto importFailed; } } - // points + // points mesh->m_VertCount = lwLayer->point.count; mesh->m_Vertices = xr_alloc(mesh->m_VertCount); for (int i = 0; i < lwLayer->point.count; i++) @@ -211,7 +212,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) Fvector& vertex = mesh->m_Vertices[i]; vertex.set(lwPoint.pos); } - // polygons + // polygons mesh->m_FaceCount = lwLayer->polygon.count; mesh->m_Faces = xr_alloc(mesh->m_FaceCount); mesh->m_SmoothGroups = xr_alloc(mesh->m_FaceCount); @@ -235,7 +236,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) mesh->m_VMRefs.push_back(st_VMapPtLst()); st_VMapPtLst& vmPointList = mesh->m_VMRefs.back(); faceVert.vmref = mesh->m_VMRefs.size()-1; - // parse uv-map + // parse uv-map st_lwPoint& lwPoint = lwLayer->point.pt[faceVert.pindex]; if (lwFaceVert.nvmaps == 0 && lwPoint.nvmaps == 0) { @@ -244,7 +245,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) } xr_vector vmPoints; AStringVec names; - // process polys + // process polys for (int j = 0; j < lwFaceVert.nvmaps; j++) { if (lwFaceVert.vm[j].vmap->type != ID_TXUV) @@ -255,7 +256,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) names.push_back(lwFaceVert.vm[j].vmap->name); pt.index = lwFaceVert.vm[j].index; } - // process points + // process points for (int j = 0; j < lwPoint.nvmaps; j++) { if (lwPoint.vm[j].vmap->type != ID_TXUV) @@ -270,7 +271,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) auto cmpFunc = [](const st_VMapPt& a, const st_VMapPt& b) { return a.vmap_index < b.vmap_index; }; std::sort(vmPoints.begin(), vmPoints.end(), cmpFunc); - // parse weight-map + // parse weight-map for (int j = 0; j < lwPoint.nvmaps; j++) { if (lwPoint.vm[j].vmap->type != ID_WGHT) @@ -284,7 +285,7 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) vmPointList.pts = xr_alloc(vmPointList.count); memcpy(vmPointList.pts, &*vmPoints.begin(), vmPointList.count*sizeof(st_VMapPt)); } - // lwPoly.surf->alpha_mode stores reviously saved surface id + // lwPoly.surf->alpha_mode stores reviously saved surface id surfIds[i] = lwPoly.surf->alpha_mode; } for (u32 polyId = 0; polyId < mesh->GetFCount(); polyId++) @@ -311,3 +312,4 @@ bool CEditableObject::ImportLWO(const char* fn, bool optimize) return result; } #endif + diff --git a/src/editors/ECore/Editor/EditObjectMotions.cpp b/src/editors/ECore/Editor/EditObjectMotions.cpp index 7e5b56f1d4f..1777e155997 100644 --- a/src/editors/ECore/Editor/EditObjectMotions.cpp +++ b/src/editors/ECore/Editor/EditObjectMotions.cpp @@ -7,7 +7,7 @@ #include "EditObject.h" #ifdef _EDITOR - #include "ui_main.h" +#include "ui_main.h" #endif #include "xrCore/Animation/Motion.hpp" @@ -16,27 +16,46 @@ #ifdef _EDITOR - #include "SkeletonAnimated.h" - #include "AnimationKeyCalculate.h" +#include "Layers/xrRender/SkeletonAnimated.h" +#include "Layers/xrRender/AnimationKeyCalculate.h" #endif #ifndef _EDITOR - bool check_scale( Fmatrix F ){ return true;} +bool check_scale(Fmatrix F) +{ + return true; +} #endif //---------------------------------------------------- -class fBoneNameEQ { - shared_str name; +class fBoneNameEQ +{ + shared_str name; public: - fBoneNameEQ(shared_str N) : name(N) {}; - IC bool operator() (CBone* B) { return (xr_strcmp(B->Name(),name)==0); } + fBoneNameEQ(shared_str N) : name(N) {}; + + IC + + bool operator()(CBone *B) + { + return (xr_strcmp(B->Name(), name)==0); + } }; -class fBoneWMNameEQ { - shared_str wm_name; + +class fBoneWMNameEQ +{ + shared_str wm_name; public: - fBoneWMNameEQ(shared_str N) : wm_name(N) {}; - IC bool operator() (CBone* B) { return (xr_strcmp(B->WMap(),wm_name)==0); } + fBoneWMNameEQ(shared_str N) : wm_name(N) {}; + + IC + + bool operator()(CBone *B) + { + return (xr_strcmp(B->WMap(), wm_name)==0); + } }; + //---------------------------------------------------- #ifdef _EDITOR extern CBone* bone_to_delete; @@ -55,7 +74,7 @@ void CEditableObject::OnFrame() } m_SMParam.Update(EDevice.fTimeDelta,m_ActiveSMotion->fSpeed,!m_ActiveSMotion->m_Flags.is(esmStopAtEnd)); }else{ - //for (BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) (*b_it)->Reset(); +//for (BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) (*b_it)->Reset(); } CalculateAnimation(m_ActiveSMotion); } @@ -69,8 +88,9 @@ void CEditableObject::OnFrame() void CEditableObject::OnBindTransformChange() { - for(EditMeshIt mesh_it=FirstMesh();mesh_it!=LastMesh();mesh_it++){ - CEditableMesh* MESH = *mesh_it; + for (EditMeshIt mesh_it = FirstMesh(); mesh_it!=LastMesh(); mesh_it++) + { + CEditableMesh*MESH = *mesh_it; MESH->UnloadSVertices(true); } GotoBindPose(); @@ -78,134 +98,142 @@ void CEditableObject::OnBindTransformChange() void CEditableObject::GotoBindPose() { - BoneVec& lst = m_Bones; - for (BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) (*b_it)->Reset(); + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + (*b_it)->Reset(); CalculateAnimation(0); #ifdef _EDITOR UI->RedrawScene(); #endif } -CSMotion* CEditableObject::ResetSAnimation(bool bGotoBindPose) +CSMotion *CEditableObject::ResetSAnimation(bool bGotoBindPose) { - CSMotion* M=m_ActiveSMotion; - SetActiveSMotion(0); + CSMotion *M = m_ActiveSMotion; + SetActiveSMotion(0); if (bGotoBindPose) - GotoBindPose(); + GotoBindPose(); return M; } //---------------------------------------------------- // Skeletal motion //---------------------------------------------------- -static void CalculateAnimBone(CBone* bone, CSMotion* motion, Fmatrix& parent) +static void CalculateAnimBone(CBone *bone, CSMotion *motion, Fmatrix &parent) { - Flags8 flags; flags.zero(); + Flags8 flags; + flags.zero(); if (motion) - flags = motion->GetMotionFlags(bone->SelfID); + flags = motion->GetMotionFlags(bone->SelfID); + + Fmatrix &M = bone->_MTransform(); + Fmatrix &L = bone->_LTransform(); - Fmatrix& M = bone->_MTransform(); - Fmatrix& L = bone->_LTransform(); - - const Fvector& r = bone->_Rotate(); - if( ! bone->callback_overwrite() ) + const Fvector &r = bone->_Rotate(); + if (! bone->callback_overwrite()) { - if ( flags.is(st_BoneMotion::flWorldOrient)){ - M.setXYZi (r.x,r.y,r.z); - M.c.set (bone->_Offset()); - L.mul (parent,M); - L.i.set (M.i); - L.j.set (M.j); - L.k.set (M.k); - - Fmatrix LI; LI.invert(parent); - M.mulA_43 (LI); - }else{ - M.setXYZi (r.x,r.y,r.z); - M.c.set (bone->_Offset()); - L.mul (parent,M); + if (flags.is(st_BoneMotion::flWorldOrient)) + { + M.setXYZi(r.x, r.y, r.z); + M.c.set(bone->_Offset()); + L.mul(parent, M); + L.i.set(M.i); + L.j.set(M.j); + L.k.set(M.k); + + Fmatrix LI; + LI.invert(parent); + M.mulA_43(LI); } - } - if( bone->callback() ) + else + { + M.setXYZi(r.x, r.y, r.z); + M.c.set(bone->_Offset()); + L.mul(parent, M); + } + } + if (bone->callback()) { - bone->callback()( bone ); - M.mul_43( Fmatrix().invert(parent), L ); - // bone->_Offset().set( M.c ); + bone->callback()(bone); + M.mul_43(Fmatrix().invert(parent), L); + // bone->_Offset().set( M.c ); } - bone->_RenderTransform().mul_43(bone->_LTransform(),bone->_RITransform()); + bone->_RenderTransform().mul_43(bone->_LTransform(), bone->_RITransform()); } -static void CalculateAnim(CBone* bone, CSMotion* motion, Fmatrix& parent) -{ - CalculateAnimBone( bone, motion, parent ); +static void CalculateAnim(CBone *bone, CSMotion *motion, Fmatrix &parent) +{ + CalculateAnimBone(bone, motion, parent); // Calculate children - for (BoneIt b_it=bone->children.begin(); b_it!=bone->children.end(); b_it++) - CalculateAnim (*b_it,motion,bone->_LTransform()); + for (BoneIt b_it = bone->children.begin(); b_it!=bone->children.end(); b_it++) + CalculateAnim(*b_it, motion, bone->_LTransform()); } - -static void CalculateRest(CBone* bone, Fmatrix& parent) +static void CalculateRest(CBone *bone, Fmatrix &parent) { - Fmatrix& R = bone->_RTransform(); - R.setXYZi (bone->_RestRotate()); - R.c.set (bone->_RestOffset()); + Fmatrix &R = bone->_RTransform(); + R.setXYZi(bone->_RestRotate()); + R.c.set(bone->_RestOffset()); bone->_LRTransform() = R; - R.mulA_43 (parent); + R.mulA_43(parent); bone->_RITransform().invert(bone->_RTransform()); // Calculate children - for (BoneIt b_it=bone->children.begin(); b_it!=bone->children.end(); b_it++) - CalculateRest (*b_it,bone->_RTransform()); + for (BoneIt b_it = bone->children.begin(); b_it!=bone->children.end(); b_it++) + CalculateRest(*b_it, bone->_RTransform()); } -void CEditableObject::CalculateAnimation(CSMotion* motion) +void CEditableObject::CalculateAnimation(CSMotion *motion) { - if (!m_Bones.empty()) - CalculateAnim(m_Bones.front(),motion,Fidentity); + if (!m_Bones.empty()) + CalculateAnim(m_Bones.front(), motion, Fidentity); } - float CEditableObject::GetBonesBottom() - { - float bottom = FLT_MAX; + +float CEditableObject::GetBonesBottom() +{ + float bottom = FLT_MAX; VERIFY(!m_Bones.empty()); - for (BoneIt b_it=m_Bones.begin()+1; b_it!=m_Bones.end(); b_it++) - if( !(*b_it)->IsRoot() && (*b_it)->_LTransform().c.y < bottom ) - bottom = (*b_it)->_LTransform().c.y; + for (BoneIt b_it = m_Bones.begin()+1; b_it!=m_Bones.end(); b_it++) + if (!(*b_it)->IsRoot()&&(*b_it)->_LTransform().c.y_LTransform().c.y; return bottom; - } +} - static void SetBoneTransform( CBone &bone, const Fmatrix &T, const Fmatrix & parent ) +static void SetBoneTransform(CBone &bone, const Fmatrix &T, const Fmatrix &parent) { - - bone._LTransform() = T; - Fmatrix LI; LI.invert(parent); - bone._MTransform().mul_43( LI, T ); - bone._RenderTransform().mul_43(bone._LTransform(),bone._RITransform()); + bone._LTransform() = T; + Fmatrix LI; + LI.invert(parent); + bone._MTransform().mul_43(LI, T); + bone._RenderTransform().mul_43(bone._LTransform(), bone._RITransform()); } -bool CEditableObject::AnimateRootObject( CSMotion* motion ) -{ - VERIFY( motion ); - if( !motion->m_Flags.test(esmRootMover) ) - return false; - CBone &root_bone = *m_Bones[GetRootBoneID()]; - if( root_bone.children.size() != 1 ) - return false; - return true; +bool CEditableObject::AnimateRootObject(CSMotion *motion) +{ + VERIFY(motion); + if (!motion->m_Flags.test(esmRootMover)) + return false; + CBone &root_bone = *m_Bones[GetRootBoneID()]; + if (root_bone.children.size()!=1) + return false; + return true; } -void CEditableObject::GetAnchorForRootObjectAnimation( Fmatrix &anchor ) + +void CEditableObject::GetAnchorForRootObjectAnimation(Fmatrix &anchor) { - CBone &root_bone = *m_Bones[GetRootBoneID()]; - VERIFY( root_bone .children.size() == 1 ); - CBone &anchor_bone = *root_bone .children[0]; - anchor = anchor_bone._LTransform(); - anchor.invert(); + CBone &root_bone = *m_Bones[GetRootBoneID()]; + VERIFY(root_bone.children.size()==1); + CBone &anchor_bone = *root_bone.children[0]; + anchor = anchor_bone._LTransform(); + anchor.invert(); } + static void AlineYtoGlobalFrame(Fmatrix &in_out_m) { - Fmatrix &m = in_out_m; - + Fmatrix &m = in_out_m; + m.i.y = 0; m.k.y = 0; @@ -213,87 +241,94 @@ static void AlineYtoGlobalFrame(Fmatrix &in_out_m) m.j.y = 1; m.j.z = 0; - float smi = m.i.x * m.i.x + m.i.z * m.i.z; - float smk = m.k.x * m.k.x + m.k.z * m.k.z; - bool bi = smi > EPS_S; - bool bk = smk > EPS_S; - if( smk > smi && bk ) + float smi = m.i.x*m.i.x+m.i.z*m.i.z; + float smk = m.k.x*m.k.x+m.k.z*m.k.z; + bool bi = smi>EPS_S; + bool bk = smk>EPS_S; + if (smk>smi&&bk) { - m.k.mul( 1.f/_sqrt( smk ) ); - m.i.crossproduct( m.j, m.k ); - } else if( bi ) + m.k.mul(1.f/_sqrt(smk)); + m.i.crossproduct(m.j, m.k); + } + else if (bi) { - m.i.mul( 1.f/_sqrt( smi ) ); - m.k.crossproduct( m.i, m.j ); - }else //if( !bi && !bk ) + m.i.mul(1.f/_sqrt(smi)); + m.k.crossproduct(m.i, m.j); + } + else //if( !bi && !bk ) { - //unreal indeed + //unreal indeed m = Fidentity; } -// if ( bi && bk ) - // { - // m.i.mul( 1.f/_sqrt( smi ) ); - // m.k.mul( 1.f/_sqrt( smk ) ); - // } - - if(!check_scale( in_out_m )) - VERIFY( check_scale( in_out_m ) ); + // if ( bi && bk ) + // { + // m.i.mul( 1.f/_sqrt( smi ) ); + // m.k.mul( 1.f/_sqrt( smk ) ); + // } + + if (!check_scale(in_out_m)) + VERIFY(check_scale(in_out_m)); } + void CEditableObject::CalculateRootObjectAnimation(const Fmatrix &anchor) { - float bottom = GetBonesBottom(); - CBone &root_bone = *m_Bones[GetRootBoneID()]; - VERIFY( root_bone .children.size() == 1 ); - CBone &anchor_bone = *root_bone .children[0]; - const Fmatrix gl_anchor = Fmatrix().mul_43( anchor_bone._LTransform(), anchor ); + float bottom = GetBonesBottom(); + CBone &root_bone = *m_Bones[GetRootBoneID()]; + VERIFY(root_bone.children.size()==1); + CBone &anchor_bone = *root_bone.children[0]; + const Fmatrix gl_anchor = Fmatrix().mul_43(anchor_bone._LTransform(), anchor); + + Fmatrix root_transform = gl_anchor;//gl_anchor; + AlineYtoGlobalFrame(root_transform); + + root_transform.c = gl_anchor.c; + root_transform.c.y = bottom; + SetBoneTransform(root_bone, root_transform, Fidentity); - Fmatrix root_transform = gl_anchor;//gl_anchor; - AlineYtoGlobalFrame( root_transform ); + SetBoneTransform(anchor_bone, anchor_bone._LTransform(), root_transform); - root_transform.c = gl_anchor.c; - root_transform.c.y=bottom; - SetBoneTransform( root_bone, root_transform, Fidentity ); - - SetBoneTransform( anchor_bone, anchor_bone._LTransform(), root_transform ); - - // for (BoneIt b_it=root_bone .children.begin(); b_it!=root_bone .children.end(); b_it++) - // SetBoneTransform( *(*b_it), (*(*b_it))._LTransform(), root_transform ); + // for (BoneIt b_it=root_bone .children.begin(); b_it!=root_bone .children.end(); b_it++) + // SetBoneTransform( *(*b_it), (*(*b_it))._LTransform(), root_transform ); } + void CEditableObject::CalculateBindPose() { - if (!m_Bones.empty()) - CalculateRest(m_Bones.front(),Fidentity); + if (!m_Bones.empty()) + CalculateRest(m_Bones.front(), Fidentity); } -void CEditableObject::SetActiveSMotion(CSMotion* mot) +void CEditableObject::SetActiveSMotion(CSMotion *mot) { - m_ActiveSMotion=mot; - if (m_ActiveSMotion) m_SMParam.Set(m_ActiveSMotion); + m_ActiveSMotion = mot; + if (m_ActiveSMotion) + m_SMParam.Set(m_ActiveSMotion); } -bool CEditableObject::RemoveSMotion(const char* name) +bool CEditableObject::RemoveSMotion(const char *name) { - SMotionVec& lst = m_SMotions; - for(SMotionIt m=lst.begin(); m!=lst.end(); m++) - if ((stricmp((*m)->Name(),name)==0)){ - if (m_ActiveSMotion==*m) SetActiveSMotion(0); + SMotionVec &lst = m_SMotions; + for (SMotionIt m = lst.begin(); m!=lst.end(); m++) + if ((stricmp((*m)->Name(), name)==0)) + { + if (m_ActiveSMotion==*m) + SetActiveSMotion(0); xr_delete(*m); - lst.erase(m); + lst.erase(m); return true; } return false; -} +} //--------------------------------------------------------------------------- /* bool CEditableObject::LoadSMotions(const char* fname) { - IReader* F = FS.r_open(fname); + IReader* F = FS.r_open(fname); ClearSMotions(); // object motions m_SMotions.resize(F->r_u32()); - SetActiveSMotion(0); + SetActiveSMotion(0); for (SMotionIt m_it=m_SMotions.begin(); m_it!=m_SMotions.end(); m_it++){ *m_it = xr_new(); if (!(*m_it)->Load(*F)){ @@ -303,80 +338,97 @@ bool CEditableObject::LoadSMotions(const char* fname) FS.r_close(F); return false; } - if (!CheckBoneCompliance(*m_it)){ - ClearSMotions(); + if (!CheckBoneCompliance(*m_it)){ + ClearSMotions(); ELog.DlgMsg(mtError,"Load failed.",fname); xr_delete(&*m_it); FS.r_close(F); return false; } } - FS.r_close(F); - return true; + FS.r_close(F); + return true; } */ -bool CEditableObject::AppendSMotion(LPCSTR fname, SMotionVec* inserted) +bool CEditableObject::AppendSMotion(LPCSTR fname, SMotionVec *inserted) { - VERIFY(IsSkeleton()); + VERIFY(IsSkeleton()); - bool bRes = true; - - LPCSTR ext = strext(fname); - if (0==stricmp(ext,".skl")){ - CSMotion* M = xr_new(); - if (!M->LoadMotion(fname)){ - ELog.Msg(mtError,"Motion '%s' can't load. Append failed.",fname); + bool bRes = true; + + LPCSTR ext = strext(fname); + if (0==stricmp(ext, ".skl")) + { + CSMotion *M = xr_new(); + if (!M->LoadMotion(fname)) + { + ELog.Msg(mtError, "Motion '%s' can't load. Append failed.", fname); xr_delete(M); bRes = false; - }else{ - string256 name; - _splitpath(fname,0,0,name,0); - if (CheckBoneCompliance(M)){ + } + else + { + string256 name; + _splitpath(fname, 0, 0, name, 0); + if (CheckBoneCompliance(M)) + { M->SortBonesBySkeleton(m_Bones); - string256 m_name; - GenerateSMotionName (m_name,name,M); - M->SetName (m_name); + string256 m_name; + GenerateSMotionName(m_name, name, M); + M->SetName(m_name); m_SMotions.push_back(M); - if (inserted) inserted->push_back(M); + if (inserted) + inserted->push_back(M); // optimize - M->Optimize (); - }else{ - ELog.Msg(mtError,"Append failed.",fname); + M->Optimize(); + } + else + { + ELog.Msg(mtError, "Append failed.", fname); xr_delete(M); - bRes = false; + bRes = false; } } - }else if (0==stricmp(ext,".skls")){ - IReader* F = FS.r_open(fname); - if (!F){ - ELog.Msg(mtError,"Can't open file '%s'.",fname); + } + else if (0==stricmp(ext, ".skls")) + { + IReader *F = FS.r_open(fname); + if (!F) + { + ELog.Msg(mtError, "Can't open file '%s'.", fname); bRes = false; - } - if (bRes){ + } + if (bRes) + { // object motions - int cnt = F->r_u32(); - for (int k=0; k(); - if (!M->Load(*F)){ - ELog.Msg(mtError,"Motion '%s' has different version. Load failed.",M->Name()); + int cnt = F->r_u32(); + for (int k = 0; k(); + if (!M->Load(*F)) + { + ELog.Msg(mtError, "Motion '%s' has different version. Load failed.", M->Name()); + xr_delete(M); + bRes = false; + break; + } + if (!CheckBoneCompliance(M)) + { xr_delete(M); bRes = false; break; } - if (!CheckBoneCompliance(M)){ - xr_delete(M); - bRes = false; - break; - } - if (bRes){ + if (bRes) + { M->SortBonesBySkeleton(m_Bones); - string256 m_name; - GenerateSMotionName (m_name,M->Name(),M); - M->SetName (m_name); + string256 m_name; + GenerateSMotionName(m_name, M->Name(), M); + M->SetName(m_name); m_SMotions.push_back(M); - if (inserted) inserted->push_back(M); + if (inserted) + inserted->push_back(M); // optimize - M->Optimize (); + M->Optimize(); } } } @@ -387,172 +439,201 @@ bool CEditableObject::AppendSMotion(LPCSTR fname, SMotionVec* inserted) void CEditableObject::ClearSMotions() { - SetActiveSMotion(0); - for(SMotionIt m_it=m_SMotions.begin(); m_it!=m_SMotions.end();m_it++)xr_delete(*m_it); + SetActiveSMotion(0); + for (SMotionIt m_it = m_SMotions.begin(); m_it!=m_SMotions.end(); m_it++) + xr_delete(*m_it); m_SMotions.clear(); } -bool CEditableObject::SaveSMotions(const char* fname) +bool CEditableObject::SaveSMotions(const char *fname) { - CMemoryWriter F; - F.w_u32 (m_SMotions.size()); - for (SMotionIt m_it=m_SMotions.begin(); m_it!=m_SMotions.end(); m_it++) (*m_it)->Save(F); - return F.save_to(fname); + CMemoryWriter F; + F.w_u32(m_SMotions.size()); + for (SMotionIt m_it = m_SMotions.begin(); m_it!=m_SMotions.end(); m_it++) + (*m_it)->Save(F); + return F.save_to(fname); } -bool CEditableObject::RenameSMotion(const char* old_name, const char* new_name) +bool CEditableObject::RenameSMotion(const char *old_name, const char *new_name) { - if (stricmp(old_name,new_name)==0) return true; - if (FindSMotionByName(new_name)) return false; - CSMotion* M = FindSMotionByName(old_name); VERIFY(M); + if (stricmp(old_name, new_name)==0) + return true; + if (FindSMotionByName(new_name)) + return false; + CSMotion *M = FindSMotionByName(old_name); + VERIFY(M); M->SetName(new_name); return true; } -CSMotion* CEditableObject::FindSMotionByName (const char* name, const CSMotion* Ignore) +CSMotion *CEditableObject::FindSMotionByName(const char *name, const CSMotion *Ignore) { - if (name&&name[0]){ - SMotionVec& lst = m_SMotions; - for(SMotionIt m=lst.begin(); m!=lst.end(); m++) - if ((Ignore!=(*m))&&(stricmp((*m)->Name(),name)==0)) return (*m); + if (name&&name[0]) + { + SMotionVec &lst = m_SMotions; + for (SMotionIt m = lst.begin(); m!=lst.end(); m++) + if ((Ignore!=(*m))&&(stricmp((*m)->Name(), name)==0)) + return (*m); } return 0; } -void CEditableObject::GenerateSMotionName(char* buffer, const char* start_name, const CSMotion* M) +void CEditableObject::GenerateSMotionName(char *buffer, const char *start_name, const CSMotion *M) { - strcpy(buffer,start_name); + strcpy(buffer, start_name); int idx = 0; - while(FindSMotionByName(buffer,M)){ - sprintf( buffer, "%s_%2d", start_name, idx ); - idx++; + while (FindSMotionByName(buffer, M)) + { + sprintf(buffer, "%s_%2d", start_name, idx); + idx++; } strlwr(buffer); } -ICF bool pred_sort_B(CBone* A, CBone* B) +ICF + +bool pred_sort_B(CBone *A, CBone *B) { - return (xr_strcmp(A->Name().c_str(),B->Name().c_str())<0); + return (xr_strcmp(A->Name().c_str(), B->Name().c_str())<0); } -ICF void fill_bones_by_parent(BoneVec& bones,CBone* start) + +ICF + +void fill_bones_by_parent(BoneVec &bones, CBone *start) { - bones.push_back (start); - for (BoneIt b_it=start->children.begin(); b_it!=start->children.end(); b_it++) - fill_bones_by_parent(bones,*b_it); + bones.push_back(start); + for (BoneIt b_it = start->children.begin(); b_it!=start->children.end(); b_it++) + fill_bones_by_parent(bones, *b_it); } + void CEditableObject::PrepareBones() { - if (m_Bones.empty())return; - CBone* PARENT = 0; + if (m_Bones.empty()) + return; + CBone *PARENT = 0; // clear empty parent - BoneIt b_it; - for (b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + BoneIt b_it; + for (b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) { - (*b_it)->children.clear (); - (*b_it)->parent = NULL; - BoneIt parent = std::find_if(m_Bones.begin(),m_Bones.end(),fBoneNameEQ((*b_it)->ParentName())); - if (parent==m_Bones.end()){ - (*b_it)->SetParentName(""); - VERIFY2 (0==PARENT,"Invalid object. Have more than 1 parent."); - PARENT = *b_it; - }else{ - BoneIt parent = std::find_if(m_Bones.begin(),m_Bones.end(),fBoneNameEQ((*b_it)->ParentName())); - CBone* tmp = (parent==m_Bones.end())?0:*parent; - (*b_it)->parent = tmp; + (*b_it)->children.clear(); + (*b_it)->parent = NULL; + BoneIt parent = std::find_if(m_Bones.begin(), m_Bones.end(), fBoneNameEQ((*b_it)->ParentName())); + if (parent==m_Bones.end()) + { + (*b_it)->SetParentName(""); + VERIFY2(0==PARENT, "Invalid object. Have more than 1 parent."); + PARENT = *b_it; + } + else + { + BoneIt parent = std::find_if(m_Bones.begin(), m_Bones.end(), fBoneNameEQ((*b_it)->ParentName())); + CBone *tmp = (parent==m_Bones.end()) ? 0 : *parent; + (*b_it)->parent = tmp; } } // sort by name - std::sort(m_Bones.begin(),m_Bones.end(),pred_sort_B); + std::sort(m_Bones.begin(), m_Bones.end(), pred_sort_B); // fill children - for (b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ - BoneIt parent = std::find_if(m_Bones.begin(),m_Bones.end(),fBoneNameEQ((*b_it)->ParentName())); - if (parent!=m_Bones.end()) (*parent)->children.push_back(*b_it); + for (b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + { + BoneIt parent = std::find_if(m_Bones.begin(), m_Bones.end(), fBoneNameEQ((*b_it)->ParentName())); + if (parent!=m_Bones.end()) + (*parent)->children.push_back(*b_it); } // manual sort - u32 b_cnt = m_Bones.size(); - m_Bones.clear (); - fill_bones_by_parent(m_Bones,PARENT); + u32 b_cnt = m_Bones.size(); + m_Bones.clear(); + fill_bones_by_parent(m_Bones, PARENT); - u32 cnt_new = m_Bones.size(); - VERIFY (b_cnt==cnt_new); + u32 cnt_new = m_Bones.size(); + VERIFY(b_cnt==cnt_new); // update SelfID - for (b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) - (*b_it)->SelfID = b_it-m_Bones.begin(); + for (b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + (*b_it)->SelfID = b_it-m_Bones.begin(); VERIFY(0==m_Bones.front()->parent); -/* - for (b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) - Msg("%20s - %20s",(*b_it)->Name().c_str(),(*b_it)->ParentName().c_str()); -*/ - CalculateBindPose (); + /* + for (b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + Msg("%20s - %20s",(*b_it)->Name().c_str(),(*b_it)->ParentName().c_str()); + */ + CalculateBindPose(); } -BoneIt CEditableObject::FindBoneByNameIt(const char* name) +BoneIt CEditableObject::FindBoneByNameIt(const char *name) { - return std::find_if(m_Bones.begin(),m_Bones.end(),fBoneNameEQ(name)); + return std::find_if(m_Bones.begin(), m_Bones.end(), fBoneNameEQ(name)); } int CEditableObject::FindBoneByNameIdx(LPCSTR name) { - BoneIt b_it = FindBoneByNameIt(name); - return (b_it==m_Bones.end())?-1:b_it-m_Bones.begin(); + BoneIt b_it = FindBoneByNameIt(name); + return (b_it==m_Bones.end()) ? -1 : b_it-m_Bones.begin(); } -CBone* CEditableObject::FindBoneByName(const char* name) +CBone *CEditableObject::FindBoneByName(const char *name) { - BoneIt b_it = FindBoneByNameIt(name); - return (b_it==m_Bones.end())?0:*b_it; + BoneIt b_it = FindBoneByNameIt(name); + return (b_it==m_Bones.end()) ? 0 : *b_it; } int CEditableObject::GetRootBoneID() { - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) - if ((*b_it)->IsRoot()) return b_it-m_Bones.begin(); + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + if ((*b_it)->IsRoot()) + return b_it-m_Bones.begin(); THROW; return -1; } int CEditableObject::PartIDByName(LPCSTR name) { - for (BPIt it=m_BoneParts.begin(); it!=m_BoneParts.end(); it++) - if (it->alias==name) return it-m_BoneParts.begin(); + for (BPIt it = m_BoneParts.begin(); it!=m_BoneParts.end(); it++) + if (it->alias==name) + return it-m_BoneParts.begin(); return -1; -} +} shared_str CEditableObject::BoneNameByID(int id) { - VERIFY((id>=0)&&(id<(int)m_Bones.size())); + VERIFY((id>=0)&&(id<(int)m_Bones.size())); return m_Bones[id]->Name(); } -u16 CEditableObject::GetBoneIndexByWMap(const char* wm_name) +u16 CEditableObject::GetBoneIndexByWMap(const char *wm_name) { - BoneIt bone = std::find_if(m_Bones.begin(),m_Bones.end(),fBoneWMNameEQ(wm_name)); - return (bone==m_Bones.end())?BI_NONE:(u16)(bone-m_Bones.begin()); + BoneIt bone = std::find_if(m_Bones.begin(), m_Bones.end(), fBoneWMNameEQ(wm_name)); + return (bone==m_Bones.end()) ? BI_NONE : (u16)(bone-m_Bones.begin()); } -void CEditableObject::GetBoneWorldTransform(u32 bone_idx, float t, CSMotion* motion, Fmatrix& matrix) +void CEditableObject::GetBoneWorldTransform(u32 bone_idx, float t, CSMotion *motion, Fmatrix &matrix) { - VERIFY(bone_idxParent()?m_Bones[idx]->Parent()->SelfID:-1)>-1); - for (int i=lst.size()-1; i>=0; i--){ - idx = lst[i]; - Flags8 flags = motion->GetMotionFlags(idx); - Fvector T,R; + do + { + lst.push_back(idx); + } while ((idx = m_Bones[idx]->Parent() ? m_Bones[idx]->Parent()->SelfID : -1)>-1); + for (int i = lst.size()-1; i>=0; i--) + { + idx = lst[i]; + Flags8 flags = motion->GetMotionFlags(idx); + Fvector T, R; Fmatrix rot, mat; - motion->_Evaluate(idx,t,T,R); - if (flags.is(st_BoneMotion::flWorldOrient)){ - rot.setXYZi(R.x,R.y,R.z); + motion->_Evaluate(idx, t, T, R); + if (flags.is(st_BoneMotion::flWorldOrient)) + { + rot.setXYZi(R.x, R.y, R.z); mat.identity(); mat.c.set(T); mat.mulA_43(matrix); mat.i.set(rot.i); mat.j.set(rot.j); mat.k.set(rot.k); - }else{ - mat.setXYZi(R.x,R.y,R.z); + } + else + { + mat.setXYZi(R.x, R.y, R.z); mat.c.set(T); mat.mulA_43(matrix); } @@ -560,27 +641,28 @@ void CEditableObject::GetBoneWorldTransform(u32 bone_idx, float t, CSMotion* mot } } -bool CEditableObject::CheckBoneCompliance(CSMotion* M) +bool CEditableObject::CheckBoneCompliance(CSMotion *M) { - VERIFY(M); -/* - BoneMotionVec& lst = M->BoneMotions(); - if (m_Bones.size()!=lst.size()){ - Log ("!Different bone count.\nObject has '%d' bones. Motion has '%d' bones.",m_Bones.size(),lst.size()); - return false; - } - for(BoneMotionIt bm_it=lst.begin(); bm_it!=lst.end(); bm_it++) - if (!FindBoneByName(*bm_it->name)){ - Msg ("!Can't find bone '%s' in object.",bm_it->name); - return false; + VERIFY(M); + /* + BoneMotionVec& lst = M->BoneMotions(); + if (m_Bones.size()!=lst.size()){ + Log ("!Different bone count.\nObject has '%d' bones. Motion has '%d' bones.",m_Bones.size(),lst.size()); + return false; } -*/ - for(BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) - if (!M->FindBoneMotion((*b_it)->Name())) { -// Msg ("!Can't find bone '%s' in motion.",*(*b_it)->Name()); -// return false; - M->add_empty_motion ((*b_it)->Name()); - continue; + for(BoneMotionIt bm_it=lst.begin(); bm_it!=lst.end(); bm_it++) + if (!FindBoneByName(*bm_it->name)){ + Msg ("!Can't find bone '%s' in object.",bm_it->name); + return false; + } + */ + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + if (!M->FindBoneMotion((*b_it)->Name())) + { + // Msg ("!Can't find bone '%s' in motion.",*(*b_it)->Name()); + // return false; + M->add_empty_motion((*b_it)->Name()); + continue; } return true; } @@ -590,13 +672,15 @@ void CEditableObject::OptimizeSMotions() #ifdef _EDITOR SPBItem* pb = UI->ProgressStart(m_SMotions.size(),"Motions optimizing..."); #endif - for (SMotionIt s_it=m_SMotions.begin(); s_it!=m_SMotions.end(); s_it++){ - (*s_it)->Optimize (); + for (SMotionIt s_it = m_SMotions.begin(); s_it!=m_SMotions.end(); s_it++) + { + (*s_it)->Optimize(); #ifdef _EDITOR pb->Inc (); #endif - } + } #ifdef _EDITOR UI->ProgressEnd (pb); #endif } + diff --git a/src/editors/ECore/Editor/EditObjectProps.cpp b/src/editors/ECore/Editor/EditObjectProps.cpp index 085725fe8c0..dea0e3cb862 100644 --- a/src/editors/ECore/Editor/EditObjectProps.cpp +++ b/src/editors/ECore/Editor/EditObjectProps.cpp @@ -4,120 +4,140 @@ #include "EditObject.h" #include "EditMesh.h" #include "ui_main.h" -#include "../../xrServerEntities/PropertiesListHelper.h" -#include "ItemListHelper.h" -#include "motion.h" -#include "bone.h" +#include "xrServerEntities/PropertiesListHelper.h" +#include "editors/xrEProps/ItemListHelper.h" +#include "xrCore/Animation/Motion.hpp" +#include "xrCore/Animation/Bone.hpp" -void CEditableObject::OnChangeShader(PropValue*) +void CEditableObject::OnChangeShader(PropValue *) { - OnDeviceDestroy (); - UI->RedrawScene (); + OnDeviceDestroy(); + UI->RedrawScene(); } + //--------------------------------------------------------------------------- -void CEditableObject::FillSurfaceProps(CSurface* SURF, LPCSTR pref, PropItemVec& items) +void CEditableObject::FillSurfaceProps(CSurface *SURF, LPCSTR pref, PropItemVec &items) { - PropValue* V; - V=PHelper().CreateChoose (items, PrepareKey(pref,"Texture"), &SURF->m_Texture, smTexture); V->OnChangeEvent.bind(this,&CEditableObject::OnChangeShader); - V=PHelper().CreateChoose (items, PrepareKey(pref,"Shader"), &SURF->m_ShaderName,smEShader); V->OnChangeEvent.bind(this,&CEditableObject::OnChangeShader); - V=PHelper().CreateChoose (items, PrepareKey(pref,"Compile"), &SURF->m_ShaderXRLCName,smCShader); - PHelper().CreateChoose (items, PrepareKey(pref,"Game Mtl"), &SURF->m_GameMtlName, smGameMaterial); - V=PHelper().CreateFlag32 (items, PrepareKey(pref,"2 Sided"), &SURF->m_Flags, CSurface::sf2Sided);V->OnChangeEvent.bind(this,&CEditableObject::OnChangeShader); - PHelper().CreateCaption (items, PrepareKey(pref,"Face Count"), shared_str().printf("%d",GetSurfFaceCount(SURF->_Name()))); + PropValue *V; + V = PHelper().CreateChoose(items, PrepareKey(pref, "Texture"), &SURF->m_Texture, smTexture); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeShader); + V = PHelper().CreateChoose(items, PrepareKey(pref, "Shader"), &SURF->m_ShaderName, smEShader); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeShader); + V = PHelper().CreateChoose(items, PrepareKey(pref, "Compile"), &SURF->m_ShaderXRLCName, smCShader); + PHelper().CreateChoose(items, PrepareKey(pref, "Game Mtl"), &SURF->m_GameMtlName, smGameMaterial); + V = PHelper().CreateFlag32(items, PrepareKey(pref, "2 Sided"), &SURF->m_Flags, CSurface::sf2Sided); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeShader); + PHelper().CreateCaption(items, PrepareKey(pref, "Face Count"), shared_str().printf("%d", GetSurfFaceCount(SURF->_Name()))); } + //--------------------------------------------------------------------------- -xr_token ECORE_API eo_type_token[]={ - { "Static", 0}, - { "Dynamic", CEditableObject::eoDynamic}, - { "Progressive Dynamic", CEditableObject::eoDynamic|CEditableObject::eoProgressive}, - { "HOM", CEditableObject::eoHOM}, - { "Multiple Usage", CEditableObject::eoMultipleUsage|CEditableObject::eoUsingLOD}, - { "Sound Occluder", CEditableObject::eoSoundOccluder}, - { 0, 0} +xr_token ECORE_API eo_type_token[] = { + {"Static", 0}, + {"Dynamic", CEditableObject::eoDynamic}, + {"Progressive Dynamic", CEditableObject::eoDynamic|CEditableObject::eoProgressive}, + {"HOM", CEditableObject::eoHOM}, + {"Multiple Usage", CEditableObject::eoMultipleUsage|CEditableObject::eoUsingLOD}, + {"Sound Occluder", CEditableObject::eoSoundOccluder}, + {0, 0} }; -void CEditableObject::FillBasicProps(LPCSTR pref, PropItemVec& items) +void CEditableObject::FillBasicProps(LPCSTR pref, PropItemVec &items) { - PropValue* V=0; - PHelper().CreateCaption (items, PrepareKey(pref,"Reference Name"), m_LibName.c_str()); - PHelper().CreateToken32 (items, PrepareKey(pref,"Object Type"), &m_objectFlags.flags, eo_type_token); - PHelper().CreateCaption (items, PrepareKey(pref,"Version\\Owner Name"), m_CreateName.c_str()); - PHelper().CreateCaption (items, PrepareKey(pref,"Version\\Modif Name"), m_ModifName.c_str()); - PHelper().CreateCaption (items, PrepareKey(pref,"Version\\Creation Time"),Trim(AnsiString(ctime(&m_CreateTime))).c_str()); - PHelper().CreateCaption (items, PrepareKey(pref,"Version\\Modified Time"),Trim(AnsiString(ctime(&m_ModifTime))).c_str()); - V=PHelper().CreateVector (items, PrepareKey(pref,"Transform\\Position"), &t_vPosition, -10000, 10000,0.01,2); V->OnChangeEvent.bind(this,&CEditableObject::OnChangeTransform); - V=PHelper().CreateAngle3 (items, PrepareKey(pref,"Transform\\Rotation"), &t_vRotate, -10000, 10000,0.1,1); V->OnChangeEvent.bind(this,&CEditableObject::OnChangeTransform); - V=PHelper().CreateVector (items, PrepareKey(pref,"Transform\\Scale"), &t_vScale, 0.01, 10000,0.01,2); V->OnChangeEvent.bind(this,&CEditableObject::OnChangeTransform); - V=PHelper().CreateCaption (items, PrepareKey(pref,"Transform\\BBox Min"), shared_str().printf("{%3.2f, %3.2f, %3.2f}",VPUSH(GetBox().min))); - V=PHelper().CreateCaption (items, PrepareKey(pref,"Transform\\BBox Max"), shared_str().printf("{%3.2f, %3.2f, %3.2f}",VPUSH(GetBox().max))); -//. PHelper().CreateChoose (items, PrepareKey(pref,"LOD\\Reference"), &m_LODs, smObject); - PHelper().CreateChoose (items, PrepareKey(pref,"LOD\\Reference"), &m_LODs, smVisual); - - FillSummaryProps (pref,items); + PropValue *V = 0; + PHelper().CreateCaption(items, PrepareKey(pref, "Reference Name"), m_LibName.c_str()); + PHelper().CreateToken32(items, PrepareKey(pref, "Object Type"), &m_objectFlags.flags, eo_type_token); + PHelper().CreateCaption(items, PrepareKey(pref, "Version\\Owner Name"), m_CreateName.c_str()); + PHelper().CreateCaption(items, PrepareKey(pref, "Version\\Modif Name"), m_ModifName.c_str()); + PHelper().CreateCaption(items, PrepareKey(pref, "Version\\Creation Time"), Trim(AnsiString(ctime(&m_CreateTime))).c_str()); + PHelper().CreateCaption(items, PrepareKey(pref, "Version\\Modified Time"), Trim(AnsiString(ctime(&m_ModifTime))).c_str()); + V = PHelper().CreateVector(items, PrepareKey(pref, "Transform\\Position"), &t_vPosition, -10000, 10000, 0.01, 2); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeTransform); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Transform\\Rotation"), &t_vRotate, -10000, 10000, 0.1, 1); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeTransform); + V = PHelper().CreateVector(items, PrepareKey(pref, "Transform\\Scale"), &t_vScale, 0.01, 10000, 0.01, 2); + V->OnChangeEvent.bind(this, &CEditableObject::OnChangeTransform); + V = PHelper().CreateCaption(items, PrepareKey(pref, "Transform\\BBox Min"), shared_str().printf("{%3.2f, %3.2f, %3.2f}", VPUSH(GetBox().min))); + V = PHelper().CreateCaption(items, PrepareKey(pref, "Transform\\BBox Max"), shared_str().printf("{%3.2f, %3.2f, %3.2f}", VPUSH(GetBox().max))); + //. PHelper().CreateChoose (items, PrepareKey(pref,"LOD\\Reference"), &m_LODs, smObject); + PHelper().CreateChoose(items, PrepareKey(pref, "LOD\\Reference"), &m_LODs, smVisual); + + FillSummaryProps(pref, items); } + //--------------------------------------------------------------------------- -void CEditableObject::FillSummaryProps(LPCSTR pref, PropItemVec& items) +void CEditableObject::FillSummaryProps(LPCSTR pref, PropItemVec &items) { - AnsiString t; t.sprintf("V: %d, F: %d", GetVertexCount(),GetFaceCount()); - PHelper().CreateCaption(items,PrepareKey(pref,"Geometry\\Object"),t.c_str()); - for (EditMeshIt m_it=FirstMesh(); m_it!=LastMesh(); m_it++){ - CEditableMesh* MESH=*m_it; - t.sprintf("V: %d, F: %d",MESH->GetVertexCount(),MESH->GetFaceCount()); - PHelper().CreateCaption(items,PrepareKey(pref,AnsiString(AnsiString("Geometry\\Meshes\\")+MESH->Name().c_str()).c_str()),t.c_str()); + AnsiString t; + t.sprintf("V: %d, F: %d", GetVertexCount(), GetFaceCount()); + PHelper().CreateCaption(items, PrepareKey(pref, "Geometry\\Object"), t.c_str()); + for (EditMeshIt m_it = FirstMesh(); m_it!=LastMesh(); m_it++) + { + CEditableMesh*MESH = *m_it; + t.sprintf("V: %d, F: %d", MESH->GetVertexCount(), MESH->GetFaceCount()); + PHelper().CreateCaption(items, PrepareKey(pref, AnsiString(AnsiString("Geometry\\Meshes\\")+MESH->Name().c_str()).c_str()), t.c_str()); } - PHelper().CreateSText(items,PrepareKey(pref, "Game options\\User Data"),&m_ClassScript); + PHelper().CreateSText(items, PrepareKey(pref, "Game options\\User Data"), &m_ClassScript); } + //--------------------------------------------------------------------------- -ECORE_API AnsiString MakeFullBoneName(CBone* bone) +ECORE_API AnsiString MakeFullBoneName(CBone *bone) { - if (bone->Parent()){ - return MakeFullBoneName(bone->Parent())+"\\"+bone->Name().c_str(); - }else{ - return bone->Name().c_str(); + if (bone->Parent()) + { + return MakeFullBoneName(bone->Parent())+"\\"+bone->Name().c_str(); + } + else + { + return bone->Name().c_str(); } } -AnsiString MakeFullBonePath(CBone* bone) +AnsiString MakeFullBonePath(CBone *bone) { - if (bone->Parent()){ - return MakeFullBoneName(bone->Parent()); - }else{ - return ""; - } + if (bone->Parent()) + { + return MakeFullBoneName(bone->Parent()); + } + else + { + return ""; + } } -void CEditableObject::FillSurfaceList(LPCSTR pref, ListItemsVec& items, int modeID) +void CEditableObject::FillSurfaceList(LPCSTR pref, ListItemsVec &items, int modeID) { - SurfaceVec& s_lst = Surfaces(); - if (pref) LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); - for (SurfaceIt s_it=s_lst.begin(); s_it!=s_lst.end(); s_it++) + SurfaceVec &s_lst = Surfaces(); + if (pref) + LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); + for (SurfaceIt s_it = s_lst.begin(); s_it!=s_lst.end(); s_it++) LHelper().CreateItem(items, PrepareKey(pref, (*s_it)->_Name()).c_str(), modeID, 0, *s_it); } + //--------------------------------------------------------------------------- -void CEditableObject::FillBoneList(LPCSTR pref, ListItemsVec& items, int modeID) +void CEditableObject::FillBoneList(LPCSTR pref, ListItemsVec &items, int modeID) { - BoneVec& b_lst = Bones(); - if (pref) LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); - for(BoneIt b_it=b_lst.begin(); b_it!=b_lst.end(); b_it++){ - AnsiString pt = MakeFullBonePath(*b_it); - AnsiString path = pt.IsEmpty()?pref:PrepareKey(pref, pt.c_str()).c_str(); - LHelper().CreateItem(items, PrepareKey(path.c_str(), (*b_it)->Name().c_str()).c_str(), modeID, 0, *b_it); + BoneVec &b_lst = Bones(); + if (pref) + LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); + for (BoneIt b_it = b_lst.begin(); b_it!=b_lst.end(); b_it++) + { + AnsiString pt = MakeFullBonePath(*b_it); + AnsiString path = pt.IsEmpty() ? pref : PrepareKey(pref, pt.c_str()).c_str(); + LHelper().CreateItem(items, PrepareKey(path.c_str(), (*b_it)->Name().c_str()).c_str(), modeID, 0, *b_it); } } -void CEditableObject::FillMotionList(LPCSTR pref, ListItemsVec& items, int modeID) +void CEditableObject::FillMotionList(LPCSTR pref, ListItemsVec &items, int modeID) { - SMotionVec& m_lst = SMotions(); - if (pref) LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); - for (SMotionIt m_it=m_lst.begin(); m_it!=m_lst.end(); m_it++) + SMotionVec &m_lst = SMotions(); + if (pref) + LHelper().CreateItem(items, pref, modeID, ListItem::flSorted); + for (SMotionIt m_it = m_lst.begin(); m_it!=m_lst.end(); m_it++) LHelper().CreateItem(items, PrepareKey(pref, (*m_it)->Name()).c_str(), modeID, 0, *m_it); } - - - \ No newline at end of file diff --git a/src/editors/ECore/Editor/EditObjectSkin.cpp b/src/editors/ECore/Editor/EditObjectSkin.cpp index 4fb3c1dc10d..8de1f1aad7b 100644 --- a/src/editors/ECore/Editor/EditObjectSkin.cpp +++ b/src/editors/ECore/Editor/EditObjectSkin.cpp @@ -7,202 +7,241 @@ #include "EditObject.h" #include "EditMesh.h" -#include "d3dutils.h" -#include "../../xrServerEntities/PropertiesListHelper.h" +#include "D3DUtils.h" +#include "xrServerEntities/PropertiesListHelper.h" -const u32 color_bone_sel_color =0xFFFFFFFF; -const u32 color_bone_norm_color =0xFFFFFF00; -const u32 color_bone_link_color =0xFFA0A000; -const u32 color_bone_sel_cm =0xFFFF0000; -const u32 color_bone_norm_cm =0xFF700000; -const float joint_size =0.025f; +const u32 color_bone_sel_color = 0xFFFFFFFF; +const u32 color_bone_norm_color = 0xFFFFFF00; +const u32 color_bone_link_color = 0xFFA0A000; +const u32 color_bone_sel_cm = 0xFFFF0000; +const u32 color_bone_norm_cm = 0xFF700000; +const float joint_size = 0.025f; void CEditableObject::ResetBones() { - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) - (*b_it)->ResetData(); + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + (*b_it)->ResetData(); } -class fBoneNameEQ { - shared_str name; +class fBoneNameEQ +{ + shared_str name; public: - fBoneNameEQ(shared_str N) : name(N) {}; - IC bool operator() (CBone* B) { return (xr_strcmp(B->Name(),name)==0); } + fBoneNameEQ(shared_str N) : name(N) {}; + + IC + + bool operator()(CBone *B) + { + return (xr_strcmp(B->Name(), name)==0); + } }; -bool CEditableObject::LoadBoneData(IReader& F) +bool CEditableObject::LoadBoneData(IReader &F) { - BoneVec load_bones; - int count=0; - IReader* R; - while(0!=(R=F.open_chunk(count++))) + BoneVec load_bones; + int count = 0; + IReader *R; + while (0!=(R = F.open_chunk(count++))) { - CBone* nBone = xr_new(); - load_bones.push_back(nBone); + CBone *nBone = xr_new(); + load_bones.push_back(nBone); nBone->LoadData(*R); Msg("loaded bone [%s]", nBone->Name().c_str()); } - bool bRes = true; + bool bRes = true; // load bones - if (!load_bones.empty()){ - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ - CBone* B = *b_it; - BoneIt n_it = std::find_if(load_bones.begin(),load_bones.end(),fBoneNameEQ(B->Name())); + if (!load_bones.empty()) + { + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + { + CBone *B = *b_it; + BoneIt n_it = std::find_if(load_bones.begin(), load_bones.end(), fBoneNameEQ(B->Name())); if (n_it!=load_bones.end()) { - B->CopyData (*n_it); - }else{ - ELog.Msg (mtError,"Can't find bone: '%s'.",*(*b_it)->Name()); - bRes = false; -// break; + B->CopyData(*n_it); + } + else + { + ELog.Msg(mtError, "Can't find bone: '%s'.", *(*b_it)->Name()); + bRes = false; + // break; } } - - for (BoneIt n_it=load_bones.begin(); n_it!=load_bones.end(); n_it++) + + for (BoneIt n_it = load_bones.begin(); n_it!=load_bones.end(); n_it++) xr_delete(*n_it); load_bones.clear(); - }else{ - ELog.Msg (mtError,"Empty bone list."); - bRes = false; + } + else + { + ELog.Msg(mtError, "Empty bone list."); + bRes = false; } // load bone part - if (F.find_chunk(EOBJ_CHUNK_BONEPARTS2)){ - shared_str buf; + if (F.find_chunk(EOBJ_CHUNK_BONEPARTS2)) + { + shared_str buf; m_BoneParts.resize(F.r_u32()); - for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++){ - F.r_stringZ (buf); bp_it->alias=buf; - bp_it->bones.resize (F.r_u32()); - for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++) - F.r_stringZ (*s_it); + for (BPIt bp_it = m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++) + { + F.r_stringZ(buf); + bp_it->alias = buf; + bp_it->bones.resize(F.r_u32()); + for (RStringVecIt s_it = bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++) + F.r_stringZ(*s_it); } if (!m_BoneParts.empty()&&!VerifyBoneParts()) - ELog.Msg (mtError,"Invalid bone parts. Found missing or duplicate bone."); - }else{ - ELog.Msg (mtError,"Can't load bone parts. Invalid version."); + ELog.Msg(mtError, "Invalid bone parts. Found missing or duplicate bone."); + } + else + { + ELog.Msg(mtError, "Can't load bone parts. Invalid version."); } return bRes; } -void CEditableObject::SaveBoneData(IWriter& F) +void CEditableObject::SaveBoneData(IWriter &F) { - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ - F.open_chunk (b_it-m_Bones.begin()); - (*b_it)->SaveData (F); - F.close_chunk (); + for (BoneIt b_it = m_Bones.begin(); b_it!=m_Bones.end(); b_it++) + { + F.open_chunk(b_it-m_Bones.begin()); + (*b_it)->SaveData(F); + F.close_chunk(); } // save bone part - F.open_chunk (EOBJ_CHUNK_BONEPARTS2); - F.w_u32 (m_BoneParts.size()); - for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++){ - F.w_stringZ (bp_it->alias.c_str()); - F.w_u32 (bp_it->bones.size()); - for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++) + F.open_chunk(EOBJ_CHUNK_BONEPARTS2); + F.w_u32(m_BoneParts.size()); + for (BPIt bp_it = m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++) + { + F.w_stringZ(bp_it->alias.c_str()); + F.w_u32(bp_it->bones.size()); + for (RStringVecIt s_it = bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++) F.w_stringZ(*s_it); } - F.close_chunk (); + F.close_chunk(); } -void CEditableObject::RenderSkeletonSingle(const Fmatrix& parent) +void CEditableObject::RenderSkeletonSingle(const Fmatrix &parent) { - RenderSingle(parent); + RenderSingle(parent); RenderBones(parent); } -void CEditableObject::RenderBones(const Fmatrix& parent) +void CEditableObject::RenderBones(const Fmatrix &parent) { - if (IsSkeleton()){ + if (IsSkeleton()) + { // render - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++){ - EDevice.SetShader(EDevice.m_WireShader); - RCache.set_xform_world(parent); - Fmatrix& M = (*b_it)->_LTransform(); - Fvector p1 = M.c; - u32 c_joint = (*b_it)->flags.is(CBone::flSelected)?color_bone_sel_color:color_bone_norm_color; + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + { + EDevice.SetShader(EDevice.m_WireShader); + RCache.set_xform_world(parent); + Fmatrix &M = (*b_it)->_LTransform(); + Fvector p1 = M.c; + u32 c_joint = (*b_it)->flags.is(CBone::flSelected) ? color_bone_sel_color : color_bone_norm_color; if (EPrefs->object_flags.is(epoDrawJoints)) - DU_impl.DrawJoint (p1,joint_size,c_joint); + DU_impl.DrawJoint(p1, joint_size, c_joint); // center of mass - if ((*b_it)->shape.type!=SBoneShape::stNone){ + if ((*b_it)->shape.type!=SBoneShape::stNone) + { Fvector cm; - M.transform_tiny(cm,(*b_it)->center_of_mass); - if ((*b_it)->flags.is(CBone::flSelected)){ - float sz = joint_size*2.f; - DU_impl.DrawCross (cm, sz,sz,sz, sz,sz,sz, 0xFFFFFFFF, false); - DU_impl.DrawRomboid (cm,joint_size*0.7f,color_bone_sel_cm); - }else{ - DU_impl.DrawRomboid (cm,joint_size*0.7f,color_bone_norm_cm); + M.transform_tiny(cm, (*b_it)->center_of_mass); + if ((*b_it)->flags.is(CBone::flSelected)) + { + float sz = joint_size*2.f; + DU_impl.DrawCross(cm, sz, sz, sz, sz, sz, sz, 0xFFFFFFFF, false); + DU_impl.DrawRomboid(cm, joint_size*0.7f, color_bone_sel_cm); + } + else + { + DU_impl.DrawRomboid(cm, joint_size*0.7f, color_bone_norm_cm); } } -/* - if (0){ - M.transform_dir (d); - p2.mad (p1,d,(*b_it)->_Length()); - DU.DrawLine (p1,p2,c_joint); + /* + if (0){ + M.transform_dir (d); + p2.mad (p1,d,(*b_it)->_Length()); + DU.DrawLine (p1,p2,c_joint); + } + */ + if ((*b_it)->Parent()) + { + EDevice.SetShader(EDevice.m_SelectionShader); + Fvector &p2 = (*b_it)->Parent()->_LTransform().c; + DU_impl.DrawLine(p1, p2, color_bone_link_color); } -*/ - if ((*b_it)->Parent()){ - EDevice.SetShader(EDevice.m_SelectionShader); - Fvector& p2 = (*b_it)->Parent()->_LTransform().c; - DU_impl.DrawLine (p1,p2,color_bone_link_color); - } - if (EPrefs->object_flags.is(epoDrawBoneAxis)){ - Fmatrix mat; mat.mul(parent,M); - DU_impl.DrawObjectAxis(mat,0.03f,(*b_it)->flags.is(CBone::flSelected)); + if (EPrefs->object_flags.is(epoDrawBoneAxis)) + { + Fmatrix mat; + mat.mul(parent, M); + DU_impl.DrawObjectAxis(mat, 0.03f, (*b_it)->flags.is(CBone::flSelected)); } - if (EPrefs->object_flags.is(epoDrawBoneNames)){ - parent.transform_tiny(p1); - u32 c = (*b_it)->flags.is(CBone::flSelected)?0xFFFFFFFF:0xFF000000; - u32 s = (*b_it)->flags.is(CBone::flSelected)?0xFF000000:0xFF909090; - DU_impl.OutText(p1,(*b_it)->Name().c_str(),c,s); + if (EPrefs->object_flags.is(epoDrawBoneNames)) + { + parent.transform_tiny(p1); + u32 c = (*b_it)->flags.is(CBone::flSelected) ? 0xFFFFFFFF : 0xFF000000; + u32 s = (*b_it)->flags.is(CBone::flSelected) ? 0xFF000000 : 0xFF909090; + DU_impl.OutText(p1, (*b_it)->Name().c_str(), c, s); } - if (EPrefs->object_flags.is(epoDrawBoneShapes)){ - EDevice.SetShader(EDevice.m_SelectionShader); - Fmatrix mat = M; - mat.mulA_43 (parent); - u32 c = (*b_it)->flags.is(CBone::flSelected)?0x80ffffff:0x300000ff; - if ((*b_it)->shape.Valid()){ - switch ((*b_it)->shape.type){ - case SBoneShape::stBox: DU_impl.DrawOBB (mat,(*b_it)->shape.box,c,c); break; - case SBoneShape::stSphere: DU_impl.DrawSphere (mat,(*b_it)->shape.sphere,c,c,TRUE,TRUE);break; - case SBoneShape::stCylinder:DU_impl.DrawCylinder (mat,(*b_it)->shape.cylinder.m_center,(*b_it)->shape.cylinder.m_direction,(*b_it)->shape.cylinder.m_height,(*b_it)->shape.cylinder.m_radius,c,c,TRUE,TRUE);break; - } + if (EPrefs->object_flags.is(epoDrawBoneShapes)) + { + EDevice.SetShader(EDevice.m_SelectionShader); + Fmatrix mat = M; + mat.mulA_43(parent); + u32 c = (*b_it)->flags.is(CBone::flSelected) ? 0x80ffffff : 0x300000ff; + if ((*b_it)->shape.Valid()) + { + switch ((*b_it)->shape.type) + { + case SBoneShape::stBox: DU_impl.DrawOBB(mat, (*b_it)->shape.box, c, c); + break; + case SBoneShape::stSphere: DU_impl.DrawSphere(mat, (*b_it)->shape.sphere, c, c, TRUE, TRUE); + break; + case SBoneShape::stCylinder: DU_impl.DrawCylinder(mat, (*b_it)->shape.cylinder.m_center, (*b_it)->shape.cylinder.m_direction, (*b_it)->shape.cylinder.m_height, (*b_it)->shape.cylinder.m_radius, c, c, TRUE, TRUE); + break; + } } } } } } -CBone* CEditableObject::PickBone(const Fvector& S, const Fvector& D, const Fmatrix& parent) +CBone *CEditableObject::PickBone(const Fvector &S, const Fvector &D, const Fmatrix &parent) { - BoneVec& lst = m_Bones; - float dist = 10000.f; - CBone* sel = 0; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++){ - if ((*b_it)->Pick(dist,S,D,parent)) - sel = *b_it; + BoneVec &lst = m_Bones; + float dist = 10000.f; + CBone *sel = 0; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + { + if ((*b_it)->Pick(dist, S, D, parent)) + sel = *b_it; } return sel; } void CEditableObject::SelectBones(bool bVal) { - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) (*b_it)->Select(bVal); } -void CEditableObject::SelectBone(CBone* b, bool bVal) +void CEditableObject::SelectBone(CBone *b, bool bVal) { - if (b) b->Select(bVal); + if (b) + b->Select(bVal); } - -int CEditableObject::GetSelectedBones(BoneVec& sel_bones) + +int CEditableObject::GetSelectedBones(BoneVec &sel_bones) { - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) - if ((*b_it)->flags.is(CBone::flSelected)) sel_bones.push_back(*b_it); + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + if ((*b_it)->flags.is(CBone::flSelected)) + sel_bones.push_back(*b_it); return sel_bones.size(); } @@ -210,213 +249,260 @@ int CEditableObject::GetSelectedBones(BoneVec& sel_bones) #include "MgcCont3DMinSphere.h" #include "ExportSkeleton.h" -BOOL f_valid (float f) + +BOOL f_valid(float f) { - return _finite(f) && !_isnan(f); + return _finite(f)&&!_isnan(f); } -BOOL SphereValid (FvectorVec& geom, Fsphere& test) + +BOOL SphereValid(FvectorVec &geom, Fsphere &test) { - if (!f_valid(test.P.x) || !f_valid(test.R)) { - Msg ("*** Attention ***: invalid sphere: %f,%f,%f - %f",test.P.x,test.P.y,test.P.z,test.R); - } - - Fsphere S = test; - S.R += EPS_L; - for (FvectorIt I = geom.begin(); I!=geom.end(); I++) - if (!S.contains(*I)) return FALSE; - return TRUE; + if (!f_valid(test.P.x)||!f_valid(test.R)) + { + Msg("*** Attention ***: invalid sphere: %f,%f,%f - %f", test.P.x, test.P.y, test.P.z, test.R); + } + + Fsphere S = test; + S.R += EPS_L; + for (FvectorIt I = geom.begin(); I!=geom.end(); I++) + if (!S.contains(*I)) + return FALSE; + return TRUE; } -void ComputeSphere(Fsphere &B, FvectorVec& V) + +void ComputeSphere(Fsphere &B, FvectorVec &V) { - if (V.size()<3) { B.P.set(0,0,0); B.R=0.f; return; } - - // 1: calc first variation - Fsphere S1; - Fsphere_compute (S1,V.begin(),V.size()); - BOOL B1 = SphereValid(V,S1); - - // 2: calc ordinary algorithm (2nd) - Fsphere S2; - Fbox bbox; - bbox.invalidate (); - for (FvectorIt I=V.begin(); I!=V.end(); I++) bbox.modify(*I); - bbox.grow (EPS_L); - bbox.getsphere (S2.P,S2.R); - S2.R = -1; - for (I=V.begin(); I!=V.end(); I++) { - float d = S2.P.distance_to_sqr(*I); - if (d>S2.R) S2.R=d; - } - S2.R = _sqrt (_abs(S2.R)); - BOOL B2 = SphereValid(V,S2); - - // 3: calc magic-fm - Mgc::Sphere _S3 = Mgc::MinSphere(V.size(), (const Mgc::Vector3*) V.begin()); - Fsphere S3; - S3.P.set (_S3.Center().x,_S3.Center().y,_S3.Center().z); - S3.R = _S3.Radius(); - BOOL B3 = SphereValid(V,S3); - - // select best one - if (B1 && (S1.RS2.R) + S2.R = d; + } + S2.R = _sqrt(_abs(S2.R)); + BOOL B2 = SphereValid(V, S2); + + // 3: calc magic-fm + Mgc::Sphere _S3 = Mgc::MinSphere(V.size(), (const Mgc::Vector3*) V.begin()); + Fsphere S3; + S3.P.set(_S3.Center().x, _S3.Center().y, _S3.Center().z); + S3.R = _S3.Radius(); + BOOL B3 = SphereValid(V, S3); + + // select best one + if (B1&&(S1.R bone_points; - bone_points.resize (m_Bones.size()); - for(EditMeshIt mesh_it=FirstMesh();mesh_it!=LastMesh();mesh_it++){ - CEditableMesh* MESH = *mesh_it; + R_ASSERT(IsSkeleton()); + xr_vector bone_points; + bone_points.resize(m_Bones.size()); + for (EditMeshIt mesh_it = FirstMesh(); mesh_it!=LastMesh(); mesh_it++) + { + CEditableMesh*MESH = *mesh_it; // generate vertex offset - MESH->GenerateSVertices (1); - for (u32 f_id=0; f_id!=MESH->GetFCount(); f_id++){ - for (int k=0; k<3; k++){ - st_SVert& sv = MESH->m_SVertices[f_id*3+k]; - VERIFY (sv.bones.size()==1); - u16 b_id = sv.bones[0].id;//(sv.bones.size()>1)?(sv.bones[0].w>sv.bones[1].w?sv.bones[0].id:sv.bones[1].id):sv.bones[0].id; - FvectorVec& P = bone_points[b_id]; - bool bFound = false; + MESH->GenerateSVertices(1); + for (u32 f_id = 0; f_id!=MESH->GetFCount(); f_id++) + { + for (int k = 0; k<3; k++) + { + st_SVert&sv = MESH->m_SVertices[f_id*3+k]; + VERIFY(sv.bones.size()==1); + u16 b_id = sv.bones[0].id;//(sv.bones.size()>1)?(sv.bones[0].w>sv.bones[1].w?sv.bones[0].id:sv.bones[1].id):sv.bones[0].id; + FvectorVec &P = bone_points[b_id]; + bool bFound = false; Fvector p; - m_Bones[b_id]->_RITransform().transform_tiny(p,sv.offs); - for (FvectorIt p_it=P.begin(); p_it!=P.end(); p_it++) - if (p_it->similar(p)){ - bFound=true; - break; - } - if (!bFound) P.push_back(p); -// if (sv.bone1!=BI_NONE) bone_points[sv.bone1].push_back(sv.offs1); + m_Bones[b_id]->_RITransform().transform_tiny(p, sv.offs); + for (FvectorIt p_it = P.begin(); p_it!=P.end(); p_it++) + if (p_it->similar(p)) + { + bFound = true; + break; + } + if (!bFound) + P.push_back(p); + // if (sv.bone1!=BI_NONE) bone_points[sv.bone1].push_back(sv.offs1); } } MESH->UnloadSVertices(); } - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++){ - if (bSelOnly&&!(*b_it)->flags.is(CBone::flSelected)) continue; - FvectorVec& positions = bone_points[b_it-lst.begin()]; - ComputeOBB_WML ((*b_it)->shape.box,positions); - ComputeSphere ((*b_it)->shape.sphere,positions); - ComputeCylinder ((*b_it)->shape.cylinder,(*b_it)->shape.box,positions); + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + { + if (bSelOnly&&!(*b_it)->flags.is(CBone::flSelected)) + continue; + FvectorVec &positions = bone_points[b_it-lst.begin()]; + ComputeOBB_WML((*b_it)->shape.box, positions); + ComputeSphere((*b_it)->shape.sphere, positions); + ComputeCylinder((*b_it)->shape.cylinder, (*b_it)->shape.box, positions); (*b_it)->center_of_mass.set((*b_it)->shape.sphere.P); } return true; } - + void CEditableObject::ClampByLimits(bool bSelOnly) { - BoneVec& lst = m_Bones; - for(BoneIt b_it=lst.begin(); b_it!=lst.end(); b_it++) - if (!bSelOnly||(bSelOnly&&(*b_it)->Selected())) (*b_it)->ClampByLimits(); + BoneVec &lst = m_Bones; + for (BoneIt b_it = lst.begin(); b_it!=lst.end(); b_it++) + if (!bSelOnly||(bSelOnly&&(*b_it)->Selected())) + (*b_it)->ClampByLimits(); } diff --git a/src/editors/ECore/Editor/EditorPreferences.cpp b/src/editors/ECore/Editor/EditorPreferences.cpp index fe8c2ffc323..1be2bac09d4 100644 --- a/src/editors/ECore/Editor/EditorPreferences.cpp +++ b/src/editors/ECore/Editor/EditorPreferences.cpp @@ -2,177 +2,193 @@ #include "stdafx.h" #pragma hdrstop -#include "PropertiesList.h" +#include "editors/xrEProps/PropertiesList.h" #include "ui_main.h" -#include "ui_toolscustom.h" +#include "UI_ToolsCustom.h" //--------------------------------------------------------------------------- -CCustomPreferences* EPrefs=0; +CCustomPreferences *EPrefs = 0; + //--------------------------------------------------------------------------- CCustomPreferences::CCustomPreferences() { - // view - view_np = 0.1f; - view_fp = 1500.f; - view_fov = deg2rad(60.f); - // fog - fog_color = 0x00555555; - fog_fogness = 0.9; + // view + view_np = 0.1f; + view_fp = 1500.f; + view_fov = deg2rad(60.f); + // fog + fog_color = 0x00555555; + fog_fogness = 0.9; // camera - cam_fly_speed = 5.0f; - cam_fly_alt = 1.8f; - cam_sens_rot = 0.6f; - cam_sens_move = 0.6f; - // tools mouse - tools_sens_move = 0.3f; - tools_sens_rot = 0.3f; - tools_sens_scale = 0.3f; - tools_show_move_axis =false; + cam_fly_speed = 5.0f; + cam_fly_alt = 1.8f; + cam_sens_rot = 0.6f; + cam_sens_move = 0.6f; + // tools mouse + tools_sens_move = 0.3f; + tools_sens_rot = 0.3f; + tools_sens_scale = 0.3f; + tools_show_move_axis = false; // box pick - bp_lim_depth = TRUE; - bp_cull = TRUE; - bp_depth_tolerance = 0.1f; + bp_lim_depth = TRUE; + bp_cull = TRUE; + bp_depth_tolerance = 0.1f; // snap - snap_angle = deg2rad(5.f); - snap_move = 0.1f; - snap_moveto = 0.5f; + snap_angle = deg2rad(5.f); + snap_move = 0.1f; + snap_moveto = 0.5f; // grid - grid_cell_size = 1.f; - grid_cell_count = 100; + grid_cell_size = 1.f; + grid_cell_count = 100; // scene - scene_undo_level = 125; - scene_recent_count = 10; - scene_clear_color = DEFAULT_CLEARCOLOR; + scene_undo_level = 125; + scene_recent_count = 10; + scene_clear_color = DEFAULT_CLEARCOLOR; // objects - object_flags.zero (); + object_flags.zero(); } + //--------------------------------------------------------------------------- -CCustomPreferences::~CCustomPreferences() -{ -} +CCustomPreferences::~CCustomPreferences() {} void CCustomPreferences::ApplyValues() { - Tools->m_MoveSnap = snap_move; - Tools->m_MoveSnapTo = snap_moveto; - Tools->m_RotateSnapAngle= snap_angle; + Tools->m_MoveSnap = snap_move; + Tools->m_MoveSnapTo = snap_moveto; + Tools->m_RotateSnapAngle = snap_angle; EDevice.m_Camera.SetViewport(view_np, view_fp, rad2deg(view_fov)); - Tools->SetFog (fog_color,fog_fogness); + Tools->SetFog(fog_color, fog_fogness); - UI->m_MouseSM = 0.2f*tools_sens_move*tools_sens_move; - UI->m_MouseSR = 0.02f*tools_sens_rot*tools_sens_rot; - UI->m_MouseSS = 0.02f*tools_sens_scale*tools_sens_scale; + UI->m_MouseSM = 0.2f*tools_sens_move*tools_sens_move; + UI->m_MouseSR = 0.02f*tools_sens_rot*tools_sens_rot; + UI->m_MouseSS = 0.02f*tools_sens_scale*tools_sens_scale; - EDevice.m_Camera.SetSensitivity (cam_sens_move, cam_sens_rot); - EDevice.m_Camera.SetFlyParams (cam_fly_speed, cam_fly_alt); + EDevice.m_Camera.SetSensitivity(cam_sens_move, cam_sens_rot); + EDevice.m_Camera.SetFlyParams(cam_fly_speed, cam_fly_alt); - ExecCommand (COMMAND_UPDATE_GRID); + ExecCommand(COMMAND_UPDATE_GRID); } + //--------------------------------------------------------------------------- -void __stdcall CCustomPreferences::OnClose () +void __stdcall CCustomPreferences::OnClose() { - ApplyValues (); + ApplyValues(); } + //--------------------------------------------------------------------------- -void CheckValidate(ShortcutValue*, const xr_shortcut& new_val, bool& result) +void CheckValidate(ShortcutValue *, const xr_shortcut &new_val, bool &result) { - result = true; - ECommandVec& cmds = GetEditorCommands(); - for (u32 cmd_idx=0; cmd_idxeditable){ - VERIFY(!CMD->sub_commands.empty()); - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; - if (SUB_CMD->shortcut.similar(new_val)){ result = false; return;} + result = true; + ECommandVec&cmds = GetEditorCommands(); + for (u32 cmd_idx = 0; cmd_idxeditable) + { + VERIFY(!CMD->sub_commands.empty()); + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; + if (SUB_CMD->shortcut.similar(new_val)) + { + result = false; + return; + } } } } } -void CCustomPreferences::OnKeyboardCommonFileClick(ButtonValue* B, bool& bModif, bool&) +void CCustomPreferences::OnKeyboardCommonFileClick(ButtonValue *B, bool &bModif, bool &) { bModif = false; xr_string fn; - switch(B->btn_num){ - case 0: - if(EFS.GetOpenName("$import$", fn, false, NULL, 6)){ - CInifile* I = xr_new(fn.c_str(), TRUE, TRUE, TRUE); - LoadShortcuts (I); - xr_delete (I); - m_ItemProps->RefreshForm(); - } - break; - case 1: - if(EFS.GetSaveName("$import$", fn, NULL, 6)){ - CInifile* I = xr_new(fn.c_str(), FALSE, TRUE, TRUE); - SaveShortcuts (I); - xr_delete (I); - } - break; - } + switch (B->btn_num) + { + case 0: + if (EFS.GetOpenName("$import$", fn, false, NULL, 6)) + { + CInifile *I = xr_new(fn.c_str(), TRUE, TRUE, TRUE); + LoadShortcuts(I); + xr_delete(I); + m_ItemProps->RefreshForm(); + } + break; + case 1: + if (EFS.GetSaveName("$import$", fn, NULL, 6)) + { + CInifile *I = xr_new(fn.c_str(), FALSE, TRUE, TRUE); + SaveShortcuts(I); + xr_delete(I); + } + break; + } } -void CCustomPreferences::FillProp(PropItemVec& props) +void CCustomPreferences::FillProp(PropItemVec &props) { - PHelper().CreateFlag32 (props,"Objects\\Library\\Discard Instance", &object_flags, epoDiscardInstance); - PHelper().CreateFlag32 (props,"Objects\\Skeleton\\Draw Joints", &object_flags, epoDrawJoints); - PHelper().CreateFlag32 (props,"Objects\\Skeleton\\Draw Bone Axis", &object_flags, epoDrawBoneAxis); - PHelper().CreateFlag32 (props,"Objects\\Skeleton\\Draw Bone Names", &object_flags, epoDrawBoneNames); - PHelper().CreateFlag32 (props,"Objects\\Skeleton\\Draw Bone Shapes", &object_flags, epoDrawBoneShapes); - PHelper().CreateFlag32 (props,"Objects\\Show\\Hint", &object_flags, epoShowHint); - PHelper().CreateFlag32 (props,"Objects\\Show\\Pivot", &object_flags, epoDrawPivot); - PHelper().CreateFlag32 (props,"Objects\\Show\\Animation Path", &object_flags, epoDrawAnimPath); - PHelper().CreateFlag32 (props,"Objects\\Show\\LOD", &object_flags, epoDrawLOD); - PHelper().CreateFlag32 (props,"Objects\\Loading\\Deffered Loading RB", &object_flags, epoDeffLoadRB); - PHelper().CreateFlag32 (props,"Objects\\Loading\\Deffered Loading CF", &object_flags, epoDeffLoadCF); - PHelper().CreateFlag32 (props,"Objects\\GroupObject\\Select ingroup", &object_flags, epoSelectInGroup); - - PHelper().CreateU32 (props,"Scene\\Common\\Recent Count", &scene_recent_count,0, 25); - PHelper().CreateU32 (props,"Scene\\Common\\Undo Level", &scene_undo_level, 0, 125); - PHelper().CreateFloat (props,"Scene\\Grid\\Cell Size", &grid_cell_size, 0.1f, 10.f); - PHelper().CreateU32 (props,"Scene\\Grid\\Cell Count", &grid_cell_count, 10, 1000); - - PHelper().CreateBOOL (props,"Tools\\Box Pick\\Limited Depth", &bp_lim_depth); - PHelper().CreateBOOL (props,"Tools\\Box Pick\\Back Face Culling", &bp_cull); - PHelper().CreateFloat (props,"Tools\\Box Pick\\Depth Tolerance", &bp_depth_tolerance,0.f, 10000.f); - PHelper().CreateFloat (props,"Tools\\Sens\\Move", &tools_sens_move); - PHelper().CreateBOOL (props,"Tools\\Sens\\ShowMoveAxis", &tools_show_move_axis); - - PHelper().CreateFloat (props,"Tools\\Sens\\Rotate", &tools_sens_rot); - PHelper().CreateFloat (props,"Tools\\Sens\\Scale", &tools_sens_scale); - PHelper().CreateAngle (props,"Tools\\Snap\\Angle", &snap_angle, 0, PI_MUL_2); - PHelper().CreateFloat (props,"Tools\\Snap\\Move", &snap_move, 0.01f, 1000.f); - PHelper().CreateFloat (props,"Tools\\Snap\\Move To", &snap_moveto, 0.01f, 1000.f); - - - PHelper().CreateFloat (props,"Viewport\\Camera\\Move Sens", &cam_sens_move); - PHelper().CreateFloat (props,"Viewport\\Camera\\Rotate Sens", &cam_sens_rot); - PHelper().CreateFloat (props,"Viewport\\Camera\\Fly Speed", &cam_fly_speed, 0.01f, 100.f); - PHelper().CreateFloat (props,"Viewport\\Camera\\Fly Altitude", &cam_fly_alt, 0.f, 1000.f); - PHelper().CreateColor (props,"Viewport\\Fog\\Color", &fog_color ); - PHelper().CreateFloat (props,"Viewport\\Fog\\Fogness", &fog_fogness, 0.f, 100.f); - PHelper().CreateFloat (props,"Viewport\\Near Plane", &view_np, 0.01f, 10.f); - PHelper().CreateFloat (props,"Viewport\\Far Plane", &view_fp, 10.f, 10000.f); - PHelper().CreateAngle (props,"Viewport\\FOV", &view_fov, deg2rad(0.1f), deg2rad(170.f)); - PHelper().CreateColor (props,"Viewport\\Clear Color", &scene_clear_color ); - - ButtonValue* B = PHelper().CreateButton (props,"Keyboard\\Common\\File","Load,Save", 0); - B->OnBtnClickEvent.bind (this,&CCustomPreferences::OnKeyboardCommonFileClick); - ECommandVec& cmds = GetEditorCommands(); - for (u32 cmd_idx=0; cmd_idxeditable){ - VERIFY(!CMD->sub_commands.empty()); - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; - string128 nm; sprintf(nm,"%s%s%s",CMD->Desc(),!SUB_CMD->desc.empty()?"\\":"",SUB_CMD->desc.c_str()); - ShortcutValue* V = PHelper().CreateShortcut(props,PrepareKey("Keyboard\\Shortcuts",nm), &SUB_CMD->shortcut); + PHelper().CreateFlag32(props, "Objects\\Library\\Discard Instance", &object_flags, epoDiscardInstance); + PHelper().CreateFlag32(props, "Objects\\Skeleton\\Draw Joints", &object_flags, epoDrawJoints); + PHelper().CreateFlag32(props, "Objects\\Skeleton\\Draw Bone Axis", &object_flags, epoDrawBoneAxis); + PHelper().CreateFlag32(props, "Objects\\Skeleton\\Draw Bone Names", &object_flags, epoDrawBoneNames); + PHelper().CreateFlag32(props, "Objects\\Skeleton\\Draw Bone Shapes", &object_flags, epoDrawBoneShapes); + PHelper().CreateFlag32(props, "Objects\\Show\\Hint", &object_flags, epoShowHint); + PHelper().CreateFlag32(props, "Objects\\Show\\Pivot", &object_flags, epoDrawPivot); + PHelper().CreateFlag32(props, "Objects\\Show\\Animation Path", &object_flags, epoDrawAnimPath); + PHelper().CreateFlag32(props, "Objects\\Show\\LOD", &object_flags, epoDrawLOD); + PHelper().CreateFlag32(props, "Objects\\Loading\\Deffered Loading RB", &object_flags, epoDeffLoadRB); + PHelper().CreateFlag32(props, "Objects\\Loading\\Deffered Loading CF", &object_flags, epoDeffLoadCF); + PHelper().CreateFlag32(props, "Objects\\GroupObject\\Select ingroup", &object_flags, epoSelectInGroup); + + PHelper().CreateU32(props, "Scene\\Common\\Recent Count", &scene_recent_count, 0, 25); + PHelper().CreateU32(props, "Scene\\Common\\Undo Level", &scene_undo_level, 0, 125); + PHelper().CreateFloat(props, "Scene\\Grid\\Cell Size", &grid_cell_size, 0.1f, 10.f); + PHelper().CreateU32(props, "Scene\\Grid\\Cell Count", &grid_cell_count, 10, 1000); + + PHelper().CreateBOOL(props, "Tools\\Box Pick\\Limited Depth", &bp_lim_depth); + PHelper().CreateBOOL(props, "Tools\\Box Pick\\Back Face Culling", &bp_cull); + PHelper().CreateFloat(props, "Tools\\Box Pick\\Depth Tolerance", &bp_depth_tolerance, 0.f, 10000.f); + PHelper().CreateFloat(props, "Tools\\Sens\\Move", &tools_sens_move); + PHelper().CreateBOOL(props, "Tools\\Sens\\ShowMoveAxis", &tools_show_move_axis); + + PHelper().CreateFloat(props, "Tools\\Sens\\Rotate", &tools_sens_rot); + PHelper().CreateFloat(props, "Tools\\Sens\\Scale", &tools_sens_scale); + PHelper().CreateAngle(props, "Tools\\Snap\\Angle", &snap_angle, 0, PI_MUL_2); + PHelper().CreateFloat(props, "Tools\\Snap\\Move", &snap_move, 0.01f, 1000.f); + PHelper().CreateFloat(props, "Tools\\Snap\\Move To", &snap_moveto, 0.01f, 1000.f); + + + PHelper().CreateFloat(props, "Viewport\\Camera\\Move Sens", &cam_sens_move); + PHelper().CreateFloat(props, "Viewport\\Camera\\Rotate Sens", &cam_sens_rot); + PHelper().CreateFloat(props, "Viewport\\Camera\\Fly Speed", &cam_fly_speed, 0.01f, 100.f); + PHelper().CreateFloat(props, "Viewport\\Camera\\Fly Altitude", &cam_fly_alt, 0.f, 1000.f); + PHelper().CreateColor(props, "Viewport\\Fog\\Color", &fog_color); + PHelper().CreateFloat(props, "Viewport\\Fog\\Fogness", &fog_fogness, 0.f, 100.f); + PHelper().CreateFloat(props, "Viewport\\Near Plane", &view_np, 0.01f, 10.f); + PHelper().CreateFloat(props, "Viewport\\Far Plane", &view_fp, 10.f, 10000.f); + PHelper().CreateAngle(props, "Viewport\\FOV", &view_fov, deg2rad(0.1f), deg2rad(170.f)); + PHelper().CreateColor(props, "Viewport\\Clear Color", &scene_clear_color); + + ButtonValue *B = PHelper().CreateButton(props, "Keyboard\\Common\\File", "Load,Save", 0); + B->OnBtnClickEvent.bind(this, &CCustomPreferences::OnKeyboardCommonFileClick); + ECommandVec&cmds = GetEditorCommands(); + for (u32 cmd_idx = 0; cmd_idxeditable) + { + VERIFY(!CMD->sub_commands.empty()); + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; + string128 nm; + sprintf(nm, "%s%s%s", CMD->Desc(), !SUB_CMD->desc.empty() ? "\\" : "", SUB_CMD->desc.c_str()); + ShortcutValue *V = PHelper().CreateShortcut(props, PrepareKey("Keyboard\\Shortcuts", nm), &SUB_CMD->shortcut); V->OnValidateResultEvent.bind(CheckValidate); } } @@ -182,174 +198,186 @@ void CCustomPreferences::FillProp(PropItemVec& props) void CCustomPreferences::Edit() { // fill prop - PropItemVec props; + PropItemVec props; - FillProp (props); + FillProp(props); - m_ItemProps->AssignItems (props); + m_ItemProps->AssignItems(props); m_ItemProps->ShowPropertiesModal(); // save changed options - Save (); + Save(); } + //--------------------------------------------------------------------------- -void CCustomPreferences::Load(CInifile* I) +void CCustomPreferences::Load(CInifile *I) { - psDeviceFlags.flags = R_U32_SAFE ("editor_prefs","device_flags", psDeviceFlags.flags); - psSoundFlags.flags = R_U32_SAFE ("editor_prefs","sound_flags", psSoundFlags.flags) - - Tools->m_Settings.flags = R_U32_SAFE ("editor_prefs","tools_settings",Tools->m_Settings.flags); - - view_np = R_FLOAT_SAFE ("editor_prefs","view_np" ,view_np ); - view_fp = R_FLOAT_SAFE ("editor_prefs","view_fp" ,view_fp ); - view_fov = R_FLOAT_SAFE ("editor_prefs","view_fov" ,view_fov ); - - fog_color = R_U32_SAFE ("editor_prefs","fog_color" ,fog_color ); - fog_fogness = R_FLOAT_SAFE ("editor_prefs","fog_fogness" ,fog_fogness ); - - cam_fly_speed = R_FLOAT_SAFE ("editor_prefs","cam_fly_speed" ,cam_fly_speed ); - cam_fly_alt = R_FLOAT_SAFE ("editor_prefs","cam_fly_alt" ,cam_fly_alt ); - cam_sens_rot = R_FLOAT_SAFE ("editor_prefs","cam_sens_rot" ,cam_sens_rot ); - cam_sens_move = R_FLOAT_SAFE ("editor_prefs","cam_sens_move" ,cam_sens_move ); - - tools_sens_move = R_FLOAT_SAFE ("editor_prefs","tools_sens_move" ,tools_sens_move ); - tools_sens_rot = R_FLOAT_SAFE ("editor_prefs","tools_sens_rot" ,tools_sens_rot ); - tools_sens_scale = R_FLOAT_SAFE ("editor_prefs","tools_sens_scale" ,tools_sens_scale ); - tools_show_move_axis= R_BOOL_SAFE ("editor_prefs","tools_show_move_axis" ,tools_show_move_axis); - - bp_lim_depth = R_BOOL_SAFE ("editor_prefs","bp_lim_depth" ,bp_lim_depth ); - bp_cull = R_BOOL_SAFE ("editor_prefs","bp_lim_depth" ,bp_cull ); - bp_depth_tolerance = R_FLOAT_SAFE ("editor_prefs","tools_sens_rot" ,bp_depth_tolerance ); - - snap_angle = R_FLOAT_SAFE ("editor_prefs","snap_angle" ,snap_angle ); - snap_move = R_FLOAT_SAFE ("editor_prefs","snap_move" ,snap_move ); - snap_moveto = R_FLOAT_SAFE ("editor_prefs","snap_moveto" ,snap_moveto ); - - grid_cell_size = R_FLOAT_SAFE ("editor_prefs","grid_cell_size" ,grid_cell_size ); - grid_cell_count = R_U32_SAFE ("editor_prefs","grid_cell_count" ,grid_cell_count ); - - scene_undo_level = R_U32_SAFE ("editor_prefs","scene_undo_level" ,scene_undo_level ); - scene_recent_count = R_U32_SAFE ("editor_prefs","scene_recent_count",scene_recent_count ); - scene_clear_color = R_U32_SAFE ("editor_prefs","scene_clear_color" ,scene_clear_color ); - - object_flags.flags = R_U32_SAFE ("editor_prefs","object_flags" ,object_flags.flags ); - - // read recent list - for (u32 i=0; im_Settings.flags = R_U32_SAFE("editor_prefs", "tools_settings", Tools->m_Settings.flags); + + view_np = R_FLOAT_SAFE("editor_prefs", "view_np", view_np); + view_fp = R_FLOAT_SAFE("editor_prefs", "view_fp", view_fp); + view_fov = R_FLOAT_SAFE("editor_prefs", "view_fov", view_fov); + + fog_color = R_U32_SAFE("editor_prefs", "fog_color", fog_color); + fog_fogness = R_FLOAT_SAFE("editor_prefs", "fog_fogness", fog_fogness); + + cam_fly_speed = R_FLOAT_SAFE("editor_prefs", "cam_fly_speed", cam_fly_speed); + cam_fly_alt = R_FLOAT_SAFE("editor_prefs", "cam_fly_alt", cam_fly_alt); + cam_sens_rot = R_FLOAT_SAFE("editor_prefs", "cam_sens_rot", cam_sens_rot); + cam_sens_move = R_FLOAT_SAFE("editor_prefs", "cam_sens_move", cam_sens_move); + + tools_sens_move = R_FLOAT_SAFE("editor_prefs", "tools_sens_move", tools_sens_move); + tools_sens_rot = R_FLOAT_SAFE("editor_prefs", "tools_sens_rot", tools_sens_rot); + tools_sens_scale = R_FLOAT_SAFE("editor_prefs", "tools_sens_scale", tools_sens_scale); + tools_show_move_axis = R_BOOL_SAFE("editor_prefs", "tools_show_move_axis", tools_show_move_axis); + + bp_lim_depth = R_BOOL_SAFE("editor_prefs", "bp_lim_depth", bp_lim_depth); + bp_cull = R_BOOL_SAFE("editor_prefs", "bp_lim_depth", bp_cull); + bp_depth_tolerance = R_FLOAT_SAFE("editor_prefs", "tools_sens_rot", bp_depth_tolerance); + + snap_angle = R_FLOAT_SAFE("editor_prefs", "snap_angle", snap_angle); + snap_move = R_FLOAT_SAFE("editor_prefs", "snap_move", snap_move); + snap_moveto = R_FLOAT_SAFE("editor_prefs", "snap_moveto", snap_moveto); + + grid_cell_size = R_FLOAT_SAFE("editor_prefs", "grid_cell_size", grid_cell_size); + grid_cell_count = R_U32_SAFE("editor_prefs", "grid_cell_count", grid_cell_count); + + scene_undo_level = R_U32_SAFE("editor_prefs", "scene_undo_level", scene_undo_level); + scene_recent_count = R_U32_SAFE("editor_prefs", "scene_recent_count", scene_recent_count); + scene_clear_color = R_U32_SAFE("editor_prefs", "scene_clear_color", scene_clear_color); + + object_flags.flags = R_U32_SAFE("editor_prefs", "object_flags", object_flags.flags); + + // read recent list + for (u32 i = 0; iLoadSettings (I); + UI->LoadSettings(I); } -void CCustomPreferences::Save(CInifile* I) +void CCustomPreferences::Save(CInifile *I) { - I->w_u32 ("editor_prefs","device_flags", psDeviceFlags.flags ); - I->w_u32 ("editor_prefs","sound_flags", psSoundFlags.flags ); + I->w_u32("editor_prefs", "device_flags", psDeviceFlags.flags); + I->w_u32("editor_prefs", "sound_flags", psSoundFlags.flags); + + I->w_u32("editor_prefs", "tools_settings", Tools->m_Settings.flags); - I->w_u32 ("editor_prefs","tools_settings", Tools->m_Settings.flags ); + I->w_float("editor_prefs", "view_np", view_np); + I->w_float("editor_prefs", "view_fp", view_fp); + I->w_float("editor_prefs", "view_fov", view_fov); - I->w_float ("editor_prefs","view_np", view_np ); - I->w_float ("editor_prefs","view_fp", view_fp ); - I->w_float ("editor_prefs","view_fov", view_fov ); + I->w_u32("editor_prefs", "fog_color", fog_color); + I->w_float("editor_prefs", "fog_fogness", fog_fogness); - I->w_u32 ("editor_prefs","fog_color", fog_color ); - I->w_float ("editor_prefs","fog_fogness", fog_fogness ); + I->w_float("editor_prefs", "cam_fly_speed", cam_fly_speed); + I->w_float("editor_prefs", "cam_fly_alt", cam_fly_alt); + I->w_float("editor_prefs", "cam_sens_rot", cam_sens_rot); + I->w_float("editor_prefs", "cam_sens_move", cam_sens_move); - I->w_float ("editor_prefs","cam_fly_speed", cam_fly_speed ); - I->w_float ("editor_prefs","cam_fly_alt", cam_fly_alt ); - I->w_float ("editor_prefs","cam_sens_rot", cam_sens_rot ); - I->w_float ("editor_prefs","cam_sens_move", cam_sens_move ); + I->w_float("editor_prefs", "tools_sens_rot", tools_sens_rot); + I->w_float("editor_prefs", "tools_sens_move", tools_sens_move); + I->w_float("editor_prefs", "tools_sens_scale", tools_sens_scale); + I->w_bool("editor_prefs", "tools_show_move_axis", tools_show_move_axis); - I->w_float ("editor_prefs","tools_sens_rot", tools_sens_rot ); - I->w_float ("editor_prefs","tools_sens_move", tools_sens_move ); - I->w_float ("editor_prefs","tools_sens_scale", tools_sens_scale); - I->w_bool ("editor_prefs","tools_show_move_axis",tools_show_move_axis); - - I->w_bool ("editor_prefs","bp_lim_depth", bp_lim_depth ); - I->w_bool ("editor_prefs","bp_lim_depth", bp_cull ); - I->w_float ("editor_prefs","bp_depth_tolerance",bp_depth_tolerance ); + I->w_bool("editor_prefs", "bp_lim_depth", bp_lim_depth); + I->w_bool("editor_prefs", "bp_lim_depth", bp_cull); + I->w_float("editor_prefs", "bp_depth_tolerance", bp_depth_tolerance); - I->w_float ("editor_prefs","snap_angle", snap_angle ); - I->w_float ("editor_prefs","snap_move", snap_move ); - I->w_float ("editor_prefs","snap_moveto", snap_moveto ); + I->w_float("editor_prefs", "snap_angle", snap_angle); + I->w_float("editor_prefs", "snap_move", snap_move); + I->w_float("editor_prefs", "snap_moveto", snap_moveto); - I->w_float ("editor_prefs","grid_cell_size", grid_cell_size ); - I->w_u32 ("editor_prefs","grid_cell_count", grid_cell_count ); + I->w_float("editor_prefs", "grid_cell_size", grid_cell_size); + I->w_u32("editor_prefs", "grid_cell_count", grid_cell_count); - I->w_u32 ("editor_prefs","scene_undo_level", scene_undo_level ); - I->w_u32 ("editor_prefs","scene_recent_count", scene_recent_count ); - I->w_u32 ("editor_prefs","scene_clear_color", scene_clear_color ); + I->w_u32("editor_prefs", "scene_undo_level", scene_undo_level); + I->w_u32("editor_prefs", "scene_recent_count", scene_recent_count); + I->w_u32("editor_prefs", "scene_clear_color", scene_clear_color); - I->w_u32 ("editor_prefs","object_flags", object_flags.flags); + I->w_u32("editor_prefs", "object_flags", object_flags.flags); - for (AStringIt it=scene_recent_list.begin(); it!=scene_recent_list.end(); it++){ - AnsiString L; L.sprintf("recent_files_%d",it-scene_recent_list.begin()); - AnsiString V; V.sprintf("\"%s\"",it->c_str()); - I->w_string("editor_prefs",L.c_str(),V.c_str()); + for (AStringIt it = scene_recent_list.begin(); it!=scene_recent_list.end(); it++) + { + AnsiString L; + L.sprintf("recent_files_%d", it-scene_recent_list.begin()); + AnsiString V; + V.sprintf("\"%s\"", it->c_str()); + I->w_string("editor_prefs", L.c_str(), V.c_str()); } - I->w_string("editor_prefs","weather", sWeather.c_str() ); + I->w_string("editor_prefs", "weather", sWeather.c_str()); // load shortcuts - SaveShortcuts (I); - UI->SaveSettings (I); + SaveShortcuts(I); + UI->SaveSettings(I); } void CCustomPreferences::Load() { - string_path fn; - INI_NAME (fn); - CInifile* I = xr_new(fn, TRUE, TRUE, TRUE); - Load (I); - xr_delete (I); - ApplyValues (); + string_path fn; + INI_NAME(fn); + CInifile *I = xr_new(fn, TRUE, TRUE, TRUE); + Load(I); + xr_delete(I); + ApplyValues(); } + void CCustomPreferences::Save() { - string_path fn; - INI_NAME (fn); - CInifile* I = xr_new(fn, FALSE, TRUE, TRUE); + string_path fn; + INI_NAME(fn); + CInifile *I = xr_new(fn, FALSE, TRUE, TRUE); I->set_override_names(TRUE); - Save (I); - xr_delete (I); + Save(I); + xr_delete(I); } void CCustomPreferences::AppendRecentFile(LPCSTR name) { - for (AStringIt it=scene_recent_list.begin(); it!=scene_recent_list.end(); it++){ - if (*it==name){ - scene_recent_list.erase (it); + for (AStringIt it = scene_recent_list.begin(); it!=scene_recent_list.end(); it++) + { + if (*it==name) + { + scene_recent_list.erase(it); break; } } - scene_recent_list.insert(scene_recent_list.begin(),name); - while (scene_recent_list.size()>=EPrefs->scene_recent_count) - scene_recent_list.pop_back(); + scene_recent_list.insert(scene_recent_list.begin(), name); + while (scene_recent_list.size()>=EPrefs->scene_recent_count) + scene_recent_list.pop_back(); - ExecCommand (COMMAND_REFRESH_UI_BAR); + ExecCommand(COMMAND_REFRESH_UI_BAR); } + //--------------------------------------------------------------------------- void CCustomPreferences::OnCreate() { - Load (); - m_ItemProps = TProperties::CreateModalForm("Editor Preferences",false,0,0,TOnCloseEvent(this,&CCustomPreferences::OnClose),TProperties::plItemFolders|TProperties::plFullSort); //TProperties::plFullExpand TProperties::plFullSort TProperties::plNoClearStore|TProperties::plFolderStore| + Load(); + m_ItemProps = TProperties::CreateModalForm("Editor Preferences", false, 0, 0, TOnCloseEvent(this, &CCustomPreferences::OnClose), TProperties::plItemFolders|TProperties::plFullSort); //TProperties::plFullExpand TProperties::plFullSort TProperties::plNoClearStore|TProperties::plFolderStore| } + //--------------------------------------------------------------------------- void CCustomPreferences::OnDestroy() { TProperties::DestroyForm(m_ItemProps); - Save (); + Save(); } + //--------------------------------------------------------------------------- + diff --git a/src/editors/ECore/Editor/EditorPreferences.h b/src/editors/ECore/Editor/EditorPreferences.h index 97a78dece98..a5ea05598d3 100644 --- a/src/editors/ECore/Editor/EditorPreferences.h +++ b/src/editors/ECore/Editor/EditorPreferences.h @@ -7,84 +7,86 @@ class TProperties; //--------------------------------------------------------------------------- -enum{ - epoDrawPivot = (1<<0), - epoDrawAnimPath = (1<<1), - epoDrawJoints = (1<<2), - epoDrawBoneAxis = (1<<3), - epoDrawBoneNames = (1<<4), - epoDrawBoneShapes = (1<<5), - epoShowHint = (1<<6), - epoDrawLOD = (1<<7), - epoDiscardInstance = (1<<8), - epoDeffLoadRB = (1<<9), - epoDeffLoadCF = (1<<10), - epoSelectInGroup = (1<<11), +enum +{ + epoDrawPivot = (1<<0), + epoDrawAnimPath = (1<<1), + epoDrawJoints = (1<<2), + epoDrawBoneAxis = (1<<3), + epoDrawBoneNames = (1<<4), + epoDrawBoneShapes = (1<<5), + epoShowHint = (1<<6), + epoDrawLOD = (1<<7), + epoDiscardInstance = (1<<8), + epoDeffLoadRB = (1<<9), + epoDeffLoadCF = (1<<10), + epoSelectInGroup = (1<<11), }; + class ECORE_API CCustomPreferences { -private: // User declarations - TProperties* m_ItemProps; -public: - // view - float view_np; - float view_fp; - float view_fov; - // fog - u32 fog_color; - float fog_fogness; + private: // User declarations + TProperties*m_ItemProps; + public: + // view + float view_np; + float view_fp; + float view_fov; + // fog + u32 fog_color; + float fog_fogness; // camera - float cam_fly_speed; - float cam_fly_alt; - float cam_sens_rot; - float cam_sens_move; - // tools mouse - float tools_sens_rot; - float tools_sens_move; - float tools_sens_scale; - BOOL tools_show_move_axis; + float cam_fly_speed; + float cam_fly_alt; + float cam_sens_rot; + float cam_sens_move; + // tools mouse + float tools_sens_rot; + float tools_sens_move; + float tools_sens_scale; + BOOL tools_show_move_axis; // box pick - BOOL bp_lim_depth; - BOOL bp_cull; - float bp_depth_tolerance; + BOOL bp_lim_depth; + BOOL bp_cull; + float bp_depth_tolerance; // snap - float snap_angle; - float snap_move; - float snap_moveto; + float snap_angle; + float snap_move; + float snap_moveto; // grid - float grid_cell_size; - u32 grid_cell_count; + float grid_cell_size; + u32 grid_cell_count; // scene - u32 scene_undo_level; - u32 scene_recent_count; - u32 scene_clear_color; - AStringVec scene_recent_list; + u32 scene_undo_level; + u32 scene_recent_count; + u32 scene_clear_color; + AStringVec scene_recent_list; // objects - Flags32 object_flags; - shared_str sWeather; -protected: - void OnKeyboardCommonFileClick (ButtonValue* value, bool& bModif, bool& bSafe); - void __stdcall OnClose (); - void ApplyValues (); + Flags32 object_flags; + shared_str sWeather; + protected: + void OnKeyboardCommonFileClick(ButtonValue*value, bool& bModif, bool& bSafe); + void__stdcall OnClose(); + void ApplyValues(); - virtual void Load (CInifile*); - virtual void Save (CInifile*); -public: // User declarations - CCustomPreferences (); - virtual ~CCustomPreferences (); + virtual void Load(CInifile*); + virtual void Save(CInifile*); + public: // User declarations + CCustomPreferences(); + virtual ~CCustomPreferences(); - void OnCreate (); - void OnDestroy (); + void OnCreate(); + void OnDestroy(); - virtual void FillProp (PropItemVec& items); + virtual void FillProp(PropItemVec&items); - void Edit (); + void Edit(); - void Load (); - void Save (); - - void AppendRecentFile (LPCSTR name); - LPCSTR FirstRecentFile (){return scene_recent_list.empty()?"":scene_recent_list.front().c_str();} + void Load(); + void Save(); + + void AppendRecentFile(LPCSTR name); + LPCSTR FirstRecentFile(){return scene_recent_list.empty() ? "" : scene_recent_list.front().c_str();} }; //--------------------------------------------------------------------------- #define R_FLOAT_SAFE(S,L,D) I->line_exist(S,L)?I->r_float(S,L):D; @@ -92,7 +94,8 @@ class ECORE_API CCustomPreferences #define R_BOOL_SAFE(S,L,D) I->line_exist(S,L)?I->r_bool(S,L):D; #define R_STRING_SAFE(S,L,D)I->line_exist(S,L)?I->r_string_wb(S,L):D; //--------------------------------------------------------------------------- -extern ECORE_API CCustomPreferences* EPrefs; +extern ECORE_API CCustomPreferences* EPrefs; //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/Engine.cpp b/src/editors/ECore/Editor/Engine.cpp index ee07b2321f9..52f264db5dc 100644 --- a/src/editors/ECore/Editor/Engine.cpp +++ b/src/editors/ECore/Editor/Engine.cpp @@ -8,8 +8,7 @@ #include "Engine.h" #include "ui_main.h" -xrDispatchTable PSGP; -CEngine Engine; +CEngine Engine; ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -17,39 +16,37 @@ CEngine Engine; CEngine::CEngine() { - pSettings = 0; + pSettings = 0; } -CEngine::~CEngine() -{ - -} +CEngine::~CEngine() {} LPCSTR CEngine::LastWindowsError() { - static string1024 errmsg_buf; - LPCSTR err=0; + static string1024 errmsg_buf; + LPCSTR err = 0; - u32 hr=GetLastError(); - if (hr!=0) { - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,errmsg_buf,1024,0); + u32 hr = GetLastError(); + if (hr!=0) + { + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, hr, 0, errmsg_buf, 1024, 0); err = errmsg_buf; - } + } return err; } -extern void __stdcall xrSkin1W_x86 (vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones); -extern void __stdcall xrSkin2W_x86 (vertRender* D, vertBoned2W* S, u32 vCount, CBoneInstance* Bones); +extern void __stdcall xrSkin1W_x86(vertRender *D, vertBoned1W *S, u32 vCount, CBoneInstance *Bones); +extern void __stdcall xrSkin2W_x86(vertRender *D, vertBoned2W *S, u32 vCount, CBoneInstance *Bones); void CEngine::Initialize(void) { - // Other stuff - string_path fn; - strconcat (sizeof(fn),fn,UI->EditorName(),".log"); - FS.update_path (fn,_local_root_,fn); + // Other stuff + string_path fn; + strconcat(sizeof(fn), fn, UI->EditorName(), ".log"); + FS.update_path(fn, _local_root_, fn); #ifdef _EDITOR - // Bind PSGP + // Bind PSGP ZeroMemory (&PSGP,sizeof(PSGP)); hPSGP = LoadLibrary("xrCPU_Pipe"); R_ASSERT2 (hPSGP,"Can't find 'xrCPU_Pipe'"); @@ -61,20 +58,25 @@ void CEngine::Initialize(void) PSGP.skin2W = xrSkin2W_x86; #endif - ReloadSettings (); + ReloadSettings(); } void CEngine::ReloadSettings() { - xr_delete (pSettings); + xr_delete(pSettings); // game configure - string_path si_name; - FS.update_path (si_name,"$game_config$","system.ltx"); - pSettings = xr_new(si_name,TRUE);// FALSE,TRUE,TRUE); + string_path si_name; + FS.update_path(si_name, "$game_config$", "system.ltx"); + pSettings = xr_new(si_name, TRUE);// FALSE,TRUE,TRUE); } void CEngine::Destroy() { - xr_delete (pSettings); - if (hPSGP) { FreeLibrary(hPSGP); hPSGP=0; } + xr_delete(pSettings); + if (hPSGP) + { + FreeLibrary(hPSGP); + hPSGP = 0; + } } + diff --git a/src/editors/ECore/Editor/ExportObjectOGF.cpp b/src/editors/ECore/Editor/ExportObjectOGF.cpp index 54276f0cca8..5896bd4a81e 100644 --- a/src/editors/ECore/Editor/ExportObjectOGF.cpp +++ b/src/editors/ECore/Editor/ExportObjectOGF.cpp @@ -16,72 +16,84 @@ CObjectOGFCollectorPacked::CObjectOGFCollectorPacked(const Fbox &bb, int apx_vertices, int apx_faces) { // Params - m_VMscale.set (bb.max.x-bb.min.x+EPS, bb.max.y-bb.min.y+EPS, bb.max.z-bb.min.z+EPS); - m_VMmin.set (bb.min).sub(EPS); - m_VMeps.set (m_VMscale.x/clpOGFMX/2,m_VMscale.y/clpOGFMY/2,m_VMscale.z/clpOGFMZ/2); - m_VMeps.x = (m_VMeps.x=0) V.P.set(m_Verts[similar_pos].P); + if (similar_pos>=0) + V.P.set(m_Verts[similar_pos].P); P = m_Verts.size(); - if (P>=0xFFFF) return 0xffff; + if (P>=0xFFFF) + return 0xffff; m_Verts.push_back(V); m_VM[ix][iy][iz].push_back(P); - u32 ixE,iyE,izE; + u32 ixE, iyE, izE; ixE = iFloor(float(V.P.x+m_VMeps.x-m_VMmin.x)/m_VMscale.x*clpOGFMX); iyE = iFloor(float(V.P.y+m_VMeps.y-m_VMmin.y)/m_VMscale.y*clpOGFMY); izE = iFloor(float(V.P.z+m_VMeps.z-m_VMmin.z)/m_VMscale.z*clpOGFMZ); - R_ASSERT(ixE<=clpOGFMX && iyE<=clpOGFMY && izE<=clpOGFMZ); - - if (ixE!=ix) m_VM[ixE][iy][iz].push_back (P); - if (iyE!=iy) m_VM[ix][iyE][iz].push_back (P); - if (izE!=iz) m_VM[ix][iy][izE].push_back (P); - if ((ixE!=ix)&&(iyE!=iy)) m_VM[ixE][iyE][iz].push_back(P); - if ((ixE!=ix)&&(izE!=iz)) m_VM[ixE][iy][izE].push_back(P); - if ((iyE!=iy)&&(izE!=iz)) m_VM[ix][iyE][izE].push_back(P); - if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) m_VM[ixE][iyE][izE].push_back(P); + R_ASSERT(ixE<=clpOGFMX&&iyE<=clpOGFMY&&izE<=clpOGFMZ); + + if (ixE!=ix) + m_VM[ixE][iy][iz].push_back(P); + if (iyE!=iy) + m_VM[ix][iyE][iz].push_back(P); + if (izE!=iz) + m_VM[ix][iy][izE].push_back(P); + if ((ixE!=ix)&&(iyE!=iy)) + m_VM[ixE][iyE][iz].push_back(P); + if ((ixE!=ix)&&(izE!=iz)) + m_VM[ixE][iy][izE].push_back(P); + if ((iyE!=iy)&&(izE!=iz)) + m_VM[ix][iyE][izE].push_back(P); + if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) + m_VM[ixE][iyE][izE].push_back(P); } VERIFY(PP); + m_Box.invalidate(); + for (OGFVertIt v_it = m_Verts.begin(); v_it!=m_Verts.end(); ++v_it) + m_Box.modify(v_it->P); } -CExportObjectOGF::SSplit::SSplit(CSurface* surf, const Fbox& bb) +CExportObjectOGF::SSplit::SSplit(CSurface *surf, const Fbox &bb) { - apx_box = bb; - m_Surf = surf; - m_CurrentPart = NULL; + apx_box = bb; + m_Surf = surf; + m_CurrentPart = NULL; } CExportObjectOGF::SSplit::~SSplit() { - for (COGFCPIt it=m_Parts.begin(); it!=m_Parts.end(); ++it) - xr_delete(*it); + for (COGFCPIt it = m_Parts.begin(); it!=m_Parts.end(); ++it) + xr_delete(*it); } void CExportObjectOGF::SSplit::AppendPart(int apx_vertices, int apx_faces) { - m_Parts.push_back (xr_new(apx_box,apx_vertices, apx_faces)); - m_CurrentPart = m_Parts.back(); + m_Parts.push_back(xr_new(apx_box, apx_vertices, apx_faces)); + m_CurrentPart = m_Parts.back(); } -void CExportObjectOGF::SSplit::SavePart(IWriter& F, CObjectOGFCollectorPacked* part) +void CExportObjectOGF::SSplit::SavePart(IWriter &F, CObjectOGFCollectorPacked *part) { // Header - F.open_chunk (OGF_HEADER); - ogf_header H; - H.format_version = xrOGF_FormatVersion; - H.type = (part->m_SWR.size())?MT_PROGRESSIVE:MT_NORMAL; - H.shader_id = 0; - H.bb.min = part->m_Box.min; - H.bb.max = part->m_Box.max; - part->m_Box.getsphere(H.bs.c,H.bs.r); - F.w (&H, sizeof(H)); - F.close_chunk (); + F.open_chunk(OGF_HEADER); + ogf_header H; + H.format_version = xrOGF_FormatVersion; + H.type = (part->m_SWR.size()) ? MT_PROGRESSIVE : MT_NORMAL; + H.shader_id = 0; + H.bb.min = part->m_Box.min; + H.bb.max = part->m_Box.max; + part->m_Box.getsphere(H.bs.c, H.bs.r); + F.w(&H, sizeof(H)); + F.close_chunk(); // Texture - F.open_chunk (OGF_TEXTURE); - F.w_stringZ (m_Surf->_Texture()); - F.w_stringZ (m_Surf->_ShaderName()); - F.close_chunk (); + F.open_chunk(OGF_TEXTURE); + F.w_stringZ(m_Surf->_Texture()); + F.w_stringZ(m_Surf->_ShaderName()); + F.close_chunk(); // Vertices - u32 dwFVF = D3DFVF_XYZ|D3DFVF_NORMAL|(1<m_Verts.size()); - for (OGFVertIt v_it=part->m_Verts.begin(); v_it!=part->m_Verts.end(); ++v_it) - { - SOGFVert const& pV = *v_it; - F.w (&(pV.P), sizeof(float)*3); // position (offset) - F.w (&(pV.N), sizeof(float)*3); // normal - F.w_float (pV.UV.x); - F.w_float (pV.UV.y); // tu,tv + u32 dwFVF = D3DFVF_XYZ|D3DFVF_NORMAL|(1<m_Verts.size()); + for (OGFVertIt v_it = part->m_Verts.begin(); v_it!=part->m_Verts.end(); ++v_it) + { + SOGFVert const &pV = *v_it; + F.w(&(pV.P), sizeof(float)*3); // position (offset) + F.w(&(pV.N), sizeof(float)*3); // normal + F.w_float(pV.UV.x); + F.w_float(pV.UV.y); // tu,tv } - F.close_chunk (); + F.close_chunk(); // Faces - F.open_chunk (OGF_INDICES); - F.w_u32 (part->m_Faces.size()*3); - F.w (&part->m_Faces.front(), part->m_Faces.size()*3*sizeof(u16)); - F.close_chunk (); + F.open_chunk(OGF_INDICES); + F.w_u32(part->m_Faces.size()*3); + F.w(&part->m_Faces.front(), part->m_Faces.size()*3*sizeof(u16)); + F.close_chunk(); // PMap - if (part->m_SWR.size()) - { + if (part->m_SWR.size()) + { F.open_chunk(OGF_SWIDATA); - F.w_u32 (0); // reserved space 16 bytes - F.w_u32 (0); - F.w_u32 (0); - F.w_u32 (0); - F.w_u32 (part->m_SWR.size()); // num collapses - for (u32 swr_idx=0; swr_idxm_SWR.size(); ++swr_idx) - F.w (&part->m_SWR[swr_idx],sizeof(VIPM_SWR)); + F.w_u32(0); // reserved space 16 bytes + F.w_u32(0); + F.w_u32(0); + F.w_u32(0); + F.w_u32(part->m_SWR.size()); // num collapses + for (u32 swr_idx = 0; swr_idxm_SWR.size(); ++swr_idx) + F.w(&part->m_SWR[swr_idx], sizeof(VIPM_SWR)); F.close_chunk(); } } -void CExportObjectOGF::SSplit::Save(IWriter& F, int& chunk_id) +void CExportObjectOGF::SSplit::Save(IWriter &F, int &chunk_id) { - for (COGFCPIt it=m_Parts.begin(); it!=m_Parts.end(); ++it) - { - CObjectOGFCollectorPacked* part = *it; - F.open_chunk (chunk_id); - SavePart (F, part); - F.close_chunk (); + for (COGFCPIt it = m_Parts.begin(); it!=m_Parts.end(); ++it) + { + CObjectOGFCollectorPacked *part = *it; + F.open_chunk(chunk_id); + SavePart(F, part); + F.close_chunk(); ++chunk_id; } } void CObjectOGFCollectorPacked::MakeProgressive() { - VIPM_Init (); + VIPM_Init(); - for (OGFVertIt vert_it=m_Verts.begin(); vert_it!=m_Verts.end(); ++vert_it) - VIPM_AppendVertex(vert_it->P,vert_it->UV); + for (OGFVertIt vert_it = m_Verts.begin(); vert_it!=m_Verts.end(); ++vert_it) + VIPM_AppendVertex(vert_it->P, vert_it->UV); - for (OGFFaceIt f_it=m_Faces.begin(); f_it!=m_Faces.end(); ++f_it) - VIPM_AppendFace(f_it->v[0],f_it->v[1],f_it->v[2]); + for (OGFFaceIt f_it = m_Faces.begin(); f_it!=m_Faces.end(); ++f_it) + VIPM_AppendFace(f_it->v[0], f_it->v[1], f_it->v[2]); - VIPM_Result* R = VIPM_Convert(u32(-1),1.f,1); + VIPM_Result *R = VIPM_Convert(u32(-1), 1.f, 1); if (R) - { + { // Permute vertices - OGFVertVec const temp_list = m_Verts; - for(u32 i=0; ipermute_verts[i]]=temp_list[i]; - + OGFVertVec const temp_list = m_Verts; + for (u32 i = 0; ipermute_verts[i]] = temp_list[i]; + // Fill indices - m_Faces.resize (R->indices.size()/3); - for (u32 f_idx=0; f_idxindices[f_idx*3+0]; - F.v[1] = R->indices[f_idx*3+1]; - F.v[2] = R->indices[f_idx*3+2]; + m_Faces.resize(R->indices.size()/3); + for (u32 f_idx = 0; f_idxindices[f_idx*3+0]; + F.v[1] = R->indices[f_idx*3+1]; + F.v[2] = R->indices[f_idx*3+2]; } // Fill SWR - m_SWR.resize (R->swr_records.size()); - for (u32 swr_idx=0; swr_idx!=m_SWR.size(); ++swr_idx) - m_SWR[swr_idx] = R->swr_records[swr_idx]; - - }else{ - Log("!..Can't make progressive."); + m_SWR.resize(R->swr_records.size()); + for (u32 swr_idx = 0; swr_idx!=m_SWR.size(); ++swr_idx) + m_SWR[swr_idx] = R->swr_records[swr_idx]; + } + else + { + Log("!..Can't make progressive."); } - + // cleanup - VIPM_Destroy (); + VIPM_Destroy(); } -void CObjectOGFCollectorPacked:: OptimizeTextureCoordinates() +void CObjectOGFCollectorPacked::OptimizeTextureCoordinates() { // Optimize texture coordinates // 1. Calc bounds - Fvector2 Tdelta; - Fvector2 Tmin, Tmax; - Tmin.set (flt_max, flt_max); - Tmax.set (flt_min, flt_min); - const u32 v_cnt = m_Verts.size(); + Fvector2 Tdelta; + Fvector2 Tmin, Tmax; + Tmin.set(flt_max, flt_max); + Tmax.set(flt_min, flt_min); + const u32 v_cnt = m_Verts.size(); { - for (u32 v_idx=0; v_idx!=v_cnt; v_idx++) - { - SOGFVert const& iV = m_Verts[v_idx]; - Tmin.min (iV.UV); - Tmax.max (iV.UV); - } + for (u32 v_idx = 0; v_idx!=v_cnt; v_idx++) + { + SOGFVert const &iV = m_Verts[v_idx]; + Tmin.min(iV.UV); + Tmax.max(iV.UV); + } } - Tdelta.x = floorf((Tmax.x-Tmin.x)/2+Tmin.x); - Tdelta.y = floorf((Tmax.y-Tmin.y)/2+Tmin.y); - - Fvector2 Tsize; - Tsize.sub (Tmax,Tmin); - { - // 2. Recalc UV mapping - for (u32 v_idx=0; v_idx!=v_cnt; ++v_idx) - { - SOGFVert &iV = m_Verts[v_idx]; - iV.UV.sub (Tdelta); - } + Tdelta.x = floorf((Tmax.x-Tmin.x)/2+Tmin.x); + Tdelta.y = floorf((Tmax.y-Tmin.y)/2+Tmin.y); + + Fvector2 Tsize; + Tsize.sub(Tmax, Tmin); + { + // 2. Recalc UV mapping + for (u32 v_idx = 0; v_idx!=v_cnt; ++v_idx) + { + SOGFVert&iV = m_Verts[v_idx]; + iV.UV.sub(Tdelta); + } } } void CExportObjectOGF::SSplit::MakeProgressive() { - for (COGFCPIt it=m_Parts.begin(); it!=m_Parts.end(); ++it) - (*it)->MakeProgressive(); + for (COGFCPIt it = m_Parts.begin(); it!=m_Parts.end(); ++it) + (*it)->MakeProgressive(); } -CExportObjectOGF::CExportObjectOGF(CEditableObject* object) +CExportObjectOGF::CExportObjectOGF(CEditableObject *object) { - m_Source = object; + m_Source = object; } CExportObjectOGF::~CExportObjectOGF() { - for (SplitIt it=m_Splits.begin(); it!=m_Splits.end(); ++it) - xr_delete(*it); + for (SplitIt it = m_Splits.begin(); it!=m_Splits.end(); ++it) + xr_delete(*it); } -CExportObjectOGF::SSplit* CExportObjectOGF::FindSplit(CSurface* surf) +CExportObjectOGF::SSplit *CExportObjectOGF::FindSplit(CSurface *surf) { - for (SplitIt it=m_Splits.begin(); it!=m_Splits.end(); ++it) - if ((*it)->m_Surf==surf) - return *it; + for (SplitIt it = m_Splits.begin(); it!=m_Splits.end(); ++it) + if ((*it)->m_Surf==surf) + return *it; return 0; } -bool CExportObjectOGF::PrepareMESH(CEditableMesh* MESH) +bool CExportObjectOGF::PrepareMESH(CEditableMesh *MESH) { -// // generate normals - bool bResult = true; + // // generate normals + bool bResult = true; MESH->GenerateVNormals(0); // fill faces - for (SurfFacesPairIt sp_it=MESH->m_SurfFaces.begin(); sp_it!=MESH->m_SurfFaces.end(); ++sp_it) - { - IntVec& face_lst= sp_it->second; - CSurface* surf = sp_it->first; - u32 dwTexCnt = ((surf->_FVF()&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); - R_ASSERT (dwTexCnt==1); - SSplit* split = FindSplit(surf); + for (SurfFacesPairIt sp_it = MESH->m_SurfFaces.begin(); sp_it!=MESH->m_SurfFaces.end(); ++sp_it) + { + IntVec &face_lst = sp_it->second; + CSurface*surf = sp_it->first; + u32 dwTexCnt = ((surf->_FVF()&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); + R_ASSERT(dwTexCnt==1); + SSplit*split = FindSplit(surf); if (0==split) - { + { #ifdef _EDITOR SGameMtl* M = GMLib.GetMaterialByID(surf->_GameMtl()); if (0==M) @@ -306,354 +319,359 @@ bool CExportObjectOGF::PrepareMESH(CEditableMesh* MESH) break; } #endif - m_Splits.push_back (xr_new(surf,m_Source->GetBox())); - split = m_Splits.back(); + m_Splits.push_back(xr_new(surf,m_Source->GetBox())); + split = m_Splits.back(); } - int elapsed_faces = surf->m_Flags.is(CSurface::sf2Sided) ?face_lst.size()*2 : face_lst.size(); - const bool b2sided = !!surf->m_Flags.is(CSurface::sf2Sided); - - if (0==split->m_CurrentPart) - split->AppendPart( (elapsed_faces>0xffff) ? 0xffff : elapsed_faces, - (elapsed_faces>0xffff) ? 0xffff : elapsed_faces); - - do{ - for (IntIt f_it=face_lst.begin(); f_it!=face_lst.end(); ++f_it) - { - bool bNewPart = false; - st_Face& face = MESH->m_Faces[*f_it]; + int elapsed_faces = surf->m_Flags.is(CSurface::sf2Sided) ? face_lst.size()*2 : face_lst.size(); + const bool b2sided = !!surf->m_Flags.is(CSurface::sf2Sided); + + if (0==split->m_CurrentPart) + split->AppendPart((elapsed_faces>0xffff) ? 0xffff : elapsed_faces, + (elapsed_faces>0xffff) ? 0xffff : elapsed_faces); + + do + { + for (IntIt f_it = face_lst.begin(); f_it!=face_lst.end(); ++f_it) + { + bool bNewPart = false; + st_Face&face = MESH->m_Faces[*f_it]; { SOGFVert v[3]; - for (int k=0; k<3; ++k) - { - st_FaceVert& fv = face.pv[k]; - int offs = 0; - const Fvector2* uv = 0; - for (u32 t=0; tm_VMRefs[fv.vmref].pts[t+offs]; - st_VMap& vmap = *MESH->m_VMaps[vm_pt.vmap_index]; + st_VMapPt&vm_pt = MESH->m_VMRefs[fv.vmref].pts[t+offs]; + st_VMap&vmap = *MESH->m_VMaps[vm_pt.vmap_index]; if (vmap.type!=vmtUV) { - ++offs; + ++offs; --t; continue; } - uv = &vmap.getUV(vm_pt.index); + uv = &vmap.getUV(vm_pt.index); } - R_ASSERT2 (uv,"uv empty"); - u32 norm_id = (*f_it)*3+k; - R_ASSERT2 (norm_idGetFCount()*3,"Normal index out of range."); - v[k].set (MESH->m_Vertices[fv.pindex],MESH->m_VertexNormals[norm_id],*uv); - } + R_ASSERT2(uv, "uv empty"); + u32 norm_id = (*f_it)*3+k; + R_ASSERT2(norm_idGetFCount()*3, "Normal index out of range."); + v[k].set(MESH->m_Vertices[fv.pindex], MESH->m_VertexNormals[norm_id], *uv); + } --elapsed_faces; - if (!split->m_CurrentPart->add_face(v[0], v[1], v[2])) - bNewPart = true; + if (!split->m_CurrentPart->add_face(v[0], v[1], v[2])) + bNewPart = true; if (b2sided) - { - v[0].N.invert(); v[1].N.invert(); v[2].N.invert(); - if (!split->m_CurrentPart->add_face(v[2], v[1], v[0])) - bNewPart = true; + { + v[0].N.invert(); + v[1].N.invert(); + v[2].N.invert(); + if (!split->m_CurrentPart->add_face(v[2], v[1], v[0])) + bNewPart = true; } } - if (bNewPart && (elapsed_faces>0)) - split->AppendPart( (elapsed_faces>0xffff) ? 0xffff : elapsed_faces, - (elapsed_faces>0xffff) ? 0xffff : elapsed_faces); + if (bNewPart&&(elapsed_faces>0)) + split->AppendPart((elapsed_faces>0xffff) ? 0xffff : elapsed_faces, + (elapsed_faces>0xffff) ? 0xffff : elapsed_faces); } - }while(elapsed_faces>0); + } while (elapsed_faces>0); } // mesh fin - MESH->UnloadVNormals (); - return bResult; + MESH->UnloadVNormals(); + return bResult; } -bool CExportObjectOGF::Prepare(bool gen_tb, CEditableMesh* mesh) +bool CExportObjectOGF::Prepare(bool gen_tb, CEditableMesh *mesh) { - if( (m_Source->MeshCount() == 0) ) return false; + if ((m_Source->MeshCount()==0)) + return false; - bool bResult = true; - if (mesh) - bResult = PrepareMESH(mesh); + bool bResult = true; + if (mesh) + bResult = PrepareMESH(mesh); else - { - for(EditMeshIt mesh_it=m_Source->FirstMesh();mesh_it!=m_Source->LastMesh();++mesh_it) - if (!PrepareMESH(*mesh_it)) - { - bResult = false; - break; - } + { + for (EditMeshIt mesh_it = m_Source->FirstMesh(); mesh_it!=m_Source->LastMesh(); ++mesh_it) + if (!PrepareMESH(*mesh_it)) + { + bResult = false; + break; + } } - if (!bResult) - return false; + if (!bResult) + return false; // calculate TB if (gen_tb) - { - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + { + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) (*split_it)->CalculateTB(); -// Log ("Time B: ",T.GetElapsed_sec()); + // Log ("Time B: ",T.GetElapsed_sec()); } // fill per bone vertices - if (m_Source->m_objectFlags.is(CEditableObject::eoProgressive)) - { - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + if (m_Source->m_objectFlags.is(CEditableObject::eoProgressive)) + { + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) (*split_it)->MakeProgressive(); } - // Compute bounding... - ComputeBounding (); -// Log ("Time C: ",T.GetElapsed_sec()); - return bResult; + // Compute bounding... + ComputeBounding(); + // Log ("Time C: ",T.GetElapsed_sec()); + return bResult; } -bool CExportObjectOGF::Export(IWriter& F, bool gen_tb, CEditableMesh* mesh) +bool CExportObjectOGF::Export(IWriter &F, bool gen_tb, CEditableMesh *mesh) { - if( !Prepare(gen_tb,mesh) ) - return false; + if (!Prepare(gen_tb, mesh)) + return false; - // Saving geometry... + // Saving geometry... if ((m_Splits.size()==1)&&(m_Splits[0]->m_Parts.size()==1)) - { - // export as single mesh - m_Splits[0]->SavePart(F,m_Splits[0]->m_Parts[0]); - }else - { - // export as hierrarhy mesh + { + // export as single mesh + m_Splits[0]->SavePart(F, m_Splits[0]->m_Parts[0]); + } + else + { + // export as hierrarhy mesh // Header - ogf_header H; - H.format_version= xrOGF_FormatVersion; - H.type = MT_HIERRARHY; - H.shader_id = 0; - H.bb.min = m_Box.min; - H.bb.max = m_Box.max; - m_Box.getsphere(H.bs.c,H.bs.r); - F.w_chunk (OGF_HEADER,&H,sizeof(H)); + ogf_header H; + H.format_version = xrOGF_FormatVersion; + H.type = MT_HIERRARHY; + H.shader_id = 0; + H.bb.min = m_Box.min; + H.bb.max = m_Box.max; + m_Box.getsphere(H.bs.c, H.bs.r); + F.w_chunk(OGF_HEADER, &H, sizeof(H)); // Desc - ogf_desc desc; + ogf_desc desc; m_Source->PrepareOGFDesc(desc); - F.open_chunk (OGF_S_DESC); - desc.Save (F); - F.close_chunk (); + F.open_chunk(OGF_S_DESC); + desc.Save(F); + F.close_chunk(); // OGF_CHILDREN - F.open_chunk (OGF_CHILDREN); - int chunk = 0; - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) - (*split_it)->Save(F,chunk); + F.open_chunk(OGF_CHILDREN); + int chunk = 0; + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + (*split_it)->Save(F, chunk); - F.close_chunk (); + F.close_chunk(); } - SplitIt split_it; - F.open_chunk (OGF_COLLISION_VERTICES); - for (split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) - { - SSplit* split = *split_it; - COGFCPIt it = split->m_Parts.begin(); + SplitIt split_it; + F.open_chunk(OGF_COLLISION_VERTICES); + for (split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + { + SSplit*split = *split_it; + COGFCPIt it = split->m_Parts.begin(); for (; it!=split->m_Parts.end(); ++it) { - CObjectOGFCollectorPacked* part = *it; + CObjectOGFCollectorPacked *part = *it; // vertices - OGFVertVec& VERTS = part->getV_Verts(); - OGFVertIt v_it = VERTS.begin(); - for(; v_it!=VERTS.end(); ++v_it) + OGFVertVec &VERTS = part->getV_Verts(); + OGFVertIt v_it = VERTS.begin(); + for (; v_it!=VERTS.end(); ++v_it) { - SOGFVert& V = *v_it; - F.w (&V.P, sizeof(V.P)); - } - }//parts - }//splits - F.close_chunk (); - - F.open_chunk (OGF_COLLISION_INDICES); - u32 v_offs = 0; - for (split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) - { - SSplit* split = *split_it; - COGFCPIt it = split->m_Parts.begin(); - - for(; it!=split->m_Parts.end(); ++it) - { - CObjectOGFCollectorPacked* part = *it; - OGFFaceVec& FACES = part->getV_Faces(); - OGFFaceIt f_it = FACES.begin(); - for(; f_it!=FACES.end(); ++f_it) - { - SOGFFace& Face = *f_it; - F.w_u32 (v_offs + Face.v[0]); - F.w_u32 (v_offs + Face.v[1]); - F.w_u32 (v_offs + Face.v[2]); - } - v_offs += part->getV_Verts().size(); - }//parts - }//splits - F.close_chunk (); + SOGFVert &V = *v_it; + F.w(&V.P, sizeof(V.P)); + } + }//parts + }//splits + F.close_chunk(); + + F.open_chunk(OGF_COLLISION_INDICES); + u32 v_offs = 0; + for (split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + { + SSplit*split = *split_it; + COGFCPIt it = split->m_Parts.begin(); + + for (; it!=split->m_Parts.end(); ++it) + { + CObjectOGFCollectorPacked *part = *it; + OGFFaceVec &FACES = part->getV_Faces(); + OGFFaceIt f_it = FACES.begin(); + for (; f_it!=FACES.end(); ++f_it) + { + SOGFFace &Face = *f_it; + F.w_u32(v_offs+Face.v[0]); + F.w_u32(v_offs+Face.v[1]); + F.w_u32(v_offs+Face.v[2]); + } + v_offs += part->getV_Verts().size(); + }//parts + }//splits + F.close_chunk(); return true; } -bool CExportObjectOGF::ExportAsSimple(IWriter& F) +bool CExportObjectOGF::ExportAsSimple(IWriter &F) { - if( Prepare(true,NULL) ) + if (Prepare(true, NULL)) { // Saving geometry... if ((m_Splits.size()==1)&&(m_Splits[0]->m_Parts.size()==1)) - { + { // export as single mesh m_Splits[0]->SavePart(F, m_Splits[0]->m_Parts[0]); - return true; + return true; } } return false; } -bool CExportObjectOGF::ExportAsWavefrontOBJ(IWriter& F, LPCSTR fn) +bool CExportObjectOGF::ExportAsWavefrontOBJ(IWriter &F, LPCSTR fn) { - if (!Prepare(false,NULL)) - return false; + if (!Prepare(false, NULL)) + return false; - string_path tmp, tex_path, tex_name; - string_path name, ext; - _splitpath (fn, 0, 0, name, ext ); - strcat (name,ext); + string_path tmp, tex_path, tex_name; + string_path name, ext; + _splitpath(fn, 0, 0, name, ext); + strcat(name, ext); - xr_string fn_material = EFS.ChangeFileExt(fn,".mtl"); - IWriter* Fm = FS.w_open(fn_material.c_str()); + xr_string fn_material = EFS.ChangeFileExt(fn, ".mtl"); + IWriter *Fm = FS.w_open(fn_material.c_str()); // write material file - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) { - _splitpath ((*split_it)->m_Surf->_Texture(), 0, tex_path, tex_name, 0 ); - - sprintf (tmp,"newmtl %s", tex_name); - Fm->w_string (tmp); - Fm->w_string ("Ka 0 0 0"); - Fm->w_string ("Kd 1 1 1"); - Fm->w_string ("Ks 0 0 0"); - - sprintf (tmp,"map_Kd %s\\\\%s\\%s%s\n", - "T:", - tex_path, - tex_name, - ".tga"); - Fm->w_string (tmp); + _splitpath((*split_it)->m_Surf->_Texture(), 0, tex_path, tex_name, 0); + + sprintf(tmp, "newmtl %s", tex_name); + Fm->w_string(tmp); + Fm->w_string("Ka 0 0 0"); + Fm->w_string("Kd 1 1 1"); + Fm->w_string("Ks 0 0 0"); + + sprintf(tmp, "map_Kd %s\\\\%s\\%s%s\n", + "T:", + tex_path, + tex_name, + ".tga"); + Fm->w_string(tmp); } - FS.w_close (Fm); + FS.w_close(Fm); - // writ comment - F.w_string ("# This file uses meters as units for non-parametric coordinates."); + // writ comment + F.w_string("# This file uses meters as units for non-parametric coordinates."); - _splitpath (fn, 0, 0, tex_name, 0 ); - sprintf (tmp,"mtllib %s.mtl", tex_name); - F.w_string (tmp); + _splitpath(fn, 0, 0, tex_name, 0); + sprintf(tmp, "mtllib %s.mtl", tex_name); + F.w_string(tmp); - u32 v_offs = 0; - for (split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + u32 v_offs = 0; + for (split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) { - _splitpath ((*split_it)->m_Surf->_Texture(), 0, 0, tex_name, 0 ); - sprintf (tmp,"g %d",split_it-m_Splits.begin()); - F.w_string (tmp); - sprintf (tmp,"usemtl %s",tex_name); - F.w_string (tmp); - Fvector mV; - Fmatrix mZ; - mZ.mirrorZ (); - for (COGFCPIt it=(*split_it)->m_Parts.begin(); it!=(*split_it)->m_Parts.end(); ++it) + _splitpath((*split_it)->m_Surf->_Texture(), 0, 0, tex_name, 0); + sprintf(tmp, "g %d", split_it-m_Splits.begin()); + F.w_string(tmp); + sprintf(tmp, "usemtl %s", tex_name); + F.w_string(tmp); + Fvector mV; + Fmatrix mZ; + mZ.mirrorZ(); + for (COGFCPIt it = (*split_it)->m_Parts.begin(); it!=(*split_it)->m_Parts.end(); ++it) { - CObjectOGFCollectorPacked* part = *it; + CObjectOGFCollectorPacked *part = *it; // vertices - OGFVertVec& VERTS = part->getV_Verts(); - OGFVertIt v_it; - for (v_it=VERTS.begin(); v_it!=VERTS.end(); v_it++) + OGFVertVec &VERTS = part->getV_Verts(); + OGFVertIt v_it; + for (v_it = VERTS.begin(); v_it!=VERTS.end(); v_it++) { - mZ.transform_tiny (mV,v_it->P); - sprintf (tmp,"v %f %f %f",mV.x,mV.y,mV.z); - F.w_string (tmp); + mZ.transform_tiny(mV, v_it->P); + sprintf(tmp, "v %f %f %f", mV.x, mV.y, mV.z); + F.w_string(tmp); } - for (v_it=VERTS.begin(); v_it!=VERTS.end(); ++v_it) + for (v_it = VERTS.begin(); v_it!=VERTS.end(); ++v_it) { - sprintf (tmp,"vt %f %f",v_it->UV.x,_abs(1.f-v_it->UV.y)); - F.w_string (tmp); + sprintf(tmp, "vt %f %f", v_it->UV.x, _abs(1.f-v_it->UV.y)); + F.w_string(tmp); } - for (v_it=VERTS.begin(); v_it!=VERTS.end(); ++v_it) + for (v_it = VERTS.begin(); v_it!=VERTS.end(); ++v_it) { - mZ.transform_dir (mV,v_it->N); - sprintf (tmp,"vn %f %f %f",mV.x,mV.y,mV.z); - F.w_string (tmp); + mZ.transform_dir(mV, v_it->N); + sprintf(tmp, "vn %f %f %f", mV.x, mV.y, mV.z); + F.w_string(tmp); } - for (v_it=VERTS.begin(); v_it!=VERTS.end(); ++v_it) + for (v_it = VERTS.begin(); v_it!=VERTS.end(); ++v_it) { - mZ.transform_dir (mV,v_it->T); - sprintf (tmp,"vg %f %f %f",mV.x,mV.y,mV.z); - F.w_string (tmp); + mZ.transform_dir(mV, v_it->T); + sprintf(tmp, "vg %f %f %f", mV.x, mV.y, mV.z); + F.w_string(tmp); } - for (v_it=VERTS.begin(); v_it!=VERTS.end(); ++v_it) + for (v_it = VERTS.begin(); v_it!=VERTS.end(); ++v_it) { - mZ.transform_dir (mV,v_it->B); - sprintf (tmp,"vb %f %f %f",mV.x,mV.y,mV.z); - F.w_string (tmp); + mZ.transform_dir(mV, v_it->B); + sprintf(tmp, "vb %f %f %f", mV.x, mV.y, mV.z); + F.w_string(tmp); } // faces - OGFFaceVec& FACES = part->getV_Faces(); - OGFFaceIt f_it; - for (f_it=FACES.begin(); f_it!=FACES.end(); ++f_it) + OGFFaceVec &FACES = part->getV_Faces(); + OGFFaceIt f_it; + for (f_it = FACES.begin(); f_it!=FACES.end(); ++f_it) { - sprintf (tmp,"f %d/%d/%d %d/%d/%d %d/%d/%d",v_offs+f_it->v[2]+1,v_offs+f_it->v[2]+1,v_offs+f_it->v[2]+1, - v_offs+f_it->v[1]+1,v_offs+f_it->v[1]+1,v_offs+f_it->v[1]+1, - v_offs+f_it->v[0]+1,v_offs+f_it->v[0]+1,v_offs+f_it->v[0]+1); - F.w_string (tmp); + sprintf(tmp, "f %d/%d/%d %d/%d/%d %d/%d/%d", v_offs+f_it->v[2]+1, v_offs+f_it->v[2]+1, v_offs+f_it->v[2]+1, + v_offs+f_it->v[1]+1, v_offs+f_it->v[1]+1, v_offs+f_it->v[1]+1, + v_offs+f_it->v[0]+1, v_offs+f_it->v[0]+1, v_offs+f_it->v[0]+1); + F.w_string(tmp); } - v_offs += VERTS.size(); + v_offs += VERTS.size(); } } - return true; + return true; } -bool CEditableObject::PrepareOGF(IWriter& F, u8 infl, bool gen_tb, CEditableMesh* mesh) +bool CEditableObject::PrepareOGF(IWriter &F, u8 infl, bool gen_tb, CEditableMesh *mesh) { - return IsSkeleton()?PrepareSkeletonOGF(F,infl):PrepareRigidOGF(F,gen_tb,mesh); + return IsSkeleton() ? PrepareSkeletonOGF(F, infl) : PrepareRigidOGF(F, gen_tb, mesh); } #include "ExportSkeleton.h" -bool CEditableObject::PrepareSkeletonOGF(IWriter& F, u8 infl) +bool CEditableObject::PrepareSkeletonOGF(IWriter &F, u8 infl) { CExportSkeleton E(this); float prev = g_EpsSkelPositionDelta; - if(m_objectFlags.test(eoHQExport)) + if (m_objectFlags.test(eoHQExport)) g_EpsSkelPositionDelta = EPS; - bool res = E.Export(F,infl); + bool res = E.Export(F, infl); g_EpsSkelPositionDelta = prev; return res; } -bool CEditableObject::PrepareRigidOGF(IWriter& F, bool gen_tb, CEditableMesh* mesh) +bool CEditableObject::PrepareRigidOGF(IWriter &F, bool gen_tb, CEditableMesh *mesh) { CExportObjectOGF E(this); float prev = g_EpsSkelPositionDelta; - if(m_objectFlags.test(eoHQExport)) + if (m_objectFlags.test(eoHQExport)) g_EpsSkelPositionDelta = EPS; g_EpsSkelPositionDelta = prev; - bool res = E.Export(F,gen_tb,mesh); + bool res = E.Export(F, gen_tb, mesh); return res; } -bool CEditableObject::PrepareSVGeometry(IWriter& F, u8 infl) +bool CEditableObject::PrepareSVGeometry(IWriter &F, u8 infl) { CExportSkeleton E(this); float prev = g_EpsSkelPositionDelta; - if(m_objectFlags.test(eoHQExport)) + if (m_objectFlags.test(eoHQExport)) g_EpsSkelPositionDelta = EPS; bool res = E.ExportGeometry(F, infl); @@ -664,20 +682,21 @@ bool CEditableObject::PrepareSVGeometry(IWriter& F, u8 infl) } -bool CEditableObject::PrepareSVKeys(IWriter& F) +bool CEditableObject::PrepareSVKeys(IWriter &F) { CExportSkeleton E(this); return E.ExportMotionKeys(F); } -bool CEditableObject::PrepareSVDefs(IWriter& F) +bool CEditableObject::PrepareSVDefs(IWriter &F) { CExportSkeleton E(this); return E.ExportMotionDefs(F); } -bool CEditableObject::PrepareOMF(IWriter& F) +bool CEditableObject::PrepareOMF(IWriter &F) { CExportSkeleton E(this); return E.ExportMotions(F); } + diff --git a/src/editors/ECore/Editor/ExportObjectOGF.h b/src/editors/ECore/Editor/ExportObjectOGF.h index 90a3d41b35b..de528f163c4 100644 --- a/src/editors/ECore/Editor/ExportObjectOGF.h +++ b/src/editors/ECore/Editor/ExportObjectOGF.h @@ -5,7 +5,7 @@ #include "utils/ETools/PropSlimTools.h" //--------------------------------------------------------------------------- -const int clpOGFMX = 48, clpOGFMY=16, clpOGFMZ=48; +const int clpOGFMX = 48, clpOGFMY = 16, clpOGFMZ = 48; //--------------------------------------------------------------------------- // refs class CEditableObject; @@ -13,165 +13,210 @@ class CEditableMesh; class CSurface; class CInifile; -struct SOGFVert{ - Fvector P; - Fvector N; - Fvector2 UV; - Fvector T; - Fvector B; - SOGFVert() - { - P.set (0,0,0); - N.set (0,1,0); - UV.set (0.f,0.f); - T.set (0,0,0); - B.set (0,0,0); - } - void set(Fvector const& p, Fvector const& n, Fvector2 const& uv) - { - P.set (p); - N.set (n); - UV.set (uv); - } - BOOL similar_pos(SOGFVert& V) - { - return P.similar(V.P,EPS_L); +struct SOGFVert +{ + Fvector P; + Fvector N; + Fvector2 UV; + Fvector T; + Fvector B; + + SOGFVert() + { + P.set(0, 0, 0); + N.set(0, 1, 0); + UV.set(0.f, 0.f); + T.set(0, 0, 0); + B.set(0, 0, 0); + } + + void set(Fvector const &p, Fvector const &n, Fvector2 const &uv) + { + P.set(p); + N.set(n); + UV.set(uv); + } + + BOOL similar_pos(SOGFVert &V) + { + return P.similar(V.P, EPS_L); + } + + BOOL similar(SOGFVert &V) + { + if (!P.similar(V.P, EPS_L)) + return FALSE; + if (!UV.similar(V.UV, EPS_S)) + return FALSE; + if (!N.similar(V.N, EPS_L)) + return FALSE; + return TRUE; } - BOOL similar(SOGFVert& V) - { - if (!P.similar (V.P,EPS_L)) return FALSE; - if (!UV.similar (V.UV,EPS_S)) return FALSE; - if (!N.similar (V.N,EPS_L)) return FALSE; - return TRUE; - } }; -struct SOGFFace{ - WORD v[3]; +struct SOGFFace +{ + WORD v[3]; }; -DEFINE_VECTOR(SOGFVert,OGFVertVec,OGFVertIt); -DEFINE_VECTOR(SOGFFace,OGFFaceVec,OGFFaceIt); +DEFINE_VECTOR(SOGFVert, OGFVertVec, OGFVertIt); +DEFINE_VECTOR(SOGFFace, OGFFaceVec, OGFFaceIt); class CObjectOGFCollectorPacked { public: -// Fobb m_OBB; - Fbox m_Box; - - OGFVertVec m_Verts; - OGFFaceVec m_Faces; + // Fobb m_OBB; + Fbox m_Box; + + OGFVertVec m_Verts; + OGFFaceVec m_Faces; // Progressive - ArbitraryList m_SWR;// The records of the collapses. + ArbitraryList m_SWR;// The records of the collapses. - Fvector m_VMmin, m_VMscale; - U32Vec m_VM[clpOGFMX+1][clpOGFMY+1][clpOGFMZ+1]; - Fvector m_VMeps; + Fvector m_VMmin, m_VMscale; + U32Vec m_VM[clpOGFMX+1][clpOGFMY+1][clpOGFMZ+1]; + Fvector m_VMeps; - u16 VPack (SOGFVert& V); - void ComputeBounding (); - void OptimizeTextureCoordinates(); + u16 VPack(SOGFVert &V); + void ComputeBounding(); + void OptimizeTextureCoordinates(); public: - CObjectOGFCollectorPacked (const Fbox &bb, int apx_vertices, int apx_faces); - void CalculateTB (); - void MakeProgressive (); - IC bool check (SOGFFace& F) - { - if ((F.v[0]==F.v[1]) || (F.v[0]==F.v[2]) || (F.v[1]==F.v[2])) - return false; - else - return true; + CObjectOGFCollectorPacked(const Fbox &bb, int apx_vertices, int apx_faces); + void CalculateTB(); + void MakeProgressive(); + IC + + bool check(SOGFFace &F) + { + if ((F.v[0]==F.v[1])||(F.v[0]==F.v[2])||(F.v[1]==F.v[2])) + return false; + else + return true; } - IC bool add_face (SOGFVert& v0, SOGFVert& v1, SOGFVert& v2) - { - if (v0.P.similar(v1.P,EPS) || v0.P.similar(v2.P,EPS) || v1.P.similar(v2.P,EPS)) - { - ELog.Msg(mtError,"Degenerate face found. Removed."); + + IC + + bool add_face(SOGFVert &v0, SOGFVert &v1, SOGFVert &v2) + { + if (v0.P.similar(v1.P, EPS)||v0.P.similar(v2.P, EPS)||v1.P.similar(v2.P, EPS)) + { + ELog.Msg(mtError, "Degenerate face found. Removed."); return true; } SOGFFace F; u16 v; - v = VPack(v0); if (0xffff==v) return false; F.v[0] = v; - v = VPack(v1); if (0xffff==v) return false; F.v[1] = v; - v = VPack(v2); if (0xffff==v) return false; F.v[2] = v; - - if (check(F)) - m_Faces.push_back(F); + v = VPack(v0); + if (0xffff==v) + return false; + F.v[0] = v; + v = VPack(v1); + if (0xffff==v) + return false; + F.v[1] = v; + v = VPack(v2); + if (0xffff==v) + return false; + F.v[2] = v; + + if (check(F)) + m_Faces.push_back(F); else - { - ELog.Msg(mtError,"Duplicate(degenerate) face found. Removed."); + { + ELog.Msg(mtError, "Duplicate(degenerate) face found. Removed."); return true; } return true; } - IC OGFVertVec& getV_Verts () {return m_Verts;} - IC OGFFaceVec& getV_Faces () {return m_Faces;} - IC SOGFVert* getVert () {return &m_Verts.front();} - IC u32 getVS () {return m_Verts.size();} - IC u32 getTS () {return m_Faces.size();} + + IC OGFVertVec&getV_Verts() + { + return m_Verts; + } + + IC OGFFaceVec&getV_Faces() + { + return m_Faces; + } + + IC SOGFVert*getVert() + { + return &m_Verts.front(); + } + + IC u32 getVS() + { + return m_Verts.size(); + } + + IC u32 getTS() + { + return m_Faces.size(); + } }; + //---------------------------------------------------- -DEFINE_VECTOR(CObjectOGFCollectorPacked*,COGFCPVec,COGFCPIt) +DEFINE_VECTOR(CObjectOGFCollectorPacked *, COGFCPVec, COGFCPIt) class ECORE_API CExportObjectOGF { struct SSplit { - Fbox apx_box; - - COGFCPVec m_Parts; - CObjectOGFCollectorPacked* m_CurrentPart; - - Fbox m_Box; - CSurface* m_Surf; + Fbox apx_box; + + COGFCPVec m_Parts; + CObjectOGFCollectorPacked*m_CurrentPart; + + Fbox m_Box; + CSurface*m_Surf; // Progressive - void AppendPart (int apx_vertices, int apx_faces); - void SavePart (IWriter& F, CObjectOGFCollectorPacked* part); - void Save (IWriter& F, int& chunk_id); + void AppendPart(int apx_vertices, int apx_faces); + void SavePart(IWriter&F, CObjectOGFCollectorPacked*part); + void Save(IWriter&F, int& chunk_id); - void CalculateTB () + void CalculateTB() { - for (COGFCPIt it=m_Parts.begin(); it!=m_Parts.end(); it++) - (*it)->CalculateTB (); + for (COGFCPIt it = m_Parts.begin(); it!=m_Parts.end(); it++) + (*it)->CalculateTB(); } - void MakeProgressive (); - SSplit (CSurface* surf, const Fbox& bb); - ~SSplit (); - void ComputeBounding () + void MakeProgressive(); + SSplit(CSurface*surf, const Fbox&bb); + ~SSplit(); + void ComputeBounding() { m_Box.invalidate(); - for (COGFCPIt it=m_Parts.begin(); it!=m_Parts.end(); it++){ - CObjectOGFCollectorPacked* part = *it; - part->ComputeBounding (); - m_Box.merge (part->m_Box); + for (COGFCPIt it = m_Parts.begin(); it!=m_Parts.end(); it++){ + CObjectOGFCollectorPacked*part = *it; + part->ComputeBounding(); + m_Box.merge(part->m_Box); } } }; - DEFINE_VECTOR (SSplit*,SplitVec,SplitIt); - SplitVec m_Splits; - CEditableObject* m_Source; - Fbox m_Box; -//---------------------------------------------------- -// void ComputeOBB (Fobb &B, FvectorVec& V); - SSplit* FindSplit (CSurface* surf); - void ComputeBounding () + DEFINE_VECTOR(SSplit*, SplitVec, SplitIt); + SplitVec m_Splits; + CEditableObject*m_Source; + Fbox m_Box; + //---------------------------------------------------- + // void ComputeOBB (Fobb &B, FvectorVec& V); + SSplit*FindSplit(CSurface*surf); + void ComputeBounding() { m_Box.invalidate(); - for (SplitIt it=m_Splits.begin(); it!=m_Splits.end(); it++){ - (*it)->ComputeBounding (); - m_Box.merge ((*it)->m_Box); + for (SplitIt it = m_Splits.begin(); it!=m_Splits.end(); it++){ + (*it)->ComputeBounding(); + m_Box.merge((*it)->m_Box); } } - bool PrepareMESH (CEditableMesh* mesh); - bool Prepare (bool gen_tb, CEditableMesh* mesh); -public: - CExportObjectOGF (CEditableObject* object); - ~CExportObjectOGF (); - bool Export (IWriter& F, bool gen_tb=true, CEditableMesh* mesh=NULL); - bool ExportAsSimple (IWriter& F); - bool ExportAsWavefrontOBJ(IWriter& F, LPCSTR fn); + bool PrepareMESH(CEditableMesh*mesh); + bool Prepare(bool gen_tb, CEditableMesh*mesh); + public: + CExportObjectOGF(CEditableObject*object); + ~CExportObjectOGF(); + bool Export(IWriter&F, bool gen_tb = true, CEditableMesh*mesh = NULL); + bool ExportAsSimple(IWriter&F); + bool ExportAsWavefrontOBJ(IWriter&F, LPCSTR fn); }; #endif + diff --git a/src/editors/ECore/Editor/ExportObjectOGFCalculateTB.cpp b/src/editors/ECore/Editor/ExportObjectOGFCalculateTB.cpp index af2b43a3469..d8a5233a529 100644 --- a/src/editors/ECore/Editor/ExportObjectOGFCalculateTB.cpp +++ b/src/editors/ECore/Editor/ExportObjectOGFCalculateTB.cpp @@ -2,10 +2,10 @@ #pragma hdrstop #include "ExportObjectOGF.h" -#include "common/nvMender2003/nvmeshmender.h" -#include "common/NvMender2003/nvMeshMender.h" -#include "common/NvMender2003/mender_input_output.h" -#include "common/NvMender2003/remove_isolated_verts.h" +#include "Common/NvMender2003/NVMeshMender.h" +#include "Common/NvMender2003/NVMeshMender.h" +#include "Common/NvMender2003/mender_input_output.h" +#include "Common/NvMender2003/remove_isolated_verts.h" IC void set_vertex( MeshMender::Vertex &out_vertex, const SOGFVert& in_vertex ) { diff --git a/src/editors/ECore/Editor/ExportSkeleton.cpp b/src/editors/ECore/Editor/ExportSkeleton.cpp index c9494c08cc4..0baba0d5219 100644 --- a/src/editors/ECore/Editor/ExportSkeleton.cpp +++ b/src/editors/ECore/Editor/ExportSkeleton.cpp @@ -14,546 +14,584 @@ #include "MgcCont3DMinBox.h" #ifdef _EDITOR #include "ui_main.h" -#include "ui_toolscustom.h" +#include "UI_ToolsCustom.h" #endif ECORE_API BOOL g_force16BitTransformQuant = FALSE; -ECORE_API float g_EpsSkelPositionDelta = EPS_L; +ECORE_API +float g_EpsSkelPositionDelta = EPS_L; -u16 CSkeletonCollectorPacked::VPack(SSkelVert& V) +u16 CSkeletonCollectorPacked::VPack(SSkelVert &V) { - u32 P = 0xffffffff; + u32 P = 0xffffffff; - u32 ix,iy,iz; + u32 ix, iy, iz; ix = iFloor(float(V.offs.x-m_VMmin.x)/m_VMscale.x*clpSMX); iy = iFloor(float(V.offs.y-m_VMmin.y)/m_VMscale.y*clpSMY); iz = iFloor(float(V.offs.z-m_VMmin.z)/m_VMscale.z*clpSMZ); - R_ASSERT(ix<=clpSMX && iy<=clpSMY && iz<=clpSMZ); + R_ASSERT(ix<=clpSMX&&iy<=clpSMY&&iz<=clpSMZ); - int similar_pos=-1; + int similar_pos = -1; { - U32Vec& vl=m_VM[ix][iy][iz]; - for(U32It it=vl.begin();it!=vl.end(); it++){ - SSkelVert& src=m_Verts[*it]; - if(src.similar_pos(V)){ - if(src.similar(V)){ + U32Vec &vl = m_VM[ix][iy][iz]; + for (U32It it = vl.begin(); it!=vl.end(); it++) + { + SSkelVert&src = m_Verts[*it]; + if (src.similar_pos(V)) + { + if (src.similar(V)) + { P = *it; break; - } - similar_pos=*it; + } + similar_pos = *it; } } } if (0xffffffff==P) { - if (similar_pos>=0) V.offs.set(m_Verts[similar_pos].offs); + if (similar_pos>=0) + V.offs.set(m_Verts[similar_pos].offs); P = m_Verts.size(); m_Verts.push_back(V); m_VM[ix][iy][iz].push_back(P); - u32 ixE,iyE,izE; + u32 ixE, iyE, izE; ixE = iFloor(float(V.offs.x+m_VMeps.x-m_VMmin.x)/m_VMscale.x*clpSMX); iyE = iFloor(float(V.offs.y+m_VMeps.y-m_VMmin.y)/m_VMscale.y*clpSMY); izE = iFloor(float(V.offs.z+m_VMeps.z-m_VMmin.z)/m_VMscale.z*clpSMZ); - R_ASSERT(ixE<=clpSMX && iyE<=clpSMY && izE<=clpSMZ); - - if (ixE!=ix) m_VM[ixE][iy][iz].push_back (P); - if (iyE!=iy) m_VM[ix][iyE][iz].push_back (P); - if (izE!=iz) m_VM[ix][iy][izE].push_back (P); - if ((ixE!=ix)&&(iyE!=iy)) m_VM[ixE][iyE][iz].push_back(P); - if ((ixE!=ix)&&(izE!=iz)) m_VM[ixE][iy][izE].push_back(P); - if ((iyE!=iy)&&(izE!=iz)) m_VM[ix][iyE][izE].push_back(P); - if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) m_VM[ixE][iyE][izE].push_back(P); + R_ASSERT(ixE<=clpSMX&&iyE<=clpSMY&&izE<=clpSMZ); + + if (ixE!=ix) + m_VM[ixE][iy][iz].push_back(P); + if (iyE!=iy) + m_VM[ix][iyE][iz].push_back(P); + if (izE!=iz) + m_VM[ix][iy][izE].push_back(P); + if ((ixE!=ix)&&(iyE!=iy)) + m_VM[ixE][iyE][iz].push_back(P); + if ((ixE!=ix)&&(izE!=iz)) + m_VM[ixE][iy][izE].push_back(P); + if ((iyE!=iy)&&(izE!=iz)) + m_VM[ix][iyE][izE].push_back(P); + if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) + m_VM[ixE][iyE][izE].push_back(P); } - VERIFY (Pm_ShaderName; - m_Texture = surf->m_Texture; - m_PartID = part; + //. m_b2Link = FALSE; + m_SkeletonLinkType = 1; + m_Shader = surf->m_ShaderName; + m_Texture = surf->m_Texture; + m_PartID = part; } -//---------------------------------------------------- - +//---------------------------------------------------- class VertexCache { - public: - VertexCache (int size); - VertexCache (); - ~VertexCache (); + VertexCache(int size); + VertexCache(); + ~VertexCache(); - bool InCache (int entry); - int AddEntry(int entry); - void Clear (); + bool InCache(int entry); + int AddEntry(int entry); + void Clear(); - void Copy (VertexCache* inVcache); - int At (int index); - void Set (int index, int value); + void Copy(VertexCache *inVcache); + int At(int index); + void Set(int index, int value); private: - xr_vector entries; + xr_vector entries; }; -IC bool VertexCache::InCache(int entry) +IC + +bool VertexCache::InCache(int entry) { - bool returnVal = false; - - for(u32 i = 0; i < entries.size(); i++) - { - if(entries[i] == entry) - { - returnVal = true; - break; - } - } - - return returnVal; + bool returnVal = false; + + for (u32 i = 0; i= 0; i--) - { - entries[i + 1] = entries[i]; - } + //push everything right one + for (int i = (u32)entries.size()-2; i>=0; i--) + { + entries[i+1] = entries[i]; + } - entries[0] = entry; + entries[0] = entry; - return removed; + return removed; } VertexCache::VertexCache() { - VertexCache(24); + VertexCache(24); } VertexCache::VertexCache(int size) { - entries.assign (size,-1); + entries.assign(size, -1); } VertexCache::~VertexCache() { - entries.clear (); + entries.clear(); } -int VertexCache::At (int index) +int VertexCache::At(int index) { - return entries[index]; + return entries[index]; } void VertexCache::Set(int index, int value) { - entries[index] = value; + entries[index] = value; } void VertexCache::Clear() { - for(u32 i = 0; i < entries.size(); i++) - entries[i] = -1; + for (u32 i = 0; iSet(i, entries[i]); - } + for (u32 i = 0; iSet(i, entries[i]); + } } -int xrSimulate (u16* indices, u32 i_cnt, int iCacheSize ) +int xrSimulate(u16 *indices, u32 i_cnt, int iCacheSize) { - VertexCache C(iCacheSize); - - int count=0; - for (u32 i=0; i= pV.bones.size() ); - for(i=0; i=pV.bones.size()); + for (i = 0; iw_string (tmp.c_str()); - } - // face - for (SkelFaceIt f_it=m_Faces.begin(); f_it!=m_Faces.end(); f_it++){ - SSkelFace& pF = *f_it; - AnsiString tmp; - tmp.sprintf ("f %d %d %d",pF.v[0]+1,pF.v[2]+1,pF.v[1]+1); - W->w_string (tmp.c_str()); - } - // normals - W->w_string ("bind n vertex"); - for (v_it=m_Verts.begin(); v_it!=m_Verts.end(); v_it++){ - SSkelVert& pV = *v_it; - AnsiString tmp; - tmp.sprintf ("n %f %f %f",pV.N.x,pV.N.y,-pV.N.z); - W->w_string (tmp.c_str()); + // SMF + /* + if (0){ + static u32 chunk_id = 0; chunk_id++; + AnsiString r=AnsiString("x:\\import\\test")+chunk_id+".smf"; + IWriter* W = FS._w_open(r.c_str()); + for (SkelVertIt v_it=m_Verts.begin(); v_it!=m_Verts.end(); v_it++){ + SSkelVert& pV = *v_it; + // vertices + AnsiString tmp; + tmp.sprintf ("v %f %f %f",pV.O.x,pV.O.y,-pV.O.z); + W->w_string (tmp.c_str()); + } + // face + for (SkelFaceIt f_it=m_Faces.begin(); f_it!=m_Faces.end(); f_it++){ + SSkelFace& pF = *f_it; + AnsiString tmp; + tmp.sprintf ("f %d %d %d",pF.v[0]+1,pF.v[2]+1,pF.v[1]+1); + W->w_string (tmp.c_str()); + } + // normals + W->w_string ("bind n vertex"); + for (v_it=m_Verts.begin(); v_it!=m_Verts.end(); v_it++){ + SSkelVert& pV = *v_it; + AnsiString tmp; + tmp.sprintf ("n %f %f %f",pV.N.x,pV.N.y,-pV.N.z); + W->w_string (tmp.c_str()); + } + FS.w_close (W); } - FS.w_close (W); - } -*/ + */ } - void CExportSkeleton::SSplit::MakeProgressive() { - VIPM_Init (); - for (SkelVertIt vert_it=m_Verts.begin(); vert_it!=m_Verts.end(); vert_it++) - VIPM_AppendVertex(vert_it->offs,vert_it->uv); - for (SkelFaceIt f_it=m_Faces.begin(); f_it!=m_Faces.end(); f_it++) - VIPM_AppendFace(f_it->v[0],f_it->v[1],f_it->v[2]); + VIPM_Init(); + for (SkelVertIt vert_it = m_Verts.begin(); vert_it!=m_Verts.end(); vert_it++) + VIPM_AppendVertex(vert_it->offs, vert_it->uv); + for (SkelFaceIt f_it = m_Faces.begin(); f_it!=m_Faces.end(); f_it++) + VIPM_AppendFace(f_it->v[0], f_it->v[1], f_it->v[2]); - VIPM_Result* R = VIPM_Convert(u32(-1),1.f,1); + VIPM_Result *R = VIPM_Convert(u32(-1), 1.f, 1); - if (R){ + if (R) + { // Permute vertices SkelVertVec temp_list = m_Verts; - for(u32 i=0; ipermute_verts[i]]=temp_list[i]; - + for (u32 i = 0; ipermute_verts[i]] = temp_list[i]; + // Fill indices - m_Faces.resize (R->indices.size()/3); - for (u32 f_idx=0; f_idxindices[f_idx*3+0]; - F.v[1] = R->indices[f_idx*3+1]; - F.v[2] = R->indices[f_idx*3+2]; + m_Faces.resize(R->indices.size()/3); + for (u32 f_idx = 0; f_idxindices[f_idx*3+0]; + F.v[1] = R->indices[f_idx*3+1]; + F.v[2] = R->indices[f_idx*3+2]; } // Fill SWR - m_SWR.resize (R->swr_records.size()); - for (u32 swr_idx=0; swr_idx!=m_SWR.size(); swr_idx++) - m_SWR[swr_idx] = R->swr_records[swr_idx]; - }else{ - Log("!..Can't make progressive."); + m_SWR.resize(R->swr_records.size()); + for (u32 swr_idx = 0; swr_idx!=m_SWR.size(); swr_idx++) + m_SWR[swr_idx] = R->swr_records[swr_idx]; } - + else + { + Log("!..Can't make progressive."); + } + // cleanup - VIPM_Destroy (); + VIPM_Destroy(); } void CExportSkeleton::SSplit::MakeStripify() { -// int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); -// Log("SRC:",ccc); - // alternative stripification - faces + // int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); + // Log("SRC:",ccc); + // alternative stripification - faces { - DWORD* remap = xr_alloc (m_Faces.size()); - HRESULT rhr = D3DXOptimizeFaces (&m_Faces.front(),m_Faces.size(),m_Verts.size(),FALSE,remap); - R_CHK (rhr); - SkelFaceVec _source = m_Faces; - for (u32 it=0; it<_source.size(); it++) + DWORD *remap = xr_alloc(m_Faces.size()); + HRESULT rhr = D3DXOptimizeFaces(&m_Faces.front(), m_Faces.size(), m_Verts.size(), FALSE, remap); + R_CHK(rhr); + SkelFaceVec _source = m_Faces; + for (u32 it = 0; it<_source.size(); it++) m_Faces[it] = _source[remap[it]]; - xr_free (remap); + xr_free(remap); -// int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); -// Log("X:",ccc); + // int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); + // Log("X:",ccc); } // alternative stripification - vertices { - DWORD* remap = xr_alloc (m_Verts.size()); - HRESULT rhr = D3DXOptimizeVertices (&m_Faces.front(),m_Faces.size(),m_Verts.size(),FALSE,remap); - R_CHK (rhr); - SkelVertVec _source = m_Verts; - - for(u32 vit=0; vit<_source.size(); vit++) - m_Verts[remap[vit]] = _source[vit]; - - for(u32 fit=0; fit<(u32)m_Faces.size(); ++fit) - for (u32 j=0; j<3; j++) - m_Faces[fit].v[j]= remap[m_Faces[fit].v[j]]; - - xr_free (remap); - -// int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); -// Log("Y:",ccc); + DWORD *remap = xr_alloc(m_Verts.size()); + HRESULT rhr = D3DXOptimizeVertices(&m_Faces.front(), m_Faces.size(), m_Verts.size(), FALSE, remap); + R_CHK(rhr); + SkelVertVec _source = m_Verts; + + for (u32 vit = 0; vit<_source.size(); vit++) + m_Verts[remap[vit]] = _source[vit]; + + for (u32 fit = 0; fit<(u32)m_Faces.size(); ++fit) + for (u32 j = 0; j<3; j++) + m_Faces[fit].v[j] = remap[m_Faces[fit].v[j]]; + + xr_free(remap); + + // int ccc = xrSimulate ((u16*)&m_Faces.front(),m_Faces.size()*3,24); + // Log("Y:",ccc); } } -CExportSkeleton::CExportSkeleton(CEditableObject* object) +CExportSkeleton::CExportSkeleton(CEditableObject *object) { - m_Source=object; + m_Source = object; } + //---------------------------------------------------- #include "editors/ECore/WildMagic/WmlMath.h" #include "editors/ECore/WildMagic/WmlContMinBox3.h" #include "editors/ECore/WildMagic/WmlContBox3.h" -extern BOOL RAPIDMinBox(Fobb& B, Fvector* vertices, u32 v_count); -void ComputeOBB_RAPID (Fobb &B, FvectorVec& V, u32 t_cnt) +extern BOOL RAPIDMinBox(Fobb &B, Fvector *vertices, u32 v_count); + +void ComputeOBB_RAPID(Fobb &B, FvectorVec &V, u32 t_cnt) { - VERIFY (t_cnt==(V.size()/3)); - if ((t_cnt<1)||(V.size()<3)) - { - B.invalidate(); - return; - } - RAPIDMinBox (B, &V.front(), V.size()); + VERIFY(t_cnt==(V.size()/3)); + if ((t_cnt<1)||(V.size()<3)) + { + B.invalidate(); + return; + } + RAPIDMinBox(B, &V.front(), V.size()); // Normalize rotation matrix (???? ???????? ContOrientedBox - ?????? ????? ???????) - B.m_rotate.i.crossproduct(B.m_rotate.j,B.m_rotate.k); - B.m_rotate.j.crossproduct(B.m_rotate.k,B.m_rotate.i); + B.m_rotate.i.crossproduct(B.m_rotate.j, B.m_rotate.k); + B.m_rotate.j.crossproduct(B.m_rotate.k, B.m_rotate.i); - VERIFY (_valid(B.m_rotate)&&_valid(B.m_translate)&&_valid(B.m_halfsize)); + VERIFY(_valid(B.m_rotate)&&_valid(B.m_translate)&&_valid(B.m_halfsize)); } -void ComputeOBB_WML (Fobb &B, FvectorVec& V) +void ComputeOBB_WML(Fobb &B, FvectorVec &V) { - if (V.size()<3) { B.invalidate(); return; } - float HV = flt_max; + if (V.size()<3) + { + B.invalidate(); + return; + } + float HV = flt_max; { - Wml::Box3 BOX; + Wml::Box3 BOX; Wml::MinBox3 mb(V.size(), (const Wml::Vector3*) &V.front(), BOX); - float hv = BOX.Extents()[0]*BOX.Extents()[1]*BOX.Extents()[2]; - if (hvm_Shader.equal(shader) && - it->m_Texture.equal(texture) && - (it->m_PartID==part_id) ) + for (SplitIt it = m_Splits.begin(); it!=m_Splits.end(); it++) + if (it->m_Shader.equal(shader)&& + it->m_Texture.equal(texture)&& + (it->m_PartID==part_id)) - return it-m_Splits.begin(); + return it-m_Splits.begin(); return -1; } -IC void BuildGroups(CBone* B, U16Vec& tgt, u16 id, u16& last_id) +IC + +void BuildGroups(CBone *B, U16Vec &tgt, u16 id, u16 &last_id) { - if (B->IK_data.ik_flags.is(SJointIKData::flBreakable)) id = ++last_id; - tgt[B->SelfID] = id; - for (BoneIt bone_it=B->children.begin(); bone_it!=B->children.end(); bone_it++) - BuildGroups (*bone_it,tgt,id,last_id); + if (B->IK_data.ik_flags.is(SJointIKData::flBreakable)) + id = ++last_id; + tgt[B->SelfID] = id; + for (BoneIt bone_it = B->children.begin(); bone_it!=B->children.end(); bone_it++) + BuildGroups(*bone_it, tgt, id, last_id); } bool CExportSkeleton::PrepareGeometry(u8 influence) { - if( m_Source->MeshCount() == 0 ) return false; + if (m_Source->MeshCount()==0) + return false; - if (m_Source->BoneCount()<1){ - ELog.Msg(mtError,"There are no bones in the object."); - return false; + if (m_Source->BoneCount()<1) + { + ELog.Msg(mtError, "There are no bones in the object."); + return false; } - if (m_Source->BoneCount()>64){ - ELog.Msg(mtError,"Object cannot handle more than 64 bones."); - return false; + if (m_Source->BoneCount()>64) + { + ELog.Msg(mtError, "Object cannot handle more than 64 bones."); + return false; } // mem active motion - CSMotion* active_motion=m_Source->ResetSAnimation(); + CSMotion *active_motion = m_Source->ResetSAnimation(); R_ASSERT(m_Source->IsDynamic()&&m_Source->IsSkeleton()); @@ -562,140 +600,148 @@ bool CExportSkeleton::PrepareGeometry(u8 influence) pb->Inc (); #endif - bool bBreakable = false; - U16Vec bone_brk_parts(m_Source->BoneCount()); - CBone* root = 0; - for (BoneIt bone_it=m_Source->FirstBone(); bone_it!=m_Source->LastBone(); bone_it++){ - CBone* B = *bone_it; - if (B->IK_data.ik_flags.is(SJointIKData::flBreakable)) bBreakable = true; - if (B->IsRoot()) root = B; + bool bBreakable = false; + U16Vec bone_brk_parts(m_Source->BoneCount()); + CBone *root = 0; + for (BoneIt bone_it = m_Source->FirstBone(); bone_it!=m_Source->LastBone(); bone_it++) + { + CBone *B = *bone_it; + if (B->IK_data.ik_flags.is(SJointIKData::flBreakable)) + bBreakable = true; + if (B->IsRoot()) + root = B; } - if (bBreakable){ - VERIFY (root); - u16 last_id = 0; - BuildGroups (root,bone_brk_parts,0,last_id); + if (bBreakable) + { + VERIFY(root); + u16 last_id = 0; + BuildGroups(root, bone_brk_parts, 0, last_id); } - for (U16It uit=bone_brk_parts.begin(); uit!=bone_brk_parts.end(); uit++){ - Msg ("Bone: %s - Part: %d",*m_Source->GetBone(uit-bone_brk_parts.begin())->Name(),*uit); + for (U16It uit = bone_brk_parts.begin(); uit!=bone_brk_parts.end(); uit++) + { + Msg("Bone: %s - Part: %d", *m_Source->GetBone(uit-bone_brk_parts.begin())->Name(), *uit); } - - bool bRes = true; + + bool bRes = true; #ifdef _EDITOR UI->SetStatus ("..Split meshes"); #endif - U16Vec tmp_bone_lst; + U16Vec tmp_bone_lst; - for(EditMeshIt mesh_it=m_Source->FirstMesh();mesh_it!=m_Source->LastMesh();mesh_it++) + for (EditMeshIt mesh_it = m_Source->FirstMesh(); mesh_it!=m_Source->LastMesh(); mesh_it++) { - if (!bRes) break; + if (!bRes) + break; - CEditableMesh* MESH = *mesh_it; + CEditableMesh*MESH = *mesh_it; // generate vertex offset - MESH->GenerateVNormals (0); - MESH->GenerateFNormals (); - MESH->GenerateSVertices (influence); + MESH->GenerateVNormals(0); + MESH->GenerateFNormals(); + MESH->GenerateSVertices(influence); #ifdef _EDITOR pb->Inc (); #endif - // fill faces - for (SurfFacesPairIt sp_it=MESH->m_SurfFaces.begin(); sp_it!=MESH->m_SurfFaces.end(); sp_it++) + // fill faces + for (SurfFacesPairIt sp_it = MESH->m_SurfFaces.begin(); sp_it!=MESH->m_SurfFaces.end(); sp_it++) { - if (!bRes) break; - IntVec& face_lst = sp_it->second; - CSurface* surf = sp_it->first; - u32 dwTexCnt = ((surf->_FVF()&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); - R_ASSERT (dwTexCnt==1); - - for (IntIt f_it=face_lst.begin(); f_it!=face_lst.end(); f_it++) + if (!bRes) + break; + IntVec &face_lst = sp_it->second; + CSurface*surf = sp_it->first; + u32 dwTexCnt = ((surf->_FVF()&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); + R_ASSERT(dwTexCnt==1); + + for (IntIt f_it = face_lst.begin(); f_it!=face_lst.end(); f_it++) { - if (!bRes) break; - int f_idx = *f_it; + if (!bRes) + break; + int f_idx = *f_it; { - SSkelVert v[3]; - tmp_bone_lst.clear_not_free (); - u32 link_type = _max(MESH->m_SVertices[f_idx*3+0].bones.size(),MESH->m_SVertices[f_idx*3+1].bones.size()); - link_type = _max(link_type,MESH->m_SVertices[f_idx*3+2].bones.size()); - VERIFY (link_type>0 && link_type<=(u32)influence); + SSkelVert v[3]; + tmp_bone_lst.clear_not_free(); + u32 link_type = _max(MESH->m_SVertices[f_idx*3+0].bones.size(), MESH->m_SVertices[f_idx*3+1].bones.size()); + link_type = _max(link_type, MESH->m_SVertices[f_idx*3+2].bones.size()); + VERIFY(link_type>0&&link_type<=(u32)influence); - for (int k=0; k<3; k++) + for (int k = 0; k<3; k++) { - st_SVert& sv = MESH->m_SVertices[f_idx*3+k]; - VERIFY (sv.bones.size()>0 && (u8)sv.bones.size()<=influence); + st_SVert&sv = MESH->m_SVertices[f_idx*3+k]; + VERIFY(sv.bones.size()>0&&(u8)sv.bones.size()<=influence); if (link_type==1) { - st_SVert::bone b[2]; - b[0].id = sv.bones[0].id; - b[1].id = sv.bones[0].id; - b[0].w = 1.f; - b[1].w = 0.f; - v[k].set (sv.offs,sv.norm,sv.uv,2,b); - tmp_bone_lst.push_back (sv.bones[0].id); - }else - if(link_type==2) + st_SVert::bone b[2]; + b[0].id = sv.bones[0].id; + b[1].id = sv.bones[0].id; + b[0].w = 1.f; + b[1].w = 0.f; + v[k].set(sv.offs, sv.norm, sv.uv, 2, b); + tmp_bone_lst.push_back(sv.bones[0].id); + } + else if (link_type==2) { { - v[k].set (sv.offs,sv.norm,sv.uv,(u8)sv.bones.size(),sv.bones.begin()); + v[k].set(sv.offs, sv.norm, sv.uv, (u8)sv.bones.size(), sv.bones.begin()); - for(u32 i=0; im_ShaderName,surf->m_Texture,bone_brk_part); + int mtl_idx = FindSplit(surf->m_ShaderName, surf->m_Texture, bone_brk_part); if (mtl_idx<0) { - m_Splits.push_back (SSplit(surf,m_Source->GetBox(),bone_brk_part)); - mtl_idx = m_Splits.size()-1; + m_Splits.push_back(SSplit(surf, m_Source->GetBox(), bone_brk_part)); + mtl_idx = m_Splits.size()-1; m_Splits[mtl_idx].m_SkeletonLinkType = 0; } - SSplit& cur_split = m_Splits[mtl_idx]; - cur_split.m_SkeletonLinkType = _max(link_type, cur_split.m_SkeletonLinkType); + SSplit&cur_split = m_Splits[mtl_idx]; + cur_split.m_SkeletonLinkType = _max(link_type, cur_split.m_SkeletonLinkType); - cur_split.m_UsedBones.insert (cur_split.m_UsedBones.end(),tmp_bone_lst.begin(),tmp_bone_lst.end()); + cur_split.m_UsedBones.insert(cur_split.m_UsedBones.end(), tmp_bone_lst.begin(), tmp_bone_lst.end()); // append face - cur_split.add_face (v[0], v[1], v[2]); + cur_split.add_face(v[0], v[1], v[2]); - if (surf->m_Flags.is(CSurface::sf2Sided)) + if (surf->m_Flags.is(CSurface::sf2Sided)) { - v[0].norm.invert (); - v[1].norm.invert (); - v[2].norm.invert (); - cur_split.add_face (v[0], v[2], v[1]); + v[0].norm.invert(); + v[1].norm.invert(); + v[2].norm.invert(); + cur_split.add_face(v[0], v[2], v[1]); } } } @@ -707,45 +753,47 @@ bool CExportSkeleton::PrepareGeometry(u8 influence) #ifdef _EDITOR pb->Inc (); #endif - } + } #ifdef _EDITOR UI->SetStatus ("..Calculate TB"); #endif - Msg ("Split statistic:"); - for (int k=0; k<(int)m_Splits.size(); k++) - { - // check splits - if (bRes) - { - if (!m_Splits[k].valid()) - { - ELog.Msg (mtError,"Empty split found (Shader/Texture: %s/%s). Removed.",*m_Splits[k].m_Shader,*m_Splits[k].m_Texture); - m_Splits.erase (m_Splits.begin()+k); k--; - }else - { - SSplit& split = m_Splits[k]; - std::sort (split.m_UsedBones.begin(),split.m_UsedBones.end()); - U16It ne = std::unique(split.m_UsedBones.begin(),split.m_UsedBones.end()); - split.m_UsedBones.erase (ne,split.m_UsedBones.end()); - Msg (" - Split %d: [Bones: %d, Links: %d, Faces: %d, Verts: %d, BrPart: %d, Shader/Texture: '%s'/'%s']",k,split.m_UsedBones.size(),split.m_SkeletonLinkType,split.getTS(),split.getVS(),split.m_PartID,*m_Splits[k].m_Shader,*m_Splits[k].m_Texture); - } - } - } - // calculate TB - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); split_it++) + Msg("Split statistic:"); + for (int k = 0; k<(int)m_Splits.size(); k++) + { + // check splits + if (bRes) { - split_it->CalculateTB(); - + if (!m_Splits[k].valid()) + { + ELog.Msg(mtError, "Empty split found (Shader/Texture: %s/%s). Removed.", *m_Splits[k].m_Shader, *m_Splits[k].m_Texture); + m_Splits.erase(m_Splits.begin()+k); + k--; + } + else + { + SSplit&split = m_Splits[k]; + std::sort(split.m_UsedBones.begin(), split.m_UsedBones.end()); + U16It ne = std::unique(split.m_UsedBones.begin(), split.m_UsedBones.end()); + split.m_UsedBones.erase(ne, split.m_UsedBones.end()); + Msg(" - Split %d: [Bones: %d, Links: %d, Faces: %d, Verts: %d, BrPart: %d, Shader/Texture: '%s'/'%s']", k, split.m_UsedBones.size(), split.m_SkeletonLinkType, split.getTS(), split.getVS(), split.m_PartID, *m_Splits[k].m_Shader, *m_Splits[k].m_Texture); + } + } + } + // calculate TB + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); split_it++) + { + split_it->CalculateTB(); + #ifdef _EDITOR pb->Inc (); #endif - } + } #ifdef _EDITOR pb->Inc (); #endif - // compute bounding - ComputeBounding (); + // compute bounding + ComputeBounding(); #ifdef _EDITOR UI->ProgressEnd(pb); @@ -756,80 +804,83 @@ bool CExportSkeleton::PrepareGeometry(u8 influence) return bRes; } -bool CExportSkeleton::ExportAsSimple(IWriter& F) +bool CExportSkeleton::ExportAsSimple(IWriter &F) { - if (!PrepareGeometry(2)) return false; + if (!PrepareGeometry(2)) + return false; { // Saving geometry... - if ( m_Splits.size()==1 ) + if (m_Splits.size()==1) { // export as single mesh m_Splits[0].Save(F); return true; - } else - return false; + } + else + return false; } - } #define _string_lod -bool CExportSkeleton::ExportGeometry(IWriter& F, u8 infl) +bool CExportSkeleton::ExportGeometry(IWriter &F, u8 infl) { - if (!PrepareGeometry(infl)) return false; + if (!PrepareGeometry(infl)) + return false; #ifdef _EDITOR SPBItem* pb = UI->ProgressStart(3+m_Splits.size(),"..Export skeleton geometry"); pb->Inc ("Make Progressive..."); #endif - // fill per bone vertices - BoneVec& bones = m_Source->Bones(); - xr_vector bone_points; - bone_points.resize (m_Source->BoneCount()); - - for (SplitIt split_it=m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) - { - if (m_Source->m_objectFlags.is(CEditableObject::eoProgressive)) - split_it->MakeProgressive(); + // fill per bone vertices + BoneVec &bones = m_Source->Bones(); + xr_vector bone_points; + bone_points.resize(m_Source->BoneCount()); + + for (SplitIt split_it = m_Splits.begin(); split_it!=m_Splits.end(); ++split_it) + { + if (m_Source->m_objectFlags.is(CEditableObject::eoProgressive)) + split_it->MakeProgressive(); else - split_it->MakeStripify(); + split_it->MakeStripify(); - SkelVertVec& lst = split_it->getV_Verts(); - for (SkelVertIt sv_it=lst.begin(); sv_it!=lst.end(); sv_it++) + SkelVertVec &lst = split_it->getV_Verts(); + for (SkelVertIt sv_it = lst.begin(); sv_it!=lst.end(); sv_it++) { - bone_points [sv_it->bones[0].id].push_back (sv_it->offs); - bones [sv_it->bones[0].id]->_RITransform().transform_tiny(bone_points[sv_it->bones[0].id].back()); + bone_points[sv_it->bones[0].id].push_back(sv_it->offs); + bones[sv_it->bones[0].id]->_RITransform().transform_tiny(bone_points[sv_it->bones[0].id].back()); } #ifdef _EDITOR pb->Inc (); #endif - } + } - // create OGF + // create OGF // Header - ogf_header H; - H.format_version= xrOGF_FormatVersion; - H.type = m_Source->IsAnimated()?MT_SKELETON_ANIM:MT_SKELETON_RIGID; - H.shader_id = 0; - H.bb.min = m_Box.min; - H.bb.max = m_Box.max; - m_Box.getsphere (H.bs.c,H.bs.r); - F.w_chunk (OGF_HEADER,&H,sizeof(H)); + ogf_header H; + H.format_version = xrOGF_FormatVersion; + H.type = m_Source->IsAnimated() ? MT_SKELETON_ANIM : MT_SKELETON_RIGID; + H.shader_id = 0; + H.bb.min = m_Box.min; + H.bb.max = m_Box.max; + m_Box.getsphere(H.bs.c, H.bs.r); + F.w_chunk(OGF_HEADER, &H, sizeof(H)); // Desc - ogf_desc desc; + ogf_desc desc; m_Source->PrepareOGFDesc(desc); - F.open_chunk (OGF_S_DESC); - desc.Save (F); - F.close_chunk (); + F.open_chunk(OGF_S_DESC); + desc.Save(F); + F.close_chunk(); // OGF_CHILDREN - F.open_chunk (OGF_CHILDREN); - int chield=0; - for (split_it=m_Splits.begin(); split_it!=m_Splits.end(); split_it++){ - F.open_chunk(chield++); + F.open_chunk(OGF_CHILDREN); + int chield = 0; + for (split_it = m_Splits.begin(); split_it!=m_Splits.end(); split_it++) + { + F.open_chunk(chield++); split_it->Save(F); - F.close_chunk(); + F.close_chunk(); } F.close_chunk(); @@ -840,38 +891,39 @@ bool CExportSkeleton::ExportGeometry(IWriter& F, u8 infl) // BoneNames F.open_chunk(OGF_S_BONE_NAMES); F.w_u32(m_Source->BoneCount()); - int bone_idx=0; - for (BoneIt bone_it=m_Source->FirstBone(); bone_it!=m_Source->LastBone(); bone_it++,bone_idx++){ - F.w_stringZ ((*bone_it)->Name()); - F.w_stringZ ((*bone_it)->Parent()?(*bone_it)->ParentName().c_str():""); - Fobb obb; - ComputeOBB_WML (obb,bone_points[bone_idx]); - F.w (&obb,sizeof(Fobb)); + int bone_idx = 0; + for (BoneIt bone_it = m_Source->FirstBone(); bone_it!=m_Source->LastBone(); bone_it++,bone_idx++) + { + F.w_stringZ((*bone_it)->Name()); + F.w_stringZ((*bone_it)->Parent() ? (*bone_it)->ParentName().c_str() : ""); + Fobb obb; + ComputeOBB_WML(obb, bone_points[bone_idx]); + F.w(&obb, sizeof(Fobb)); } F.close_chunk(); bool bRes = true; - + F.open_chunk(OGF_S_IKDATA); - for (bone_it=m_Source->FirstBone(); bone_it!=m_Source->LastBone(); ++bone_it,++bone_idx) - if (!(*bone_it)->ExportOGF(F)) - bRes=false; + for (bone_it = m_Source->FirstBone(); bone_it!=m_Source->LastBone(); ++bone_it,++bone_idx) + if (!(*bone_it)->ExportOGF(F)) + bRes = false; F.close_chunk(); if (m_Source->GetClassScript().size()) - { - F.open_chunk (OGF_S_USERDATA); - F.w_stringZ (m_Source->GetClassScript()); - F.close_chunk (); + { + F.open_chunk(OGF_S_USERDATA); + F.w_stringZ(m_Source->GetClassScript()); + F.close_chunk(); } #ifdef _EDITOR pb->Inc (); #endif - if (m_Source->GetLODs() && xr_strlen(m_Source->GetLODs())>0 && bRes) + if (m_Source->GetLODs()&&xr_strlen(m_Source->GetLODs())>0&&bRes) { - F.open_chunk (OGF_S_LODS); + F.open_chunk(OGF_S_LODS); #ifndef _string_lod CEditableObject* lod_src = Lib.CreateEditObject( m_Source->GetLODs() ); if (0==lod_src) @@ -883,7 +935,7 @@ bool CExportSkeleton::ExportGeometry(IWriter& F, u8 infl) CExportSkeleton E(lod_src); #else - F.w_string ( m_Source->GetLODs() ); + F.w_string(m_Source->GetLODs()); #endif #ifndef _string_lod @@ -896,7 +948,7 @@ bool CExportSkeleton::ExportGeometry(IWriter& F, u8 infl) Lib.RemoveEditObject(lod_src); } #endif - F.close_chunk (); + F.close_chunk(); } #ifdef _EDITOR @@ -904,33 +956,38 @@ bool CExportSkeleton::ExportGeometry(IWriter& F, u8 infl) #endif return bRes; } + //---------------------------------------------------- -struct bm_item{ - CKeyQR* _keysQR; - CKeyQT8* _keysQT8; - CKeyQT16* _keysQT16; - Fvector* _keysT; +struct bm_item +{ + CKeyQR *_keysQR; + CKeyQT8 *_keysQT8; + CKeyQT16 *_keysQT16; + Fvector *_keysT; + void create(u32 len) { - _keysQR = xr_alloc(len); - _keysQT8 = xr_alloc(len); - _keysQT16 = xr_alloc(len); - _keysT = xr_alloc(len); + _keysQR = xr_alloc(len); + _keysQT8 = xr_alloc(len); + _keysQT16 = xr_alloc(len); + _keysT = xr_alloc(len); } + void destroy() { - xr_free (_keysQR); - xr_free (_keysQT8); - xr_free (_keysQT16); - xr_free (_keysT); + xr_free(_keysQR); + xr_free(_keysQT8); + xr_free(_keysQT16); + xr_free(_keysT); } }; -bool CExportSkeleton::ExportMotionKeys(IWriter& F) +bool CExportSkeleton::ExportMotionKeys(IWriter &F) { - if (!!m_Source->m_SMotionRefs.size()||(m_Source->SMotionCount()<1)){ - Msg("!..Object doesn't have own motion"); - return !!m_Source->m_SMotionRefs.size(); + if (!!m_Source->m_SMotionRefs.size()||(m_Source->SMotionCount()<1)) + { + Msg("!..Object doesn't have own motion"); + return !!m_Source->m_SMotionRefs.size(); } #ifdef _EDITOR @@ -938,229 +995,243 @@ bool CExportSkeleton::ExportMotionKeys(IWriter& F) pb->Inc (); #endif // mem active motion - CSMotion* active_motion=m_Source->ResetSAnimation(); + CSMotion *active_motion = m_Source->ResetSAnimation(); // Motions - F.open_chunk (OGF_S_MOTIONS); - F.open_chunk (0); - F.w_u32 (m_Source->SMotionCount()); - F.close_chunk (); - int smot = 1; + F.open_chunk(OGF_S_MOTIONS); + F.open_chunk(0); + F.w_u32(m_Source->SMotionCount()); + F.close_chunk(); + int smot = 1; // use global transform - Fmatrix mGT,mTranslate,mRotate; - mRotate.setHPB (m_Source->a_vRotate.y, m_Source->a_vRotate.x, m_Source->a_vRotate.z); - mTranslate.translate (m_Source->a_vPosition); - mGT.mul (mTranslate,mRotate); + Fmatrix mGT, mTranslate, mRotate; + mRotate.setHPB(m_Source->a_vRotate.y, m_Source->a_vRotate.x, m_Source->a_vRotate.z); + mTranslate.translate(m_Source->a_vPosition); + mGT.mul(mTranslate, mRotate); - for (SMotionIt motion_it=m_Source->FirstSMotion(); motion_it!=m_Source->LastSMotion(); motion_it++, smot++) + for (SMotionIt motion_it = m_Source->FirstSMotion(); motion_it!=m_Source->LastSMotion(); motion_it++,smot++) { - CSMotion* cur_motion = *motion_it; - - if( cur_motion->m_Flags.test(esmRootMover) && !m_Source->AnimateRootObject(cur_motion) ) + CSMotion *cur_motion = *motion_it; + + if (cur_motion->m_Flags.test(esmRootMover)&&!m_Source->AnimateRootObject(cur_motion)) { - Msg("! %s has moveXform flag - but skeleton root has more than one child or has mesh! add special root bone please!", cur_motion->Name() ); - return false; + Msg("! %s has moveXform flag - but skeleton root has more than one child or has mesh! add special root bone please!", cur_motion->Name()); + return false; } -// if (motion->m_Flags.is(esmStopAtEnd)) Msg("%s - %d",motion->Name(),motion->m_Flags.is(esmStopAtEnd)); + // if (motion->m_Flags.is(esmStopAtEnd)) Msg("%s - %d",motion->Name(),motion->m_Flags.is(esmStopAtEnd)); - F.open_chunk (smot); - F.w_stringZ (cur_motion->Name()); - F.w_u32 (cur_motion->Length()); + F.open_chunk(smot); + F.w_stringZ(cur_motion->Name()); + F.w_u32(cur_motion->Length()); - u32 dwLen = cur_motion->Length(); - BoneVec& b_lst = m_Source->Bones(); + u32 dwLen = cur_motion->Length(); + BoneVec &b_lst = m_Source->Bones(); - bm_item* items = xr_alloc(b_lst.size()); - for (u32 itm_idx=0; itm_idx(b_lst.size()); + for (u32 itm_idx = 0; itm_idxFrameStart(); frame<=cur_motion->FrameEnd(); ++frame) + for (int frame = cur_motion->FrameStart(); frame<=cur_motion->FrameEnd(); ++frame) { + float t = (float)frame/cur_motion->FPS(); + int bone_id = 0; - - float t = (float)frame/cur_motion->FPS(); - int bone_id = 0; - - for(BoneIt b_it=b_lst.begin(); b_it!=b_lst.end(); ++b_it, ++bone_id) + for (BoneIt b_it = b_lst.begin(); b_it!=b_lst.end(); ++b_it,++bone_id) { - Fvector T,R; - if(cur_motion->BoneMotions().size()>bone_id) - cur_motion->_Evaluate (bone_id,t,T,R); - else - { - T = (*b_it)->_Offset(); - R = (*b_it)->_Rotate(); - } - (*b_it)->_Update (T,R); - - if(bone_id==0 && frame==(cur_motion->FrameEnd()) ) + Fvector T, R; + if (cur_motion->BoneMotions().size()>bone_id) + cur_motion->_Evaluate(bone_id, t, T, R); + else + { + T = (*b_it)->_Offset(); + R = (*b_it)->_Rotate(); + } + (*b_it)->_Update(T, R); + + if (bone_id==0&&frame==(cur_motion->FrameEnd())) { - Msg("motion [%s] end frame %f,%f,%f",cur_motion->Name(),T.x,T.y,T.z); + Msg("motion [%s] end frame %f,%f,%f", cur_motion->Name(), T.x, T.y, T.z); } } - m_Source->CalculateAnimation( cur_motion ); - if(cur_motion->m_Flags.test(esmRootMover)) + m_Source->CalculateAnimation(cur_motion); + if (cur_motion->m_Flags.test(esmRootMover)) { - if( frame == cur_motion->FrameStart() ) - m_Source->GetAnchorForRootObjectAnimation( ro_anchor ); - - m_Source->CalculateRootObjectAnimation( ro_anchor ); + if (frame==cur_motion->FrameStart()) + m_Source->GetAnchorForRootObjectAnimation(ro_anchor); + + m_Source->CalculateRootObjectAnimation(ro_anchor); } - bone_id = 0; - for(b_it=b_lst.begin(); b_it!=b_lst.end(); b_it++, bone_id++) + bone_id = 0; + for (b_it = b_lst.begin(); b_it!=b_lst.end(); b_it++,bone_id++) { - CBone* B = *b_it; - Fmatrix mat = B->_MTransform(); - if (B->IsRoot()) mat.mulA_43(mGT); - Fquaternion q; - q.set (mat); - CKeyQR& Kr = items[bone_id]._keysQR[frame-cur_motion->FrameStart()]; - Fvector&Kt = items[bone_id]._keysT [frame-cur_motion->FrameStart()]; + CBone *B = *b_it; + Fmatrix mat = B->_MTransform(); + if (B->IsRoot()) + mat.mulA_43(mGT); + Fquaternion q; + q.set(mat); + CKeyQR &Kr = items[bone_id]._keysQR[frame-cur_motion->FrameStart()]; + Fvector &Kt = items[bone_id]._keysT[frame-cur_motion->FrameStart()]; // Quantize quaternion - int _x = int(q.x*KEY_Quant); clamp(_x,-32767,32767); Kr.x = (s16)_x; - int _y = int(q.y*KEY_Quant); clamp(_y,-32767,32767); Kr.y = (s16)_y; - int _z = int(q.z*KEY_Quant); clamp(_z,-32767,32767); Kr.z = (s16)_z; - int _w = int(q.w*KEY_Quant); clamp(_w,-32767,32767); Kr.w = (s16)_w; - Kt.set (mat.c);//B->_Offset()); + int _x = int(q.x*KEY_Quant); + clamp(_x, -32767, 32767); + Kr.x = (s16)_x; + int _y = int(q.y*KEY_Quant); + clamp(_y, -32767, 32767); + Kr.y = (s16)_y; + int _z = int(q.z*KEY_Quant); + clamp(_z, -32767, 32767); + Kr.z = (s16)_z; + int _w = int(q.w*KEY_Quant); + clamp(_w, -32767, 32767); + Kr.w = (s16)_w; + Kt.set(mat.c);//B->_Offset()); } } // free temp storage - for (itm_idx=0; itm_idx1.5f) + if (g_force16BitTransformQuant||St.magnitude()>1.5f) { - bTransform16Bit = true; + bTransform16Bit = true; Msg("animation [%s] is 16bit-transform (%f)m", cur_motion->Name(), St.magnitude()); } - - for (t_idx=0; t_idxInc (); #endif } - F.close_chunk (); + F.close_chunk(); #ifdef _EDITOR UI->ProgressEnd (pb); #endif // restore active motion - m_Source->SetActiveSMotion (active_motion); - return true; + m_Source->SetActiveSMotion(active_motion); + return true; } -bool CExportSkeleton::ExportMotionDefs(IWriter& F) +bool CExportSkeleton::ExportMotionDefs(IWriter &F) { - if (!m_Source->IsAnimated()){ - ELog.Msg(mtError,"Object doesn't have any motion or motion refs."); - return false; + if (!m_Source->IsAnimated()) + { + ELog.Msg(mtError, "Object doesn't have any motion or motion refs."); + return false; } - bool bRes=true; + bool bRes = true; #ifdef _EDITOR SPBItem* pb = UI->ProgressStart(3,"..Export skeleton motions defs"); @@ -1169,84 +1240,88 @@ bool CExportSkeleton::ExportMotionDefs(IWriter& F) if (m_Source->m_SMotionRefs.size()) { - F.open_chunk (OGF_S_MOTION_REFS2); - F.w_u32 (m_Source->m_SMotionRefs.size()); - for(u32 i=0; im_SMotionRefs.size(); ++i) - F.w_stringZ (m_Source->m_SMotionRefs[i].c_str()); + F.open_chunk(OGF_S_MOTION_REFS2); + F.w_u32(m_Source->m_SMotionRefs.size()); + for (u32 i = 0; im_SMotionRefs.size(); ++i) + F.w_stringZ(m_Source->m_SMotionRefs[i].c_str()); - F.close_chunk (); + F.close_chunk(); #ifdef _EDITOR pb->Inc (); #endif - }else{ + } + else + { // save smparams - F.open_chunk (OGF_S_SMPARAMS); - F.w_u16 (xrOGF_SMParamsVersion); + F.open_chunk(OGF_S_SMPARAMS); + F.w_u16(xrOGF_SMParamsVersion); // bone parts - BPVec& bp_lst = m_Source->BoneParts(); + BPVec &bp_lst = m_Source->BoneParts(); if (bp_lst.size()) - { + { if (m_Source->VerifyBoneParts()) - { + { F.w_u16((u16)bp_lst.size()); - for (BPIt bp_it=bp_lst.begin(); bp_it!=bp_lst.end(); ++bp_it) - { - string512 buff; - strcpy (buff, bp_it->alias.c_str()); - strlwr (buff); - F.w_stringZ (buff); - F.w_u16 ((u16)bp_it->bones.size()); - for (int i=0; ibones.size()); ++i) - { - F.w_stringZ (bp_it->bones[i].c_str()); - int idx = m_Source->FindBoneByNameIdx(bp_it->bones[i].c_str()); - VERIFY(idx>=0); - F.w_u32 (idx); + for (BPIt bp_it = bp_lst.begin(); bp_it!=bp_lst.end(); ++bp_it) + { + string512 buff; + strcpy(buff, bp_it->alias.c_str()); + strlwr(buff); + F.w_stringZ(buff); + F.w_u16((u16)bp_it->bones.size()); + for (int i = 0; ibones.size()); ++i) + { + F.w_stringZ(bp_it->bones[i].c_str()); + int idx = m_Source->FindBoneByNameIdx(bp_it->bones[i].c_str()); + VERIFY(idx>=0); + F.w_u32(idx); } } - }else - { - ELog.Msg(mtError,"Invalid bone parts (missing or duplicate bones)."); - bRes = false; } - }else - { + else + { + ELog.Msg(mtError, "Invalid bone parts (missing or duplicate bones)."); + bRes = false; + } + } + else + { F.w_u16(1); F.w_stringZ("default"); F.w_u16((u16)m_Source->BoneCount()); - for (int i=0; iBoneCount(); i++) - F.w_u32(i); + for (int i = 0; iBoneCount(); i++) + F.w_u32(i); } #ifdef _EDITOR pb->Inc (); #endif // motion defs - SMotionVec& sm_lst = m_Source->SMotions(); + SMotionVec &sm_lst = m_Source->SMotions(); F.w_u16((u16)sm_lst.size()); - for (SMotionIt motion_it=m_Source->FirstSMotion(); motion_it!=m_Source->LastSMotion(); ++motion_it) - { - CSMotion* motion = *motion_it; + for (SMotionIt motion_it = m_Source->FirstSMotion(); motion_it!=m_Source->LastSMotion(); ++motion_it) + { + CSMotion *motion = *motion_it; // verify if (!motion->m_Flags.is(esmFX)) - { + { if (!((motion->m_BoneOrPart==BI_NONE)||(motion->m_BoneOrPart<(int)bp_lst.size()))) - { - ELog.Msg(mtError,"Invalid Bone Part of motion: '%s'.",motion->Name()); - bRes=false; + { + ELog.Msg(mtError, "Invalid Bone Part of motion: '%s'.", motion->Name()); + bRes = false; continue; } } if (bRes) - { + { // export - F.w_stringZ (motion->Name()); - F.w_u32 (motion->m_Flags.get()); - F.w_u16 (motion->m_BoneOrPart); - F.w_u16 (u16(motion_it-sm_lst.begin())); - F.w_float (motion->fSpeed); - F.w_float (motion->fPower); - F.w_float (motion->fAccrue); - F.w_float (motion->fFalloff); + F.w_stringZ(motion->Name()); + F.w_u32(motion->m_Flags.get()); + F.w_u16(motion->m_BoneOrPart); + F.w_u16(u16(motion_it-sm_lst.begin())); + F.w_float(motion->fSpeed); + F.w_float(motion->fPower); + F.w_float(motion->fAccrue); + F.w_float(motion->fFalloff); #ifdef _EDITOR u32 sz = motion->marks.size(); @@ -1256,45 +1331,50 @@ bool CExportSkeleton::ExportMotionDefs(IWriter& F) motion->marks[i].Save(&F); } #else - F.w_u32 (0); + F.w_u32(0); #endif } } #ifdef _EDITOR pb->Inc (); #endif - F.close_chunk(); + F.close_chunk(); } - + #ifdef _EDITOR UI->ProgressEnd(pb); #endif return bRes; } -bool CExportSkeleton::ExportMotions(IWriter& F) +bool CExportSkeleton::ExportMotions(IWriter &F) { - if (!ExportMotionKeys(F)) return false; - if (!ExportMotionDefs(F)) return false; + if (!ExportMotionKeys(F)) + return false; + if (!ExportMotionDefs(F)) + return false; return true; } + //---------------------------------------------------- -bool CExportSkeleton::Export(IWriter& F, u8 infl) +bool CExportSkeleton::Export(IWriter &F, u8 infl) { - if (!ExportGeometry(F,infl)) return false; - if (m_Source->IsAnimated()&&!ExportMotions(F)) return false; + if (!ExportGeometry(F, infl)) + return false; + if (m_Source->IsAnimated()&&!ExportMotions(F)) + return false; return true; }; -//---------------------------------------------------- +//---------------------------------------------------- #if defined _EDITOR || defined _MAYA_EXPORT bool CBone::ExportOGF(IWriter& F) { - // check valid +// check valid if (!shape.Valid()){ ELog.Msg(mtError,"Bone '%s' has invalid shape.",*Name()); return false; @@ -1329,4 +1409,5 @@ bool CBone::ExportOGF(IWriter& F) return true; } -#endif \ No newline at end of file +#endif + diff --git a/src/editors/ECore/Editor/ExportSkeleton.h b/src/editors/ECore/Editor/ExportSkeleton.h index d4e4a8978c5..c8d601d666e 100644 --- a/src/editors/ECore/Editor/ExportSkeleton.h +++ b/src/editors/ECore/Editor/ExportSkeleton.h @@ -5,199 +5,209 @@ #include "EditMesh.h" //--------------------------------------------------------------------------- -const int clpSMX = 28, clpSMY=16, clpSMZ=28; +const int clpSMX = 28, clpSMY = 16, clpSMZ = 28; //--------------------------------------------------------------------------- // refs class CEditableObject; class CSurface; class CInifile; extern ECORE_API BOOL g_force16BitTransformQuant; -extern ECORE_API float g_EpsSkelPositionDelta; - -struct ECORE_API SSkelVert: public st_SVert{ - Fvector tang; - Fvector binorm; - SSkelVert(){ - uv.set (0.f,0.f); - offs.set (0,0,0); - norm.set (0,1,0); - tang.set (1,0,0); - binorm.set (0,0,1); - } - void set(const Fvector& _o, const Fvector& _n, const Fvector2& _uv, u8 _w_cnt, const st_SVert::bone* b) - { - offs.set (_o); - norm.set (_n); - uv.set (_uv); - VERIFY (_w_cnt>0 && _w_cnt<=4); - bones.resize(_w_cnt); +extern ECORE_API +float g_EpsSkelPositionDelta; - for (u8 k=0; k<_w_cnt; k++) - { - bones[k]=b[k]; - } - sort_by_bone(); // need to similar - } - BOOL similar_pos(SSkelVert& V) +struct ECORE_API SSkelVert: + +public +st_SVert +{ + Fvector tang; + Fvector binorm; + SSkelVert(){ + uv.set (0.f,0.f); + offs.set (0,0,0); + norm.set (0,1,0); + tang.set (1,0,0); + binorm.set (0,0,1); +} +void set(const Fvector& _o, const Fvector& _n, const Fvector2& _uv, u8 _w_cnt, const st_SVert::bone* b) +{ + offs.set (_o); + norm.set (_n); + uv.set (_uv); + VERIFY (_w_cnt>0 && _w_cnt<=4); + bones.resize(_w_cnt); + + for (u8 k=0; k<_w_cnt; k++) { - return offs.similar(V.offs,g_EpsSkelPositionDelta); - } - BOOL similar(SSkelVert& V) + bones[k]=b[k]; +} +sort_by_bone(); // need to similar +} +BOOL similar_pos(SSkelVert& V) +{ + return offs.similar(V.offs,g_EpsSkelPositionDelta); +} +BOOL similar(SSkelVert& V) +{ + if (bones.size()!=V.bones.size()) return FALSE; + for (u8 k=0; k<(u8)bones.size(); k++) { - if (bones.size()!=V.bones.size()) return FALSE; - for (u8 k=0; k<(u8)bones.size(); k++) - { - if (!bones[k].similar(V.bones[k])) - return FALSE; - } - if (!uv.similar (V.uv,EPS_S)) - return FALSE; + if (!bones[k].similar(V.bones[k])) + return FALSE; +} +if (!uv.similar (V.uv,EPS_S)) +return FALSE; - if (!offs.similar(V.offs,g_EpsSkelPositionDelta)) - return FALSE; +if (!offs.similar(V.offs,g_EpsSkelPositionDelta)) +return FALSE; - if (!norm.similar(V.norm,g_EpsSkelPositionDelta)) - return FALSE; +if (!norm.similar(V.norm,g_EpsSkelPositionDelta)) +return FALSE; - return TRUE; - } +return TRUE; +} }; struct ECORE_API SSkelFace{ - WORD v[3]; + WORD v[3]; }; -DEFINE_VECTOR(SSkelVert,SkelVertVec,SkelVertIt); -DEFINE_VECTOR(SSkelFace,SkelFaceVec,SkelFaceIt); +DEFINE_VECTOR(SSkelVert, SkelVertVec, SkelVertIt); +DEFINE_VECTOR(SSkelFace, SkelFaceVec, SkelFaceIt); class ECORE_API CSkeletonCollectorPacked { -protected: - SkelVertVec m_Verts; - SkelFaceVec m_Faces; - - Fvector m_VMmin, m_VMscale; - U32Vec m_VM[clpSMX+1][clpSMY+1][clpSMZ+1]; - Fvector m_VMeps; - - u16 VPack(SSkelVert& V); -public: - u32 invalid_faces; -public: - CSkeletonCollectorPacked (const Fbox &bb, int apx_vertices=5000, int apx_faces=5000); - bool check (SSkelFace& F){ - if ((F.v[0]==F.v[1]) || (F.v[0]==F.v[2]) || (F.v[1]==F.v[2])) return false; - for (SkelFaceIt f_it=m_Faces.begin(); f_it!=m_Faces.end(); f_it++){ + protected: + SkelVertVec m_Verts; + SkelFaceVec m_Faces; + + Fvector m_VMmin, m_VMscale; + U32Vec m_VM[clpSMX+1][clpSMY+1][clpSMZ+1]; + Fvector m_VMeps; + + u16 VPack(SSkelVert&V); + public: + u32 invalid_faces; + public: + CSkeletonCollectorPacked(const Fbox&bb, int apx_vertices = 5000, int apx_faces = 5000); + bool check(SSkelFace&F){ + if ((F.v[0]==F.v[1])||(F.v[0]==F.v[2])||(F.v[1]==F.v[2]))return false; + for (SkelFaceIt f_it = m_Faces.begin(); f_it!=m_Faces.end(); f_it++){ // Test for 6 variations - if ((f_it->v[0]==F.v[0]) && (f_it->v[1]==F.v[1]) && (f_it->v[2]==F.v[2])) return false; - if ((f_it->v[0]==F.v[0]) && (f_it->v[2]==F.v[1]) && (f_it->v[1]==F.v[2])) return false; - if ((f_it->v[2]==F.v[0]) && (f_it->v[0]==F.v[1]) && (f_it->v[1]==F.v[2])) return false; - if ((f_it->v[2]==F.v[0]) && (f_it->v[1]==F.v[1]) && (f_it->v[0]==F.v[2])) return false; - if ((f_it->v[1]==F.v[0]) && (f_it->v[0]==F.v[1]) && (f_it->v[2]==F.v[2])) return false; - if ((f_it->v[1]==F.v[0]) && (f_it->v[2]==F.v[1]) && (f_it->v[0]==F.v[2])) return false; + if ((f_it->v[0]==F.v[0])&&(f_it->v[1]==F.v[1])&&(f_it->v[2]==F.v[2]))return false; + if ((f_it->v[0]==F.v[0])&&(f_it->v[2]==F.v[1])&&(f_it->v[1]==F.v[2]))return false; + if ((f_it->v[2]==F.v[0])&&(f_it->v[0]==F.v[1])&&(f_it->v[1]==F.v[2]))return false; + if ((f_it->v[2]==F.v[0])&&(f_it->v[1]==F.v[1])&&(f_it->v[0]==F.v[2]))return false; + if ((f_it->v[1]==F.v[0])&&(f_it->v[0]==F.v[1])&&(f_it->v[2]==F.v[2]))return false; + if ((f_it->v[1]==F.v[0])&&(f_it->v[2]==F.v[1])&&(f_it->v[0]==F.v[2]))return false; } return true; } - bool add_face (SSkelVert& v0, SSkelVert& v1, SSkelVert& v2) + bool add_face(SSkelVert&v0, SSkelVert&v1, SSkelVert&v2) { - if (v0.offs.similar(v1.offs,EPS) || v0.offs.similar(v2.offs,EPS) || v1.offs.similar(v2.offs,EPS)){ - ELog.Msg(mtError,"Degenerate face found. Removed."); + if (v0.offs.similar(v1.offs, EPS)||v0.offs.similar(v2.offs, EPS)||v1.offs.similar(v2.offs, EPS)){ + ELog.Msg(mtError, "Degenerate face found. Removed."); invalid_faces++; return false; } SSkelFace F; - F.v[0] = VPack(v0); - F.v[1] = VPack(v1); - F.v[2] = VPack(v2); - if (check(F)){ - m_Faces.push_back (F); - return true; - }else{ - ELog.Msg(mtError,"Duplicate face found. Removed."); + F.v[0] = VPack(v0); + F.v[1] = VPack(v1); + F.v[2] = VPack(v2); + if (check(F)){ + m_Faces.push_back(F); + return true; + }else{ + ELog.Msg(mtError, "Duplicate face found. Removed."); invalid_faces++; return false; } } - SkelVertVec& getV_Verts() {return m_Verts;} - SkelFaceVec& getV_Faces() {return m_Faces;} - SSkelVert* getVert() { return &m_Verts[0];/*.begin();*/ } - int getVS() { return m_Verts.size(); } -// SSkelFace& getFace(int id) { return VERIFY(id m_SWR;// The records of the collapses. - u32 m_SkeletonLinkType; - public: - SSplit (CSurface* surf, const Fbox& bb, u16 part); + ArbitraryListm_SWR;// The records of the collapses. + u32 m_SkeletonLinkType; + public: + SSplit(CSurface*surf, const Fbox&bb, u16 part); - bool valid() + bool valid() { - if (m_Verts.empty()) return false; - if (m_Faces.empty()) return false; + if (m_Verts.empty())return false; + if (m_Faces.empty())return false; return true; } - void MakeProgressive (); - void MakeStripify (); - void CalculateTB (); - void OptimizeTextureCoordinates (); + void MakeProgressive(); + void MakeStripify(); + void CalculateTB(); + void OptimizeTextureCoordinates(); - void Save (IWriter& F); + void Save(IWriter&F); - void ComputeBounding () + void ComputeBounding() { // calculate BBox - m_Box.invalidate (); - for (SkelVertIt v_it=m_Verts.begin(); v_it!=m_Verts.end(); v_it++){ - SSkelVert& pV = *v_it; + m_Box.invalidate(); + for (SkelVertIt v_it = m_Verts.begin(); v_it!=m_Verts.end(); v_it++){ + SSkelVert&pV = *v_it; m_Box.modify(pV.offs); } } }; - DEFINE_VECTOR (SSplit,SplitVec,SplitIt); - SplitVec m_Splits; - Fbox m_Box; -//---------------------------------------------------- - int FindSplit (shared_str shader, shared_str texture, u16 part_id); - void ComputeBounding () + DEFINE_VECTOR(SSplit, SplitVec, SplitIt); + SplitVec m_Splits; + Fbox m_Box; + //---------------------------------------------------- + int FindSplit(shared_str shader, shared_str texture, u16 part_id); + void ComputeBounding() { m_Box.invalidate(); - for (SplitIt it=m_Splits.begin(); it!=m_Splits.end(); it++){ - it->ComputeBounding (); - m_Box.merge (it->m_Box); + for (SplitIt it = m_Splits.begin(); it!=m_Splits.end(); it++){ + it->ComputeBounding(); + m_Box.merge(it->m_Box); } } -public: - virtual bool Export (IWriter& F, u8 infl)=0; + public: + virtual bool Export(IWriter&F, u8 infl) = 0; }; -class ECORE_API CExportSkeleton: public CExportSkeletonCustom{ - CEditableObject* m_Source; - bool PrepareGeometry (u8 influence); -public: - CExportSkeleton (CEditableObject* object); - virtual bool Export (IWriter& F, u8 infl); - virtual bool ExportGeometry (IWriter& F, u8 infl); - virtual bool ExportMotions (IWriter& F); +class ECORE_API CExportSkeleton: - virtual bool ExportMotionKeys (IWriter& F); - virtual bool ExportMotionDefs (IWriter& F); - bool ExportAsSimple (IWriter& F); +public +CExportSkeletonCustom +{ + CEditableObject* m_Source; + bool PrepareGeometry (u8 influence); + public: + CExportSkeleton (CEditableObject* object); + virtual bool Export (IWriter& F, u8 infl); + virtual bool ExportGeometry (IWriter& F, u8 infl); + virtual bool ExportMotions (IWriter& F); + + virtual bool ExportMotionKeys (IWriter& F); + virtual bool ExportMotionDefs (IWriter& F); + bool ExportAsSimple (IWriter& F); }; -void ECORE_API ComputeOBB_RAPID (Fobb &B, FvectorVec& V, u32 t_cnt); -void ECORE_API ComputeOBB_WML (Fobb &B, FvectorVec& V); +void ECORE_API ComputeOBB_RAPID(Fobb &B, FvectorVec &V, u32 t_cnt); +void ECORE_API ComputeOBB_WML(Fobb&B, FvectorVec&V); #endif + diff --git a/src/editors/ECore/Editor/ExportSkeletonCalculateTB.cpp b/src/editors/ECore/Editor/ExportSkeletonCalculateTB.cpp index 5971093b68b..42815bc4b12 100644 --- a/src/editors/ECore/Editor/ExportSkeletonCalculateTB.cpp +++ b/src/editors/ECore/Editor/ExportSkeletonCalculateTB.cpp @@ -4,8 +4,8 @@ #ifndef _EDITOR #include "xrEngine/defines.h" #include "xrCore/xrCore.h" -#include "Layers/xrRender/hwcaps.h" -#include "Layers/xrRender/hw.h" +#include "Layers/xrRender/HWCaps.h" +#include "Layers/xrRender/HW.h" #include "xrEngine/pure.h" class CGameFont; #include "Include/xrRender/drawutils.h" @@ -171,10 +171,10 @@ void CExportSkeleton::SSplit::CalculateTB() ///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// -#include "common/nvMender2003/nvmeshmender.h" -#include "common/NvMender2003/nvMeshMender.h" -#include "common/NvMender2003/mender_input_output.h" -#include "common/NvMender2003/remove_isolated_verts.h" +#include "Common/NvMender2003/NVMeshMender.h" +#include "Common/NvMender2003/NVMeshMender.h" +#include "Common/NvMender2003/mender_input_output.h" +#include "Common/NvMender2003/remove_isolated_verts.h" void CExportSkeleton::SSplit::OptimizeTextureCoordinates() { diff --git a/src/editors/ECore/Editor/GeometryCollector.cpp b/src/editors/ECore/Editor/GeometryCollector.cpp index 515f8841c64..c0e188741c2 100644 --- a/src/editors/ECore/Editor/GeometryCollector.cpp +++ b/src/editors/ECore/Editor/GeometryCollector.cpp @@ -11,49 +11,50 @@ //------------------------------------------------------------------------------ VCPacked::VCPacked(const Fbox &bb, float _eps, u32 _sx, u32 _sy, u32 _sz, int apx_vertices) { - eps = _eps; - sx = _max(_sx,1); - sy = _max(_sy,1); - sz = _max(_sz,1); - // prepare hash table - VM.resize (sx*sy*sz); - + eps = _eps; + sx = _max(_sx, 1); + sy = _max(_sy, 1); + sz = _max(_sz, 1); + // prepare hash table + VM.resize(sx*sy*sz); + // Params - VMscale.set (bb.max.x-bb.min.x, bb.max.y-bb.min.y, bb.max.z-bb.min.z); - VMmin.set (bb.min); - VMeps.set (VMscale.x/(sx-1)/2,VMscale.y/(sy-1)/2,VMscale.z/(sz-1)/2); - VMeps.x = (VMeps.xreserve (_average); + int _size = VM.size(); + int _average = (apx_vertices/_size)/2; + for (GCHashIt it = VM.begin(); it!=VM.end(); it++) + it->reserve(_average); } -u32 VCPacked::add_vert(const Fvector& V) +u32 VCPacked::add_vert(const Fvector &V) { u32 P = 0xffffffff; - u32 clpX=sx-1, clpY=sy-1, clpZ=sz-1; + u32 clpX = sx-1, clpY = sy-1, clpZ = sz-1; - u32 ix,iy,iz; + u32 ix, iy, iz; ix = iFloor(float(V.x-VMmin.x)/VMscale.x*clpX); iy = iFloor(float(V.y-VMmin.y)/VMscale.y*clpY); iz = iFloor(float(V.z-VMmin.z)/VMscale.z*clpZ); - clamp(ix,(u32)0,clpX); - clamp(iy,(u32)0,clpY); - clamp(iz,(u32)0,clpZ); + clamp(ix, (u32)0, clpX); + clamp(iy, (u32)0, clpY); + clamp(iz, (u32)0, clpZ); { - U32Vec& vl = get_element(ix,iy,iz); - for(U32It it=vl.begin();it!=vl.end(); it++) - if( verts[*it].similar(V,eps) ) { + U32Vec &vl = get_element(ix, iy, iz); + for (U32It it = vl.begin(); it!=vl.end(); it++) + if (verts[*it].similar(V, eps)) + { P = *it; verts[*it].refs++; break; @@ -64,80 +65,92 @@ u32 VCPacked::add_vert(const Fvector& V) P = verts.size(); verts.push_back(GCVertex(V)); - get_element(ix,iy,iz).push_back(P); + get_element(ix, iy, iz).push_back(P); - u32 ixE,iyE,izE; + u32 ixE, iyE, izE; ixE = iFloor(float(V.x+VMeps.x-VMmin.x)/VMscale.x*clpX); iyE = iFloor(float(V.y+VMeps.y-VMmin.y)/VMscale.y*clpY); izE = iFloor(float(V.z+VMeps.z-VMmin.z)/VMscale.z*clpZ); // R_ASSERT(ixE<=clpMX && iyE<=clpMY && izE<=clpMZ); - clamp(ixE,(u32)0,clpX); clamp(iyE,(u32)0,clpY); clamp(izE,(u32)0,clpZ); - - if (ixE!=ix) get_element(ixE,iy,iz).push_back (P); - if (iyE!=iy) get_element(ix,iyE,iz).push_back (P); - if (izE!=iz) get_element(ix,iy,izE).push_back (P); - if ((ixE!=ix)&&(iyE!=iy)) get_element(ixE,iyE,iz).push_back (P); - if ((ixE!=ix)&&(izE!=iz)) get_element(ixE,iy,izE).push_back (P); - if ((iyE!=iy)&&(izE!=iz)) get_element(ix,iyE,izE).push_back (P); - if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) get_element(ixE,iyE,izE).push_back (P); + clamp(ixE, (u32)0, clpX); + clamp(iyE, (u32)0, clpY); + clamp(izE, (u32)0, clpZ); + + if (ixE!=ix) + get_element(ixE, iy, iz).push_back(P); + if (iyE!=iy) + get_element(ix, iyE, iz).push_back(P); + if (izE!=iz) + get_element(ix, iy, izE).push_back(P); + if ((ixE!=ix)&&(iyE!=iy)) + get_element(ixE, iyE, iz).push_back(P); + if ((ixE!=ix)&&(izE!=iz)) + get_element(ixE, iy, izE).push_back(P); + if ((iyE!=iy)&&(izE!=iz)) + get_element(ix, iyE, izE).push_back(P); + if ((ixE!=ix)&&(iyE!=iy)&&(izE!=iz)) + get_element(ixE, iyE, izE).push_back(P); } return P; } -void VCPacked::clear() +void VCPacked::clear() { - verts.clear_and_free (); - for (GCHashIt it=VM.begin(); it!=VM.end(); it++) - it->clear_and_free (); + verts.clear_and_free(); + for (GCHashIt it = VM.begin(); it!=VM.end(); it++) + it->clear_and_free(); } //------------------------------------------------------------------------------ // GCPacked //------------------------------------------------------------------------------ -void GCPacked::add_face(const Fvector& v0, const Fvector& v1, const Fvector& v2, u32 dummy) +void GCPacked::add_face(const Fvector &v0, const Fvector &v1, const Fvector &v2, u32 dummy) { - GCFace T; - T.verts [0] = add_vert(v0); - T.verts [1] = add_vert(v1); - T.verts [2] = add_vert(v2); - T.dummy = dummy; - faces.push_back (T); - validate (T); + GCFace T; + T.verts[0] = add_vert(v0); + T.verts[1] = add_vert(v1); + T.verts[2] = add_vert(v2); + T.dummy = dummy; + faces.push_back(T); + validate(T); } -void GCPacked::clear() +void GCPacked::clear() { - GCPacked::clear (); - faces.clear_and_free (); + GCPacked::clear(); + faces.clear_and_free(); } -void GCPacked::calc_adjacency (U32Vec& dest) +void GCPacked::calc_adjacency(U32Vec &dest) { - dest.assign (faces.size()*3,0xffffffff); + dest.assign(faces.size()*3, 0xffffffff); // Dumb algorithm O(N^2) :) - for (u32 f=0; ff2) std::swap(f1,f2); + u32 f1 = faces[f].verts[(f_e+0)%3]; + u32 f2 = faces[f].verts[(f_e+1)%3]; + if (f1>f2) + std::swap(f1, f2); - for (u32 t_e=0; t_e<3; t_e++) + for (u32 t_e = 0; t_e<3; t_e++) { - u32 t1 = faces[t].verts[(t_e+0)%3]; - u32 t2 = faces[t].verts[(t_e+1)%3]; - if (t1>t2) std::swap(t1,t2); + u32 t1 = faces[t].verts[(t_e+0)%3]; + u32 t2 = faces[t].verts[(t_e+1)%3]; + if (t1>t2) + std::swap(t1, t2); - if (f1==t1 && f2==t2) + if (f1==t1&&f2==t2) { // f.edge[f_e] linked to t.edge[t_e] - dest[f*3+f_e] = t; + dest[f*3+f_e] = t; break; } } diff --git a/src/editors/ECore/Editor/GeometryCollector.h b/src/editors/ECore/Editor/GeometryCollector.h index b29e3f21ecc..7fd2bfdce36 100644 --- a/src/editors/ECore/Editor/GeometryCollector.h +++ b/src/editors/ECore/Editor/GeometryCollector.h @@ -3,69 +3,73 @@ //--------------------------------------------------------------------------- struct ECORE_API GCVertex{ - Fvector pos; - u32 refs; - GCVertex (const Fvector& p){pos=p;refs=1;} - bool similar (const GCVertex& v, float eps=EPS){return pos.similar(v.pos);} + Fvector pos; + u32 refs; + GCVertex(const Fvector&p){pos = p;refs = 1;} + bool similar(const GCVertex&v, float eps = EPS){return pos.similar(v.pos);} }; struct ECORE_API GCFace{ - u32 verts[3]; - bool valid; - u32 dummy; + u32 verts[3]; + bool valid; + u32 dummy; }; class ECORE_API VCPacked { -protected: - DEFINE_VECTOR(U32Vec,GCHash,GCHashIt); + protected: + DEFINE_VECTOR(U32Vec, GCHash, GCHashIt); - xr_vector verts; + xr_vectorverts; - GCHash VM; - Fvector VMmin, VMscale; - Fvector VMeps; - float eps; - u32 sx,sy,sz; + GCHash VM; + Fvector VMmin, VMscale; + Fvector VMeps; + float eps; + u32 sx,sy,sz; - IC U32Vec& get_element (u32 ix, u32 iy, u32 iz) {VERIFY((ix&Vertices () { return verts; } + GCVertex*getV(){return &*verts.begin();} + size_t getVS(){return verts.size();} + xr_vector&Vertices(){return verts;} - void getHASH_size(u32& x, u32& y, u32& z){x=sx;y=sy;z=sz;} - U32Vec& getHASH_elem(u32 ix, u32 iy, u32 iz){return get_element(ix,iy,iz);} + void getHASH_size(u32&x, u32&y, u32&z){x = sx;y = sy;z = sz;} + U32Vec&getHASH_elem(u32 ix, u32 iy, u32 iz){return get_element(ix, iy, iz);} }; -class ECORE_API GCPacked: public VCPacked +class ECORE_API GCPacked: + +public +VCPacked { - xr_vector faces; - void validate (GCFace& F) + xr_vector faces; + void validate (GCFace& F) { - if ((F.verts[0]==F.verts[1])||(F.verts[0]==F.verts[2])||(F.verts[1]==F.verts[2])) F.valid=false; - else F.valid=true; - } + if ((F.verts[0]==F.verts[1])||(F.verts[0]==F.verts[2])||(F.verts[1]==F.verts[2])) F.valid=false; + else F.valid=true; +} public: - GCPacked (const Fbox &bb, float eps=EPS, u32 clpMX=24, u32 clpMY=16, u32 clpMZ=24, int apx_vertices=5000, int apx_faces=5000): - VCPacked(bb,eps,clpMX,clpMY,clpMZ,apx_vertices){faces.reserve(apx_faces);} - virtual ~GCPacked () { clear(); } - virtual void clear (); +GCPacked (const Fbox &bb, float eps=EPS, u32 clpMX=24, u32 clpMY=16, u32 clpMZ=24, int apx_vertices=5000, int apx_faces=5000): +VCPacked(bb,eps,clpMX,clpMY,clpMZ,apx_vertices){faces.reserve(apx_faces);} +virtual ~GCPacked () { clear(); } +virtual void clear (); - xr_vector& Faces () { return faces; } +xr_vector& Faces () { return faces; } - void add_face (const Fvector& v0, const Fvector& v1, const Fvector& v2, u32 dummy=0); +void add_face (const Fvector& v0, const Fvector& v1, const Fvector& v2, u32 dummy=0); - GCFace* getF () { return &*faces.begin(); } - size_t getFS () { return faces.size(); } +GCFace* getF () { return &*faces.begin(); } +size_t getFS () { return faces.size(); } - void calc_adjacency(U32Vec& dest); +void calc_adjacency(U32Vec& dest); }; #endif + diff --git a/src/editors/ECore/Editor/ImageEditor.cpp b/src/editors/ECore/Editor/ImageEditor.cpp index 3047b6f34b9..39dc158cc07 100644 --- a/src/editors/ECore/Editor/ImageEditor.cpp +++ b/src/editors/ECore/Editor/ImageEditor.cpp @@ -5,10 +5,10 @@ #include "ImageEditor.h" #include "EThumbnail.h" #include "ImageManager.h" -#include "PropertiesList.h" -#include "FolderLib.h" +#include "editors/xrEProps/PropertiesList.h" +#include "editors/xrEProps/FolderLib.h" #include "ui_main.h" -#include "ItemList.h" +#include "editors/xrEProps/ItemList.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "ElTree" @@ -17,154 +17,168 @@ #pragma link "mxPlacemnt" #pragma link "MXCtrls" #pragma resource "*.dfm" -TfrmImageLib* TfrmImageLib::form = 0; -FS_FileSet TfrmImageLib::texture_map; -FS_FileSet TfrmImageLib::modif_map; -bool TfrmImageLib::bFormLocked=false; -Flags32 TfrmImageLib::m_Flags={0}; +TfrmImageLib *TfrmImageLib::form = 0; +FS_FileSet TfrmImageLib::texture_map; +FS_FileSet TfrmImageLib::modif_map; +bool TfrmImageLib::bFormLocked = false; +Flags32 TfrmImageLib::m_Flags = {0}; + //--------------------------------------------------------------------------- -__fastcall TfrmImageLib::TfrmImageLib(TComponent* Owner) +__fastcall TfrmImageLib::TfrmImageLib(TComponent *Owner) : TForm(Owner) { DEFINE_INI(fsStorage); - bImportMode = false; - ttImage->Tag = STextureParams::ttImage; - ttCubeMap->Tag = STextureParams::ttCubeMap; - ttBumpMap->Tag = STextureParams::ttBumpMap; - ttNormalMap->Tag= STextureParams::ttNormalMap; - ttTerrain->Tag = STextureParams::ttTerrain; + bImportMode = false; + ttImage->Tag = STextureParams::ttImage; + ttCubeMap->Tag = STextureParams::ttCubeMap; + ttBumpMap->Tag = STextureParams::ttBumpMap; + ttNormalMap->Tag = STextureParams::ttNormalMap; + ttTerrain->Tag = STextureParams::ttTerrain; } + //--------------------------------------------------------------------------- -void __fastcall TfrmImageLib::FormCreate(TObject*) +void __fastcall TfrmImageLib::FormCreate(TObject *) { - m_ItemProps = TProperties::CreateForm ("",paProperties,alClient); - m_ItemList = TItemList::CreateForm ("Items",paItems,alClient); - m_ItemList->SetOnItemsFocusedEvent (fastdelegate::bind(this,&TfrmImageLib::OnItemsFocused)); - m_ItemList->SetOnItemRemoveEvent (fastdelegate::bind(&ImageLib,&CImageManager::RemoveTexture)); - m_ItemList->SetImages (ImageList); + m_ItemProps = TProperties::CreateForm("", paProperties, alClient); + m_ItemList = TItemList::CreateForm("Items", paItems, alClient); + m_ItemList->SetOnItemsFocusedEvent(fastdelegate::bind(this, &TfrmImageLib::OnItemsFocused)); + m_ItemList->SetOnItemRemoveEvent(fastdelegate::bind(&ImageLib, &CImageManager::RemoveTexture)); + m_ItemList->SetImages(ImageList); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::FormDestroy(TObject *) { TProperties::DestroyForm(m_ItemProps); - TItemList::DestroyForm (m_ItemList); + TItemList::DestroyForm(m_ItemList); } + //--------------------------------------------------------------------------- -void __fastcall TfrmImageLib::EditLib(AnsiString& title, bool bImport) +void __fastcall TfrmImageLib::EditLib(AnsiString &title, bool bImport) { - if (!form){ - form = xr_new((TComponent*)0); - form->Caption = title; - form->bImportMode = bImport; - form->ebRemoveTexture->Enabled = !bImport; -//. form->ebRebuildAssociation->Enabled = !bImport; - form->bReadonlyMode = !FS.can_write_to_alias(_textures_); - if (form->bReadonlyMode){ - Log ("#!You don't have permisions to modify textures."); - form->ebOk->Enabled = false; - form->ebRemoveTexture->Enabled = false; -//. form->ebRebuildAssociation->Enabled = false; - form->m_ItemProps->SetReadOnly (TRUE); + if (!form) + { + form = xr_new((TComponent*)0); + form->Caption = title; + form->bImportMode = bImport; + form->ebRemoveTexture->Enabled = !bImport; + //. form->ebRebuildAssociation->Enabled = !bImport; + form->bReadonlyMode = !FS.can_write_to_alias(_textures_); + if (form->bReadonlyMode) + { + Log("#!You don't have permisions to modify textures."); + form->ebOk->Enabled = false; + form->ebRemoveTexture->Enabled = false; + //. form->ebRebuildAssociation->Enabled = false; + form->m_ItemProps->SetReadOnly(TRUE); } - form->modif_map.clear (); - form->paFilter->Enabled = !bImport; - m_Flags.zero (); + form->modif_map.clear(); + form->paFilter->Enabled = !bImport; + m_Flags.zero(); } form->ShowModal(); UI->RedrawScene(); } + //--------------------------------------------------------------------------- -ETextureThumbnail* TfrmImageLib::FindUsedTHM(const shared_str& name) +ETextureThumbnail *TfrmImageLib::FindUsedTHM(const shared_str &name) { THMMapIt it = m_THM_Used.find(name); - if (it!=m_THM_Used.end()) - return it->second; + if (it!=m_THM_Used.end()) + return it->second; - ETextureThumbnail* thm = xr_new(name.c_str(), false); - m_THM_Used[name] = thm; + ETextureThumbnail*thm = xr_new(name.c_str(),false); + m_THM_Used[name] = thm; - if(bImportMode) + if (bImportMode) { - xr_string fn = name.c_str(); - ImageLib.UpdateFileName (fn); + xr_string fn = name.c_str(); + ImageLib.UpdateFileName(fn); if (!thm->Load(name.c_str(), _import_)) { - bool bLoad = thm->Load(fn.c_str(),_game_textures_); - ImageLib.CreateTextureThumbnail (thm, name.c_str(), _import_, !bLoad); + bool bLoad = thm->Load(fn.c_str(), _game_textures_); + ImageLib.CreateTextureThumbnail(thm, name.c_str(), _import_, !bLoad); } - }else + } + else { - thm->Load(); + thm->Load(); } return thm; } + //--------------------------------------------------------------------------- void TfrmImageLib::SaveUsedTHM() { - for(THMMapIt t_it=m_THM_Used.begin(); t_it!=m_THM_Used.end(); ++t_it) - { - if (modif_map.find(FS_File(t_it->second->SrcName()))!=modif_map.end()) - t_it->second->Save(); + for (THMMapIt t_it = m_THM_Used.begin(); t_it!=m_THM_Used.end(); ++t_it) + { + if (modif_map.find(FS_File(t_it->second->SrcName()))!=modif_map.end()) + t_it->second->Save(); } } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::ImportTextures() { - texture_map.clear(); + texture_map.clear(); int new_cnt = ImageLib.GetLocalNewTextures(texture_map); - if (new_cnt){ - if (ELog.DlgMsg(mtInformation,"Found %d new texture(s)",new_cnt)) - EditLib(AnsiString("Update images"),true); - }else{ - ELog.DlgMsg(mtInformation,"Can't find new textures."); + if (new_cnt) + { + if (ELog.DlgMsg(mtInformation, "Found %d new texture(s)", new_cnt)) + EditLib(AnsiString("Update images"), true); + } + else + { + ELog.DlgMsg(mtInformation, "Can't find new textures."); } } void __fastcall TfrmImageLib::UpdateLib() { - VERIFY (!bReadonlyMode); - RegisterModifiedTHM (); - SaveUsedTHM (); - if (bImportMode && !texture_map.empty()) + VERIFY(!bReadonlyMode); + RegisterModifiedTHM(); + SaveUsedTHM(); + if (bImportMode&&!texture_map.empty()) { - AStringVec modif; + AStringVec modif; LockForm(); ImageLib.SafeCopyLocalToServer(texture_map); - // rename with folder - FS_FileSet files = texture_map; - texture_map.clear (); - xr_string fn; - FS_FileSetIt it = files.begin(); - FS_FileSetIt _E = files.end(); - - for (;it!=_E; it++) + // rename with folder + FS_FileSet files = texture_map; + texture_map.clear(); + xr_string fn; + FS_FileSetIt it = files.begin(); + FS_FileSetIt _E = files.end(); + + for (; it!=_E; it++) { - fn = EFS.ChangeFileExt(it->name.c_str(),""); + fn = EFS.ChangeFileExt(it->name.c_str(), ""); ImageLib.UpdateFileName(fn); - FS_File F(*it); - F.name = fn; - texture_map.insert (F); + FS_File F(*it); + F.name = fn; + texture_map.insert(F); } // sync - ImageLib.SynchronizeTextures(true,true,true,&texture_map,&modif); - UnlockForm (); - ImageLib.RefreshTextures(&modif); - }else + ImageLib.SynchronizeTextures(true, true, true, &texture_map, &modif); + UnlockForm(); + ImageLib.RefreshTextures(&modif); + } + else { - // save game textures + // save game textures if (modif_map.size()) { AStringVec modif; - LockForm(); - ImageLib.SynchronizeTextures(true,true,true,&modif_map,&modif); + LockForm(); + ImageLib.SynchronizeTextures(true, true, true, &modif_map, &modif); UnlockForm(); ImageLib.RefreshTextures(&modif); } @@ -173,182 +187,208 @@ void __fastcall TfrmImageLib::UpdateLib() bool __fastcall TfrmImageLib::HideLib() { - if (form){ - form->Close(); - texture_map.clear(); - modif_map.clear(); + if (form) + { + form->Close(); + texture_map.clear(); + modif_map.clear(); } return true; } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::FormShow(TObject *) { - InitItemsList (); - // check window position - UI->CheckWindowPos (this); + InitItemsList(); + // check window position + UI->CheckWindowPos(this); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::FormClose(TObject *, TCloseAction &Action) { - if (!form) return; - form->Enabled = false; - DestroyUsedTHM (); - form = 0; - Action = caFree; + if (!form) + return; + form->Enabled = false; + DestroyUsedTHM(); + form = 0; + Action = caFree; } + //--------------------------------------------------------------------------- void fix_texture_thm_name(LPSTR fn); -#include "ResourceManager.h" +#include "Layers/xrRender/ResourceManager.h" + void TfrmImageLib::InitItemsList() { - R_ASSERT (m_THM_Used.empty()); - if(!form->bImportMode) - ImageLib.GetTexturesRaw(texture_map); -/* - FS_FileSet flist; - FS.file_list (flist,"$game_textures$",FS_ListFiles|FS_ClampExt,"*.thm"); - Msg ("TfrmImageLib::InitItemsList count of .thm files=%d", flist.size()); - FS_FileSetIt It = flist.begin(); - FS_FileSetIt It_e = flist.end(); - string256 tex_name; - for(;It!=It_e;++It) - { - shared_str sn =(*It).name.c_str(); - FindUsedTHM (sn); - } -*/ - - ListItemsVec items; - SPBItem* pb = UI->ProgressStart (texture_map.size(),"Fill list..."); + R_ASSERT(m_THM_Used.empty()); + if (!form->bImportMode) + ImageLib.GetTexturesRaw(texture_map); + /* + FS_FileSet flist; + FS.file_list (flist,"$game_textures$",FS_ListFiles|FS_ClampExt,"*.thm"); + Msg ("TfrmImageLib::InitItemsList count of .thm files=%d", flist.size()); + FS_FileSetIt It = flist.begin(); + FS_FileSetIt It_e = flist.end(); + string256 tex_name; + for(;It!=It_e;++It) + { + shared_str sn =(*It).name.c_str(); + FindUsedTHM (sn); + } + */ + + ListItemsVec items; + SPBItem*pb = UI->ProgressStart(texture_map.size(), "Fill list..."); // fill - FS_FileSetIt it = texture_map.begin(); - FS_FileSetIt _E = texture_map.end(); + FS_FileSetIt it = texture_map.begin(); + FS_FileSetIt _E = texture_map.end(); for (; it!=_E; it++) { - pb->Inc (); - ListItem* I = LHelper().CreateItem(items,it->name.c_str(),0); - I->m_Object = (void*)(FindUsedTHM(it->name.c_str())); - R_ASSERT2 (I->m_Object, it->name.c_str()); + pb->Inc(); + ListItem *I = LHelper().CreateItem(items, it->name.c_str(), 0); + I->m_Object = (void*)(FindUsedTHM(it->name.c_str())); + R_ASSERT2(I->m_Object, it->name.c_str()); } - UI->ProgressEnd (pb); - m_ItemList->AssignItems (items,false,true); + UI->ProgressEnd(pb); + m_ItemList->AssignItems(items, false, true); } - //--------------------------------------------------------------------------- -void __fastcall TfrmImageLib::FormKeyDown(TObject*, WORD &Key, - TShiftState Shift) +void __fastcall TfrmImageLib::FormKeyDown(TObject *, WORD &Key, + TShiftState Shift) { - if (Shift.Contains(ssCtrl)){ - if (Key==VK_CANCEL) ExecCommand(COMMAND_BREAK_LAST_OPERATION); - }else{ - if (Key==VK_ESCAPE){ - if (bFormLocked) ExecCommand(COMMAND_BREAK_LAST_OPERATION); + if (Shift.Contains(ssCtrl)) + { + if (Key==VK_CANCEL) + ExecCommand(COMMAND_BREAK_LAST_OPERATION); + } + else + { + if (Key==VK_ESCAPE) + { + if (bFormLocked) + ExecCommand(COMMAND_BREAK_LAST_OPERATION); Key = 0; // :-) нужно для того чтобы AccessVoilation не вылазил по ESCAPE } } } + //--------------------------------------------------------------------------- -void __fastcall TfrmImageLib::ebOkClick(TObject*) +void __fastcall TfrmImageLib::ebOkClick(TObject *) { - if (bFormLocked) return; + if (bFormLocked) + return; - UpdateLib (); - HideLib (); + UpdateLib(); + HideLib(); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::ebCancelClick(TObject *) { - if (bFormLocked){ - ExecCommand(COMMAND_BREAK_LAST_OPERATION); - return; + if (bFormLocked) + { + ExecCommand(COMMAND_BREAK_LAST_OPERATION); + return; } HideLib(); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::RegisterModifiedTHM() { - if (m_ItemProps->IsModified()||bImportMode) + if (m_ItemProps->IsModified()||bImportMode) { - for (THMIt t_it=m_THM_Current.begin(); t_it!=m_THM_Current.end(); ++t_it) + for (THMIt t_it = m_THM_Current.begin(); t_it!=m_THM_Current.end(); ++t_it) { - FS_FileSetIt it = texture_map.find(FS_File((*t_it)->SrcName())); - R_ASSERT (it!=texture_map.end()); - modif_map.insert (*it); + FS_FileSetIt it = texture_map.find(FS_File((*t_it)->SrcName())); + R_ASSERT(it!=texture_map.end()); + modif_map.insert(*it); } } } void __fastcall TfrmImageLib::fsStorageRestorePlacement(TObject *) -{ - m_ItemProps->RestoreParams(fsStorage); +{ + m_ItemProps->RestoreParams(fsStorage); m_ItemList->LoadParams(fsStorage); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::fsStorageSavePlacement(TObject *) { - m_ItemProps->SaveParams(fsStorage); + m_ItemProps->SaveParams(fsStorage); m_ItemList->SaveParams(fsStorage); } + //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::ebRemoveTextureClick(TObject *) { - m_ItemList->RemoveSelItems(0); + m_ItemList->RemoveSelItems(0); } + //--------------------------------------------------------------------------- void TfrmImageLib::DestroyUsedTHM() { for (THMMapIt it = m_THM_Used.begin(); it!=m_THM_Used.end(); ++it) - xr_delete(it->second); + xr_delete(it->second); m_THM_Used.clear(); } -void TfrmImageLib::OnTypeChange(PropValue* ) +void TfrmImageLib::OnTypeChange(PropValue *) { - UpdateProperties(); + UpdateProperties(); } -void TfrmImageLib::OnCubeMapBtnClick(ButtonValue* value, bool& bModif, bool& ) +void TfrmImageLib::OnCubeMapBtnClick(ButtonValue *value, bool &bModif, bool &) { - ButtonValue* B = dynamic_cast(value); R_ASSERT(B); + ButtonValue *B = dynamic_cast(value); + R_ASSERT(B); bModif = false; - switch(B->btn_num){ - case 0:{ - RStringVec items; - if (0!=m_ItemList->GetSelected(items)){ - for (RStringVecIt it=items.begin(); it!=items.end(); it++){ - AnsiString new_name = AnsiString(it->c_str())+"#small"; - ImageLib.CreateSmallerCubeMap(it->c_str(),new_name.c_str()); + switch (B->btn_num) + { + case 0: + { + RStringVec items; + if (0!=m_ItemList->GetSelected(items)) + { + for (RStringVecIt it = items.begin(); it!=items.end(); it++) + { + AnsiString new_name = AnsiString(it->c_str())+"#small"; + ImageLib.CreateSmallerCubeMap(it->c_str(), new_name.c_str()); + } } } - }break; - } + break; + } } -void TfrmImageLib::OnItemsFocused(ListItemsVec& items) +void TfrmImageLib::OnItemsFocused(ListItemsVec &items) { - PropItemVec props; + PropItemVec props; + + RegisterModifiedTHM(); + m_THM_Current.clear(); - RegisterModifiedTHM (); - m_THM_Current.clear (); - - if (!items.empty()) + if (!items.empty()) { - for (ListItemsIt it=items.begin(); it!=items.end(); it++) + for (ListItemsIt it = items.begin(); it!=items.end(); it++) { - ListItem* prop = *it; - if (prop){ - ETextureThumbnail* thm=0; + ListItem *prop = *it; + if (prop) + { + ETextureThumbnail*thm = 0; thm = FindUsedTHM(prop->Key()); /* @@ -357,134 +397,142 @@ void TfrmImageLib::OnItemsFocused(ListItemsVec& items) thm = FindUsedTHM(prop->Key()); if (!thm) { - m_THM_Used.push_back (thm=xr_new(prop->Key(),false)); - xr_string fn = prop->Key(); - ImageLib.UpdateFileName (fn); + m_THM_Used.push_back (thm=xr_new(prop->Key(),false)); + xr_string fn = prop->Key(); + ImageLib.UpdateFileName (fn); - if (!thm->Load(prop->Key(),_import_)) + if (!thm->Load(prop->Key(),_import_)) { - bool bLoad = thm->Load(fn.c_str(),_game_textures_); + bool bLoad = thm->Load(fn.c_str(),_game_textures_); ImageLib.CreateTextureThumbnail (thm, prop->Key(), _import_, !bLoad); - } + } } }else { thm = FindUsedTHM(prop->Key()); if (!thm) - m_THM_Used.push_back(thm=xr_new(prop->Key())); + m_THM_Used.push_back(thm=xr_new(prop->Key())); } */ - m_THM_Current.push_back (thm); + m_THM_Current.push_back(thm); //prop->tag = thm->_Format().type; - + // fill prop - thm->FillProp (props,PropValue::TOnChange(this,&TfrmImageLib::OnTypeChange)); - - if (thm->_Format().type==STextureParams::ttCubeMap) + thm->FillProp(props, PropValue::TOnChange(this, &TfrmImageLib::OnTypeChange)); + + if (thm->_Format().type==STextureParams::ttCubeMap) { - ButtonValue* B = PHelper().CreateButton (props, "CubeMap\\Edit", "Make Small", 0); - B->OnBtnClickEvent.bind(this,&TfrmImageLib::OnCubeMapBtnClick); + ButtonValue *B = PHelper().CreateButton(props, "CubeMap\\Edit", "Make Small", 0); + B->OnBtnClickEvent.bind(this, &TfrmImageLib::OnCubeMapBtnClick); } } } } - paImage->Repaint (); + paImage->Repaint(); m_ItemProps->tvProperties->MultiSelect = true; - m_ItemProps->AssignItems (props); + m_ItemProps->AssignItems(props); } void __fastcall TfrmImageLib::btFilterClick(TObject *Sender) { - if(m_THM_Current.size()!=1 ) return; + if (m_THM_Current.size()!=1) + return; - ETextureThumbnail* thm = m_THM_Current.back(); - xr_vector sel_str_vec; - - for ( TElTreeItem* node = m_ItemProps->tvProperties->Items->GetFirstNode(); node; node = node->GetNext()) + ETextureThumbnail*thm = m_THM_Current.back(); + xr_vector sel_str_vec; + + for (TElTreeItem *node = m_ItemProps->tvProperties->Items->GetFirstNode(); node; node = node->GetNext()) { - if (node && node->Selected && node->ChildrenCount==0) + if (node&&node->Selected&&node->ChildrenCount==0) { AnsiString str = node->Text; - if(node->Parent) - str = node->Parent->Text + "\\" + str; - - sel_str_vec.push_back(str); + if (node->Parent) + str = node->Parent->Text+"\\"+str; + + sel_str_vec.push_back(str); } } - SortList(thm, sel_str_vec); + SortList(thm, sel_str_vec); } //--------------------------------------------------------------------------- void __fastcall TfrmImageLib::paImagePaint(TObject *) { - if (m_THM_Current.size()==1) m_THM_Current.back()->Draw(paImage); + if (m_THM_Current.size()==1) + m_THM_Current.back()->Draw(paImage); } + //--------------------------------------------------------------------------- void TfrmImageLib::OnFrame() { - if (form){ - if (m_Flags.is(flUpdateProperties)){ - form->m_ItemList->FireOnItemFocused(); - m_Flags.set(flUpdateProperties,FALSE); + if (form) + { + if (m_Flags.is(flUpdateProperties)) + { + form->m_ItemList->FireOnItemFocused(); + m_Flags.set(flUpdateProperties, FALSE); } } } void __fastcall TfrmImageLib::ttImageClick(TObject *Sender) { - const ListItemsVec& items = m_ItemList->GetItems(); + const ListItemsVec &items = m_ItemList->GetItems(); u32 cnt = items.size(); - for (u32 k=0; km_Object; + ETextureThumbnail*thm = (ETextureThumbnail*)I->m_Object; BOOL bVis = FALSE; - int type = thm->_Format().type; - - if (ttImage->Down && ttImage->Tag==type) - bVis = TRUE; - else if (ttCubeMap->Down && ttCubeMap->Tag==type) - bVis = TRUE; - else if (ttBumpMap->Down && ttBumpMap->Tag==type) - bVis = TRUE; - else if (ttNormalMap->Down && ttNormalMap->Tag==type) - bVis = TRUE; - else if (ttTerrain->Down && ttTerrain->Tag==type) - bVis = TRUE; - - I->Visible(bVis); + int type = thm->_Format().type; + + if (ttImage->Down&&ttImage->Tag==type) + bVis = TRUE; + else if (ttCubeMap->Down&&ttCubeMap->Tag==type) + bVis = TRUE; + else if (ttBumpMap->Down&&ttBumpMap->Tag==type) + bVis = TRUE; + else if (ttNormalMap->Down&&ttNormalMap->Tag==type) + bVis = TRUE; + else if (ttTerrain->Down&&ttTerrain->Tag==type) + bVis = TRUE; + + I->Visible(bVis); } - m_ItemList->RefreshForm (); + m_ItemList->RefreshForm(); } -void TfrmImageLib::SortList(ETextureThumbnail* thm0, xr_vector& sel_params) +void TfrmImageLib::SortList(ETextureThumbnail *thm0, xr_vector &sel_params) { - ttImageClick (NULL); - const ListItemsVec& items = m_ItemList->GetItems(); + ttImageClick(NULL); + const ListItemsVec &items = m_ItemList->GetItems(); u32 cnt = items.size(); - for (u32 k=0; kVisible()) continue; - ETextureThumbnail* thm1 = (ETextureThumbnail*)I->m_Object; - - BOOL bVis = thm0->similar(thm1, sel_params); - I->Visible (bVis); - } - m_ItemList->RefreshForm (); - m_ItemList->ExpandAll1Click (NULL); + ListItem *I = items[k]; + if (!I->Visible()) + continue; + ETextureThumbnail*thm1 = (ETextureThumbnail*)I->m_Object; + + BOOL bVis = thm0->similar(thm1, sel_params); + I->Visible(bVis); + } + m_ItemList->RefreshForm(); + m_ItemList->ExpandAll1Click(NULL); } void __fastcall TfrmImageLib::ExtBtn1Click(TObject *Sender) { - ttImageClick(Sender); - m_ItemList->CollapseAll1Click(Sender); + ttImageClick(Sender); + m_ItemList->CollapseAll1Click(Sender); } + //--------------------------------------------------------------------------- + diff --git a/src/editors/ECore/Editor/ImageEditor.h b/src/editors/ECore/Editor/ImageEditor.h index 8b37ff28871..e0a07cd9ad5 100644 --- a/src/editors/ECore/Editor/ImageEditor.h +++ b/src/editors/ECore/Editor/ImageEditor.h @@ -19,100 +19,126 @@ // refs class ETextureThumbnail; class TProperties; + //--------------------------------------------------------------------------- class TfrmImageLib : public TForm { -__published: // IDE-managed Components - TPanel *paRight; - TFormStorage *fsStorage; - TPanel *paCommand; - TExtBtn *ebOk; - TBevel *Bevel1; - TPanel *paProperties; - TPanel *paItems; - TSplitter *Splitter1; - TBevel *Bevel2; - TImageList *ImageList; - TExtBtn *ebCancel; - TExtBtn *ebRemoveTexture; - TBevel *Bevel5; - TPanel *Panel1; - TMxPanel *paImage; - TPanel *paFilter; - TExtBtn *ttImage; - TExtBtn *ttBumpMap; - TExtBtn *ttNormalMap; - TExtBtn *ttCubeMap; - TExtBtn *ttTerrain; - TPanel *Panel2; - TExtBtn *btFilter; - TExtBtn *ExtBtn1; + __published: // IDE-managed Components + TPanel*paRight; + TFormStorage *fsStorage; + TPanel *paCommand; + TExtBtn *ebOk; + TBevel *Bevel1; + TPanel *paProperties; + TPanel *paItems; + TSplitter *Splitter1; + TBevel *Bevel2; + TImageList *ImageList; + TExtBtn *ebCancel; + TExtBtn *ebRemoveTexture; + TBevel *Bevel5; + TPanel *Panel1; + TMxPanel *paImage; + TPanel *paFilter; + TExtBtn *ttImage; + TExtBtn *ttBumpMap; + TExtBtn *ttNormalMap; + TExtBtn *ttCubeMap; + TExtBtn *ttTerrain; + TPanel *Panel2; + TExtBtn *btFilter; + TExtBtn *ExtBtn1; void __fastcall ebOkClick(TObject *Sender); void __fastcall FormShow(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift); - void __fastcall fsStorageRestorePlacement(TObject *Sender); - void __fastcall fsStorageSavePlacement(TObject *Sender); - void __fastcall FormCreate(TObject *Sender); - void __fastcall ebCancelClick(TObject *Sender); - void __fastcall ebRemoveTextureClick(TObject *Sender); - void __fastcall FormDestroy(TObject *Sender); - void __fastcall paImagePaint(TObject *Sender); - void __fastcall ttImageClick(TObject *Sender); - void __fastcall btFilterClick(TObject *Sender); - void __fastcall ExtBtn1Click(TObject *Sender); + TShiftState Shift); + void __fastcall fsStorageRestorePlacement(TObject *Sender); + void __fastcall fsStorageSavePlacement(TObject *Sender); + void __fastcall FormCreate(TObject *Sender); + void __fastcall ebCancelClick(TObject *Sender); + void __fastcall ebRemoveTextureClick(TObject *Sender); + void __fastcall FormDestroy(TObject *Sender); + void __fastcall paImagePaint(TObject *Sender); + void __fastcall ttImageClick(TObject *Sender); + void __fastcall btFilterClick(TObject *Sender); + void __fastcall ExtBtn1Click(TObject *Sender); private: -// list functions - void __stdcall RemoveTexture (LPCSTR fname, EItemType type, bool& res); - - void InitItemsList (); - void __stdcall OnItemsFocused (ListItemsVec& items); - - void __stdcall OnCubeMapBtnClick (ButtonValue* value, bool& bModif, bool& bSafe); - - enum{ - flUpdateProperties = (1<<0), - }; - static Flags32 m_Flags; -private: // User declarations - static TfrmImageLib* form; - - DEFINE_VECTOR (ETextureThumbnail*,THMVec,THMIt); - DEFINE_MAP (shared_str,ETextureThumbnail*,THMMap,THMMapIt); - THMMap m_THM_Used; - THMVec m_THM_Current; - TItemList* m_ItemList; - TProperties* m_ItemProps; - - ETextureThumbnail* FindUsedTHM (const shared_str& name); - void SaveUsedTHM (); - void DestroyUsedTHM (); - - void __fastcall RegisterModifiedTHM (); - - void OnModified (); - static FS_FileSet texture_map; - static FS_FileSet modif_map; - bool bImportMode; - bool bReadonlyMode; - void __fastcall UpdateLib (); - static bool bFormLocked; - static void LockForm (){ bFormLocked = true; form->paProperties->Enabled = false; form->paItems->Enabled = false; } - static void UnlockForm (){ bFormLocked = false;form->paProperties->Enabled = true; form->paItems->Enabled = true; } - - void __stdcall OnTypeChange (PropValue* prop); - void SortList (ETextureThumbnail* thm, xr_vector& sel_str_vec); -public: // User declarations - __fastcall TfrmImageLib (TComponent* Owner); -// static function - static void __fastcall ImportTextures (); - static void __fastcall EditLib (AnsiString& title, bool bImport=false); - static bool __fastcall HideLib (); - static bool __fastcall Visible (){return !!form;} - static void OnFrame (); - static void UpdateProperties (){m_Flags.set(flUpdateProperties,TRUE);} + // list functions + void __stdcall RemoveTexture(LPCSTR fname, EItemType type, bool &res); + + void InitItemsList(); + void __stdcall OnItemsFocused(ListItemsVec &items); + + void __stdcall OnCubeMapBtnClick(ButtonValue *value, bool &bModif, bool &bSafe); + + enum + { + flUpdateProperties = (1<<0), + }; + + static Flags32 m_Flags; +private: // User declarations + static TfrmImageLib *form; + + DEFINE_VECTOR(ETextureThumbnail *, THMVec, THMIt); + DEFINE_MAP(shared_str, ETextureThumbnail *, THMMap, THMMapIt); + THMMap m_THM_Used; + THMVec m_THM_Current; + TItemList *m_ItemList; + TProperties *m_ItemProps; + + ETextureThumbnail *FindUsedTHM(const shared_str &name); + void SaveUsedTHM(); + void DestroyUsedTHM(); + + void __fastcall RegisterModifiedTHM(); + + void OnModified(); + static FS_FileSet texture_map; + static FS_FileSet modif_map; + bool bImportMode; + bool bReadonlyMode; + void __fastcall UpdateLib(); + static bool bFormLocked; + + static void LockForm() + { + bFormLocked = true; + form->paProperties->Enabled = false; + form->paItems->Enabled = false; + } + + static void UnlockForm() + { + bFormLocked = false; + form->paProperties->Enabled = true; + form->paItems->Enabled = true; + } + + void __stdcall OnTypeChange(PropValue *prop); + void SortList(ETextureThumbnail *thm, xr_vector &sel_str_vec); +public: // User declarations + __fastcall TfrmImageLib(TComponent *Owner); + // static function + static void __fastcall ImportTextures(); + static void __fastcall EditLib(AnsiString &title, bool bImport = false); + static bool __fastcall HideLib(); + + static bool __fastcall Visible() + { + return !!form; + } + + static void OnFrame(); + + static void UpdateProperties() + { + m_Flags.set(flUpdateProperties, TRUE); + } }; + //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/ImageManager.cpp b/src/editors/ECore/Editor/ImageManager.cpp index c560fe73c41..0077ad31a30 100644 --- a/src/editors/ECore/Editor/ImageManager.cpp +++ b/src/editors/ECore/Editor/ImageManager.cpp @@ -7,215 +7,251 @@ #include "Image.h" #include "ui_main.h" #include "EditObject.h" -#include "ResourceManager.h" +#include "Layers/xrRender/ResourceManager.h" CImageManager ImageLib; //--------------------------------------------------------------------------- #pragma package(smart_init) extern bool IsFormatRegister(LPCSTR ext); -extern FIBITMAP* Surface_Load(char* full_name); +extern FIBITMAP *Surface_Load(char *full_name); extern "C" __declspec(dllimport) -int DXTCompress (LPCSTR out_name, u8* raw_data, u8* ext_data, u32 w, u32 h, u32 pitch, - STextureParams* options, u32 depth); +int DXTCompress(LPCSTR out_name, u8 *raw_data, u8 *ext_data, u32 w, u32 h, u32 pitch, + STextureParams *options, u32 depth); -bool IsValidSize(u32 w, u32 h){ - if (!btwIsPow2(h)) return false; - if (h*6==w) return true; - if (!btwIsPow2(w)) return false; +bool IsValidSize(u32 w, u32 h) +{ + if (!btwIsPow2(h)) + return false; + if (h*6==w) + return true; + if (!btwIsPow2(w)) + return false; return true; } -bool Surface_Load(LPCSTR full_name, U32Vec& data, u32& w, u32& h, u32& a) +bool Surface_Load(LPCSTR full_name, U32Vec &data, u32 &w, u32 &h, u32 &a) { - if (!FS.exist(full_name)){ - ELog.Msg(mtError,"Can't find file: '%s'",full_name); - return false; + if (!FS.exist(full_name)) + { + ELog.Msg(mtError, "Can't find file: '%s'", full_name); + return false; } - AnsiString ext = ExtractFileExt(full_name).LowerCase(); - if (ext==".tga"){ - CImage img; - if (!img.LoadTGA (full_name)) return false; - w = img.dwWidth; - h = img.dwHeight; - a = img.bAlpha; - data.resize (w*h); - CopyMemory (data.begin(),img.pData,sizeof(u32)*data.size()); - if (!IsValidSize(w,h)) ELog.Msg(mtError,"Texture (%s) - invalid size: [%d, %d]",full_name,w,h); + AnsiString ext = ExtractFileExt(full_name).LowerCase(); + if (ext==".tga") + { + CImage img; + if (!img.LoadTGA(full_name)) + return false; + w = img.dwWidth; + h = img.dwHeight; + a = img.bAlpha; + data.resize(w*h); + CopyMemory(data.begin(), img.pData, sizeof(u32)*data.size()); + if (!IsValidSize(w, h)) + ELog.Msg(mtError, "Texture (%s) - invalid size: [%d, %d]", full_name, w, h); return true; - }else{ - FIBITMAP* bm = Surface_Load((LPSTR)full_name); - if (bm){ - w = FreeImage_GetWidth (bm); - h = FreeImage_GetHeight(bm); - u32 w4 = w*4; - data.resize (w*h); - for (int y=h-1; y>=0; y--) CopyMemory(data.begin()+(h-y-1)*w,FreeImage_GetScanLine(bm,y),w4); - a = FIC_RGBALPHA==FreeImage_GetColorType(bm); - FreeImage_Unload (bm); - if (!IsValidSize(w,h)) ELog.Msg(mtError,"Texture (%s) - invalid size: [%d, %d]",full_name,w,h); + } + else + { + FIBITMAP *bm = Surface_Load((LPSTR)full_name); + if (bm) + { + w = FreeImage_GetWidth(bm); + h = FreeImage_GetHeight(bm); + u32 w4 = w*4; + data.resize(w*h); + for (int y = h-1; y>=0; y--) + CopyMemory(data.begin()+(h-y-1)*w, FreeImage_GetScanLine(bm, y), w4); + a = FIC_RGBALPHA==FreeImage_GetColorType(bm); + FreeImage_Unload(bm); + if (!IsValidSize(w, h)) + ELog.Msg(mtError, "Texture (%s) - invalid size: [%d, %d]", full_name, w, h); return true; } } - return false; + return false; } + //------------------------------------------------------------------------------ -xr_string CImageManager::UpdateFileName(xr_string& fn) +xr_string CImageManager::UpdateFileName(xr_string &fn) { - return EFS.AppendFolderToName(fn,1,TRUE); + return EFS.AppendFolderToName(fn, 1, TRUE); } //------------------------------------------------------------------------------ // создает тхм //------------------------------------------------------------------------------ -void CImageManager::MakeThumbnailImage(ETextureThumbnail* THM, u32* data, u32 w, u32 h, u32 a) +void CImageManager::MakeThumbnailImage(ETextureThumbnail *THM, u32 *data, u32 w, u32 h, u32 a) { - R_ASSERT(THM); - // create thumbnail - if (THM->m_Pixels.empty()) THM->m_Pixels.resize(THUMB_SIZE); - THM->m_TexParams.width = w; - THM->m_TexParams.height= h; - THM->m_TexParams.flags.set(STextureParams::flHasAlpha,a); - imf_Process(THM->m_Pixels.begin(),THUMB_WIDTH,THUMB_HEIGHT,data,THM->_Width(),THM->_Height(),imf_box); + R_ASSERT(THM); + // create thumbnail + if (THM->m_Pixels.empty()) + THM->m_Pixels.resize(THUMB_SIZE); + THM->m_TexParams.width = w; + THM->m_TexParams.height = h; + THM->m_TexParams.flags.set(STextureParams::flHasAlpha, a); + imf_Process(THM->m_Pixels.begin(), THUMB_WIDTH, THUMB_HEIGHT, data, THM->_Width(), THM->_Height(), imf_box); THM->VFlip(); } //------------------------------------------------------------------------------ // создает тхм //------------------------------------------------------------------------------ -void CImageManager::CreateTextureThumbnail(ETextureThumbnail* THM, const AnsiString& src_name, LPCSTR initial, bool bSetDefParam) +void CImageManager::CreateTextureThumbnail(ETextureThumbnail *THM, const AnsiString &src_name, LPCSTR initial, bool bSetDefParam) { - R_ASSERT(src_name.Length()); - string_path base_name; + R_ASSERT(src_name.Length()); + string_path base_name; if (initial) - FS.update_path(base_name,initial,src_name.c_str()); + FS.update_path(base_name, initial, src_name.c_str()); else - FS.update_path(base_name,_textures_,src_name.c_str()); + FS.update_path(base_name, _textures_, src_name.c_str()); U32Vec data; u32 w, h, a; - xr_string fn = EFS.ChangeFileExt(base_name,".tga"); - if (!Surface_Load(fn.c_str(),data,w,h,a)) + xr_string fn = EFS.ChangeFileExt(base_name, ".tga"); + if (!Surface_Load(fn.c_str(), data, w, h, a)) { - ELog.Msg(mtError,"Can't load texture '%s'.\nCheck file existence",fn.c_str()); - return; + ELog.Msg(mtError, "Can't load texture '%s'.\nCheck file existence", fn.c_str()); + return; } - MakeThumbnailImage(THM,data.begin(),w,h,a); + MakeThumbnailImage(THM, data.begin(), w, h, a); // выставить начальные параметры - if (bSetDefParam){ - THM->m_Age = FS.get_file_age(fn.c_str()); - THM->m_TexParams.fmt = (a)?STextureParams::tfDXT3:STextureParams::tfDXT1; - if ((h*6)==w){ - THM->m_TexParams.type = STextureParams::ttCubeMap; - THM->m_TexParams.flags.set (STextureParams::flGenerateMipMaps,FALSE); + if (bSetDefParam) + { + THM->m_Age = FS.get_file_age(fn.c_str()); + THM->m_TexParams.fmt = (a) ? STextureParams::tfDXT3 : STextureParams::tfDXT1; + if ((h*6)==w) + { + THM->m_TexParams.type = STextureParams::ttCubeMap; + THM->m_TexParams.flags.set(STextureParams::flGenerateMipMaps, FALSE); } } THM->SetValid(); } + //------------------------------------------------------------------------------ // создает новую текстуру //------------------------------------------------------------------------------ -void CImageManager::CreateGameTexture(LPCSTR src_name, ETextureThumbnail* thumb) +void CImageManager::CreateGameTexture(LPCSTR src_name, ETextureThumbnail *thumb) { - R_ASSERT(src_name&&src_name[0]); - ETextureThumbnail* THM = thumb?thumb:xr_new(src_name); - string_path base_name; - strcpy (base_name,src_name); + R_ASSERT(src_name&&src_name[0]); + ETextureThumbnail *THM = thumb ? thumb : xr_new(src_name); + string_path base_name; + strcpy(base_name, src_name); - string_path game_name; - strcpy (game_name,EFS.ChangeFileExt(src_name,".dds").c_str()); - FS.update_path (base_name,_textures_,base_name); - FS.update_path (game_name,_game_textures_,game_name); - int base_age = FS.get_file_age(base_name); + string_path game_name; + strcpy(game_name, EFS.ChangeFileExt(src_name, ".dds").c_str()); + FS.update_path(base_name, _textures_, base_name); + FS.update_path(game_name, _game_textures_, game_name); + int base_age = FS.get_file_age(base_name); U32Vec data; u32 w, h, a; - if (!Surface_Load(base_name,data,w,h,a)) return; - MakeGameTexture(THM,game_name,data.begin()); + if (!Surface_Load(base_name, data, w, h, a)) + return; + MakeGameTexture(THM, game_name, data.begin()); FS.set_file_age(game_name, base_age); - if (!thumb) xr_delete(THM); + if (!thumb) + xr_delete(THM); } //------------------------------------------------------------------------------ // создает игровую текстуру //------------------------------------------------------------------------------ -bool CImageManager::MakeGameTexture(LPCSTR game_name, u32* data, const STextureParams& tp) +bool CImageManager::MakeGameTexture(LPCSTR game_name, u32 *data, const STextureParams &tp) { - VerifyPath(game_name); + VerifyPath(game_name); // fill texture params - // compress - u32 w4= tp.width*4; - int res = DXTCompress(game_name, (u8*)data, 0, tp.width, tp.height, w4, (STextureParams*)&tp, 4); - if (1!=res){ - FS.file_delete(game_name); - switch(res){ - case 0: ELog.DlgMsg (mtError,"Can't make game texture '%s'.",game_name); break; - case -1000: ELog.Msg (mtError,"Invalid gloss mask '%s'.",game_name); return true; + // compress + u32 w4 = tp.width*4; + int res = DXTCompress(game_name, (u8*)data, 0, tp.width, tp.height, w4, (STextureParams*)&tp, 4); + if (1!=res) + { + FS.file_delete(game_name); + switch (res) + { + case 0: ELog.DlgMsg(mtError, "Can't make game texture '%s'.", game_name); + break; + case -1000: ELog.Msg(mtError, "Invalid gloss mask '%s'.", game_name); + return true; } - return false; + return false; } R_ASSERT((res==1)&&FS.file_length(game_name)); return res==1; } -bool CImageManager::MakeGameTexture(ETextureThumbnail* THM, LPCSTR game_name, u32* load_data) + +bool CImageManager::MakeGameTexture(ETextureThumbnail *THM, LPCSTR game_name, u32 *load_data) { - VerifyPath(game_name); + VerifyPath(game_name); // flip u32 w = THM->_Width(); u32 h = THM->_Height(); - u32 w4= w*4; - // remove old - FS.file_delete (game_name); - AnsiString game_name2 = ChangeFileExt(game_name,"#.dds"); - FS.file_delete (game_name2.c_str()); + u32 w4 = w*4; + // remove old + FS.file_delete(game_name); + AnsiString game_name2 = ChangeFileExt(game_name, "#.dds"); + FS.file_delete(game_name2.c_str()); - U32Vec ext_data; + U32Vec ext_data; if ((THM->m_TexParams.type==STextureParams::ttBumpMap)&&(THM->m_TexParams.ext_normal_map_name.size())) { - bool e_res = true; - LPCSTR e_name = THM->m_TexParams.ext_normal_map_name.c_str(); - ETextureThumbnail* NM_THM = xr_new(e_name); + bool e_res = true; + LPCSTR e_name = THM->m_TexParams.ext_normal_map_name.c_str(); + ETextureThumbnail *NM_THM = xr_new(e_name); if (NM_THM->_Format().type==STextureParams::ttNormalMap) { - if (NM_THM->_Format().fmt==STextureParams::tfRGBA) + if (NM_THM->_Format().fmt==STextureParams::tfRGBA) { - u32 _w,_h; - if (!LoadTextureData(e_name,ext_data,_w,_h)) + u32 _w, _h; + if (!LoadTextureData(e_name, ext_data, _w, _h)) { - ELog.DlgMsg (mtError,"Can't load special normal map texture '%s'.",e_name); - e_res = false; - }else if ((_w!=w)||(_h!=h)) + ELog.DlgMsg(mtError, "Can't load special normal map texture '%s'.", e_name); + e_res = false; + } + else if ((_w!=w)||(_h!=h)) { - ELog.DlgMsg (mtError,"Invalid load special normal map size '%s'. It should be [%dx%d]",e_name,w,h); - e_res = false; + ELog.DlgMsg(mtError, "Invalid load special normal map size '%s'. It should be [%dx%d]", e_name, w, h); + e_res = false; } - }else{ - ELog.DlgMsg (mtError,"Invalid special normal map format '%s'. It should be '32 bit (8:8:8:8)'",e_name); - e_res = false; } - }else{ - ELog.DlgMsg (mtError,"Invalid special normal map type '%s'. It should be 'NormalMap'",e_name); - e_res = false; + else + { + ELog.DlgMsg(mtError, "Invalid special normal map format '%s'. It should be '32 bit (8:8:8:8)'", e_name); + e_res = false; + } + } + else + { + ELog.DlgMsg(mtError, "Invalid special normal map type '%s'. It should be 'NormalMap'", e_name); + e_res = false; } - xr_delete (NM_THM); - if (false==e_res) return false; + xr_delete(NM_THM); + if (false==e_res) + return false; } // compress - - int res = DXTCompress(game_name, (u8*)load_data, (u8*)(ext_data.empty()?0:ext_data.begin()), w, h, w4, &THM->m_TexParams, 4); - if (1!=res){ - if (-1000!=res){ //. Special for Oles (glos<10%) - FS.file_delete (game_name); - FS.file_delete (game_name2.c_str()); + + int res = DXTCompress(game_name, (u8*)load_data, (u8*)(ext_data.empty() ? 0 : ext_data.begin()), w, h, w4, &THM->m_TexParams, 4); + if (1!=res) + { + if (-1000!=res) + { //. Special for Oles (glos<10%) + FS.file_delete(game_name); + FS.file_delete(game_name2.c_str()); } - switch(res){ - case 0: ELog.DlgMsg (mtError,"Can't make game texture '%s'.",THM->m_SrcName.c_str()); break; - case -1000: ELog.Msg (mtError,"Invalid gloss mask '%s'.",THM->m_SrcName.c_str()); return true; + switch (res) + { + case 0: ELog.DlgMsg(mtError, "Can't make game texture '%s'.", THM->m_SrcName.c_str()); + break; + case -1000: ELog.Msg(mtError, "Invalid gloss mask '%s'.", THM->m_SrcName.c_str()); + return true; } - return false; + return false; } R_ASSERT((res==1)&&FS.file_length(game_name)); return res==1; @@ -224,14 +260,16 @@ bool CImageManager::MakeGameTexture(ETextureThumbnail* THM, LPCSTR game_name, u3 //------------------------------------------------------------------------------ // загружает 32-bit данные //------------------------------------------------------------------------------ -bool CImageManager::LoadTextureData(LPCSTR src_name, U32Vec& data, u32& w, u32& h, int* age) +bool CImageManager::LoadTextureData(LPCSTR src_name, U32Vec &data, u32 &w, u32 &h, int *age) { - string_path fn; -//. FS.update_path (fn,_textures_,ChangeFileExt(src_name,".tga").c_str()); - FS.update_path (fn,_game_textures_,ChangeFileExt(src_name,".dds").c_str()); + string_path fn; + //. FS.update_path (fn,_textures_,ChangeFileExt(src_name,".tga").c_str()); + FS.update_path(fn, _game_textures_, ChangeFileExt(src_name, ".dds").c_str()); u32 a; - if (!Surface_Load(fn,data,w,h,a)) return false; - if (age) *age = FS.get_file_age(fn); + if (!Surface_Load(fn, data, w, h, a)) + return false; + if (age) + *age = FS.get_file_age(fn); return true; } @@ -239,156 +277,193 @@ bool CImageManager::LoadTextureData(LPCSTR src_name, U32Vec& data, u32& w, u32& // копирует обновленные текстуры с Import'a в Textures // files - список файлов для копирование //------------------------------------------------------------------------------ -void CImageManager::SafeCopyLocalToServer(FS_FileSet& files) +void CImageManager::SafeCopyLocalToServer(FS_FileSet &files) { - string_path p_import, p_textures; - string_path src_name, dest_name; - FS.update_path (p_import,_import_,""); - FS.update_path (p_textures,_textures_,""); - - FS_FileSetIt it = files.begin(); - FS_FileSetIt _E = files.end(); - for (; it!=_E; it++){ - xr_string fn; - - // copy sources - fn = it->name; - strconcat (sizeof(src_name),src_name, p_import, fn.c_str()); - UpdateFileName (fn); - - strconcat(sizeof(dest_name),dest_name, p_textures, EFS.ChangeFileExt(fn,".tga").c_str() ); - - if (0==strcmp(strext(src_name),".tga")){ - FS.file_copy(src_name,dest_name); - }else{ - // convert to TGA + string_path p_import, p_textures; + string_path src_name, dest_name; + FS.update_path(p_import, _import_, ""); + FS.update_path(p_textures, _textures_, ""); + + FS_FileSetIt it = files.begin(); + FS_FileSetIt _E = files.end(); + for (; it!=_E; it++) + { + xr_string fn; + + // copy sources + fn = it->name; + strconcat(sizeof(src_name), src_name, p_import, fn.c_str()); + UpdateFileName(fn); + + strconcat(sizeof(dest_name), dest_name, p_textures, EFS.ChangeFileExt(fn, ".tga").c_str()); + + if (0==strcmp(strext(src_name), ".tga")) + { + FS.file_copy(src_name, dest_name); + } + else + { + // convert to TGA U32Vec data; - u32 w,h,a; - R_ASSERT (Surface_Load(src_name,data,w,h,a)); - CImage* I = xr_new(); - I->Create (w,h,data.begin()); - I->Vflip (); - I->SaveTGA (dest_name); - xr_delete (I); + u32 w, h, a; + R_ASSERT(Surface_Load(src_name, data, w, h, a)); + CImage *I = xr_new(); + I->Create(w, h, data.begin()); + I->Vflip(); + I->SaveTGA(dest_name); + xr_delete(I); } - FS.set_file_age (dest_name, FS.get_file_age(src_name)); - EFS.MarkFile (src_name,true); + FS.set_file_age(dest_name, FS.get_file_age(src_name)); + EFS.MarkFile(src_name, true); } -} +} + //------------------------------------------------------------------------------ // возвращает список не синхронизированных (модифицированных) текстур // source_list - содержит список текстур с расширениями // sync_list - реально сохраненные файлы (после использования освободить) //------------------------------------------------------------------------------ -void CImageManager::SynchronizeTextures(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet* source_list, AStringVec* sync_list, FS_FileSet* modif_map, bool bForceBaseAge) -{ +void CImageManager::SynchronizeTextures(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet *source_list, AStringVec *sync_list, FS_FileSet *modif_map, bool bForceBaseAge) +{ FS_FileSet M_BASE; FS_FileSet M_THUM; FS_FileSet M_GAME; - if (source_list) M_BASE = *source_list; - else FS.file_list(M_BASE,_textures_,FS_ListFiles|FS_ClampExt,"*.tga"); - if (M_BASE.empty()) return; - if (sync_thm) FS.file_list(M_THUM,_textures_,FS_ListFiles|FS_ClampExt,"*.thm"); - if (sync_game) FS.file_list(M_GAME,_game_textures_,FS_ListFiles|FS_ClampExt,"*.dds"); + if (source_list) + M_BASE = *source_list; + else + FS.file_list(M_BASE, _textures_, FS_ListFiles|FS_ClampExt, "*.tga"); + if (M_BASE.empty()) + return; + if (sync_thm) + FS.file_list(M_THUM, _textures_, FS_ListFiles|FS_ClampExt, "*.thm"); + if (sync_game) + FS.file_list(M_GAME, _game_textures_, FS_ListFiles|FS_ClampExt, "*.dds"); + + bool bProgress = M_BASE.size()>1; - bool bProgress = M_BASE.size()>1; - // lock rescanning - int m_age = time(NULL); + int m_age = time(NULL); // sync assoc - SPBItem* pb=0; - if (bProgress) pb = UI->ProgressStart(M_BASE.size(),"Synchronize textures..."); - FS_FileSetIt it=M_BASE.begin(); - FS_FileSetIt _E = M_BASE.end(); - for (; it!=_E; it++){ - U32Vec data; - u32 w, h, a; - - xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); - string_path fn; - FS.update_path (fn,_textures_,EFS.ChangeFileExt(base_name,".tga").c_str()); - if (!FS.exist(fn)) continue; - - FS_FileSetIt th = M_THUM.find(base_name); - bool bThm = ((th==M_THUM.end()) || ((th!=M_THUM.end())&&(th->time_write!=it->time_write))); - FS_FileSetIt gm = M_GAME.find(base_name); - bool bGame= bThm || ((gm==M_GAME.end()) || ((gm!=M_GAME.end())&&(gm->time_write!=it->time_write))); - - ETextureThumbnail* THM=0; - - BOOL bUpdated = FALSE; - BOOL bFailed = FALSE; - // check thumbnail - if (sync_thm&&bThm){ - THM = xr_new(it->name.c_str()); - bool bRes = Surface_Load(fn,data,w,h,a); R_ASSERT(bRes); -//. MakeThumbnailImage(THM,data.begin(),w,h,a); - THM->Save (it->time_write); + SPBItem*pb = 0; + if (bProgress) + pb = UI->ProgressStart(M_BASE.size(), "Synchronize textures..."); + FS_FileSetIt it = M_BASE.begin(); + FS_FileSetIt _E = M_BASE.end(); + for (; it!=_E; it++) + { + U32Vec data; + u32 w, h, a; + + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + string_path fn; + FS.update_path(fn, _textures_, EFS.ChangeFileExt(base_name, ".tga").c_str()); + if (!FS.exist(fn)) + continue; + + FS_FileSetIt th = M_THUM.find(base_name); + bool bThm = ((th==M_THUM.end())||((th!=M_THUM.end())&&(th->time_write!=it->time_write))); + FS_FileSetIt gm = M_GAME.find(base_name); + bool bGame = bThm||((gm==M_GAME.end())||((gm!=M_GAME.end())&&(gm->time_write!=it->time_write))); + + ETextureThumbnail *THM = 0; + + BOOL bUpdated = FALSE; + BOOL bFailed = FALSE; + // check thumbnail + if (sync_thm&&bThm) + { + THM = xr_new(it->name.c_str()); + bool bRes = Surface_Load(fn, data, w, h, a); + R_ASSERT(bRes); + //. MakeThumbnailImage(THM,data.begin(),w,h,a); + THM->Save(it->time_write); bUpdated = TRUE; } // check game textures - if (bForceGame||(sync_game&&bGame)){ - if (!THM) THM = xr_new(it->name.c_str()); + if (bForceGame||(sync_game&&bGame)) + { + if (!THM) + THM = xr_new(it->name.c_str()); R_ASSERT(THM); - if (data.empty()){ bool bRes = Surface_Load(fn,data,w,h,a); R_ASSERT(bRes);} - if (IsValidSize(w,h)){ - string_path game_name; - strconcat (sizeof(game_name), game_name, base_name.c_str(), ".dds"); + if (data.empty()) + { + bool bRes = Surface_Load(fn, data, w, h, a); + R_ASSERT(bRes); + } + if (IsValidSize(w, h)) + { + string_path game_name; + strconcat(sizeof(game_name), game_name, base_name.c_str(), ".dds"); - FS.update_path (game_name,_game_textures_,game_name); - if (MakeGameTexture(THM,game_name,data.begin())) + FS.update_path(game_name, _game_textures_, game_name); + if (MakeGameTexture(THM, game_name, data.begin())) { - if (sync_list) sync_list->push_back(base_name.c_str()); - if (modif_map) modif_map->insert(*it); - }else{ - bFailed = TRUE; + if (sync_list) + sync_list->push_back(base_name.c_str()); + if (modif_map) + modif_map->insert(*it); } - bUpdated = TRUE; - }else{ - ELog.DlgMsg(mtError,"Can't make game texture '%s'.\nInvalid size (%dx%d).",base_name.c_str(),w,h); + else + { + bFailed = TRUE; + } + bUpdated = TRUE; } - } - if (THM) xr_delete(THM); - if (UI->NeedAbort()) break; - - if (bProgress) - pb->Inc(bUpdated?xr_string(base_name+(bFailed?" - FAILED":" - UPDATED.")).c_str():base_name.c_str(),bUpdated); - - if (bUpdated){ - string_path tga_fn,thm_fn,dds_fn; - FS.update_path (tga_fn,_textures_, EFS.ChangeFileExt(base_name,".tga").c_str()); - FS.update_path (thm_fn,_game_textures_, EFS.ChangeFileExt(base_name,".thm").c_str()); - FS.update_path (dds_fn,_game_textures_, EFS.ChangeFileExt(base_name,".dds").c_str()); - if (bForceBaseAge){ - int age = it->time_write; - FS.set_file_age (tga_fn,age); - FS.set_file_age (thm_fn,age); - FS.set_file_age (dds_fn,age); - }else{ - FS.set_file_age (tga_fn,m_age); - FS.set_file_age (thm_fn,m_age); - FS.set_file_age (dds_fn,m_age); + else + { + ELog.DlgMsg(mtError, "Can't make game texture '%s'.\nInvalid size (%dx%d).", base_name.c_str(), w, h); + } + } + if (THM) + xr_delete(THM); + if (UI->NeedAbort()) + break; + + if (bProgress) + pb->Inc(bUpdated ? xr_string(base_name+(bFailed ? " - FAILED" : " - UPDATED.")).c_str() : base_name.c_str(), bUpdated); + + if (bUpdated) + { + string_path tga_fn, thm_fn, dds_fn; + FS.update_path(tga_fn, _textures_, EFS.ChangeFileExt(base_name, ".tga").c_str()); + FS.update_path(thm_fn, _game_textures_, EFS.ChangeFileExt(base_name, ".thm").c_str()); + FS.update_path(dds_fn, _game_textures_, EFS.ChangeFileExt(base_name, ".dds").c_str()); + if (bForceBaseAge) + { + int age = it->time_write; + FS.set_file_age(tga_fn, age); + FS.set_file_age(thm_fn, age); + FS.set_file_age(dds_fn, age); + } + else + { + FS.set_file_age(tga_fn, m_age); + FS.set_file_age(thm_fn, m_age); + FS.set_file_age(dds_fn, m_age); } } } - if (bProgress) UI->ProgressEnd(pb); + if (bProgress) + UI->ProgressEnd(pb); } + /* void CImageManager::ChangeFileAgeTo(FS_FileSet* tgt_map, int age) { - VERIFY(tgt_map); - FS_FileSet* M_BASE = tgt_map; + VERIFY(tgt_map); + FS_FileSet* M_BASE = tgt_map; // lock rescanning FS.lock_rescan (); // change - SPBItem* pb=0; + SPBItem* pb=0; if (M_BASE->size()>1) pb = UI->ProgressStart(M_BASE->size(),"Change textures age..."); FS_FileSetIt it = M_BASE->begin(); - FS_FileSetIt _E = M_BASE->end(); - for (; it!=_E; it++){ + FS_FileSetIt _E = M_BASE->end(); + for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); xr_string tga_fn,thm_fn,dds_fn; FS.update_path (tga_fn,_textures_, EFS.ChangeFileExt(base_name,".tga").c_str()); @@ -404,164 +479,188 @@ void CImageManager::ChangeFileAgeTo(FS_FileSet* tgt_map, int age) FS.unlock_rescan (); } */ -void CImageManager::WriteAssociation(CInifile* ltx_ini, LPCSTR base_name, const STextureParams& fmt) +void CImageManager::WriteAssociation(CInifile *ltx_ini, LPCSTR base_name, const STextureParams &fmt) { - ltx_ini->w_u32 ("types", base_name,fmt.type); + ltx_ini->w_u32("types", base_name, fmt.type); } void CImageManager::SynchronizeTexture(LPCSTR tex_name, int age) { AStringVec modif; FS_FileSet t_map; - FS_File F(tex_name); F.time_write = age; - t_map.insert (F); - SynchronizeTextures (true,true,true,&t_map,&modif,0,age); - RefreshTextures (&modif); + FS_File F(tex_name); + F.time_write = age; + t_map.insert(F); + SynchronizeTextures(true, true, true, &t_map, &modif, 0, age); + RefreshTextures(&modif); } + //------------------------------------------------------------------------------ // возвращает список всех текстур //------------------------------------------------------------------------------ -int CImageManager::GetTextures(FS_FileSet& files, BOOL bFolders) -{ - return FS.file_list(files,_game_textures_,(bFolders?FS_ListFolders:0)|FS_ListFiles|FS_ClampExt,"*.dds"); +int CImageManager::GetTextures(FS_FileSet &files, BOOL bFolders) +{ + return FS.file_list(files, _game_textures_, (bFolders ? FS_ListFolders : 0)|FS_ListFiles|FS_ClampExt, "*.dds"); } -int CImageManager::GetTexturesRaw(FS_FileSet& files, BOOL bFolders) +int CImageManager::GetTexturesRaw(FS_FileSet &files, BOOL bFolders) { - return FS.file_list(files,_textures_,(bFolders?FS_ListFolders:0)|FS_ListFiles|FS_ClampExt,"*.tga"); + return FS.file_list(files, _textures_, (bFolders ? FS_ListFolders : 0)|FS_ListFiles|FS_ClampExt, "*.tga"); } + //------------------------------------------------------------------------------ // возвращает список текстур, которые нужно обновить //------------------------------------------------------------------------------ -int CImageManager::GetLocalNewTextures(FS_FileSet& files) +int CImageManager::GetLocalNewTextures(FS_FileSet &files) { - return FS.file_list(files,_import_,FS_ListFiles|FS_RootOnly,"*.tga,*.bmp"); + return FS.file_list(files, _import_, FS_ListFiles|FS_RootOnly, "*.tga,*.bmp"); } + //------------------------------------------------------------------------------ // проверяет соответствие размера текстур // input: список файлов для тестирования // output: соответствие //------------------------------------------------------------------------------ #define SQR(a) ((a)*(a)) -BOOL CImageManager::CheckCompliance(LPCSTR fname, int& compl) + +BOOL CImageManager::CheckCompliance(LPCSTR fname, int &compl) { - compl = 0; + compl = 0; U32Vec data; u32 w, h, a; - if (!Surface_Load(fname,data,w,h,a)) return FALSE; - if ((1==w) || (1==h)) return TRUE; + if (!Surface_Load(fname, data, w, h, a)) + return FALSE; + if ((1==w)||(1==h)) + return TRUE; - u32 w_2 = (1==w)?w:w/2; - u32 h_2 = (1==h)?h:h/2; + u32 w_2 = (1==w) ? w : w/2; + u32 h_2 = (1==h) ? h : h/2; // scale down(lanczos3) and up (bilinear, as video board) - u32* pScaled = (u32*)(xr_malloc((w_2)*(h_2)*4)); - u32* pRestored = (u32*)(xr_malloc(w*h*4)); - try { - imf_Process (pScaled, w_2,h_2,data.begin(),w,h,imf_lanczos3 ); - imf_Process (pRestored, w,h,pScaled,w_2,h_2,imf_filter ); + u32 *pScaled = (u32*)(xr_malloc((w_2)*(h_2)*4)); + u32 *pRestored = (u32*)(xr_malloc(w*h*4)); + try + { + imf_Process(pScaled, w_2, h_2, data.begin(), w, h, imf_lanczos3); + imf_Process(pRestored, w, h, pScaled, w_2, h_2, imf_filter); } catch (...) { - Msg ("* ERROR: imf_Process"); - xr_free (pScaled); - xr_free (pRestored); - return FALSE; + Msg("* ERROR: imf_Process"); + xr_free(pScaled); + xr_free(pRestored); + return FALSE; } // Analyze - float difference = 0; - float maximal = 0; - for (u32 p=0; pProgressStart(files.size(),"Check texture compliance: "); - FS_FileSetIt it = files.begin(); - FS_FileSetIt _E = files.end(); - for (; it!=_E; it++){ - int val = 0; - string_path fname; - FS.update_path (fname,_textures_,it->name.c_str()); - if (!CheckCompliance(fname,val)) - ELog.Msg(mtError,"Bad texture: '%s'",it->name.c_str()); - FS_File F(*it); F.attrib = val; - compl.insert (F); - pb->Inc (); - if (UI->NeedAbort()) break; + SPBItem*pb = UI->ProgressStart(files.size(), "Check texture compliance: "); + FS_FileSetIt it = files.begin(); + FS_FileSetIt _E = files.end(); + for (; it!=_E; it++) + { + int val = 0; + string_path fname; + FS.update_path(fname, _textures_, it->name.c_str()); + if (!CheckCompliance(fname, val)) + ELog.Msg(mtError, "Bad texture: '%s'", it->name.c_str()); + FS_File F(*it); + F.attrib = val; + compl.insert(F); + pb->Inc(); + if (UI->NeedAbort()) + break; } - UI->ProgressEnd(pb); + UI->ProgressEnd(pb); } -IC void GET(U32Vec& pixels, u32 w, u32 h, u32 x, u32 y, u32 ref, u32 &count, u32 &r, u32 &g, u32 &b) +IC + +void GET(U32Vec &pixels, u32 w, u32 h, u32 x, u32 y, u32 ref, u32 &count, u32 &r, u32 &g, u32 &b) { // wrap pixels - if (x>=w) return; - if (y>=h) return; + if (x>=w) + return; + if (y>=h) + return; // summarize - u32 pixel = pixels[y*w + x]; - if (color_get_A(pixel)<=ref) return; + u32 pixel = pixels[y*w+x]; + if (color_get_A(pixel)<=ref) + return; - r+=color_get_R (pixel); - g+=color_get_G (pixel); - b+=color_get_B (pixel); + r += color_get_R(pixel); + g += color_get_G(pixel); + b += color_get_B(pixel); count++; } -BOOL _ApplyBorders(U32Vec& pixels, u32 w, u32 h, u32 ref) +BOOL _ApplyBorders(U32Vec &pixels, u32 w, u32 h, u32 ref) { - BOOL bNeedContinue = FALSE; + BOOL bNeedContinue = FALSE; - try { + try + { U32Vec result; result.resize(w*h); - CopyMemory(result.begin(),pixels.begin(),w*h*4); - for (u32 y=0; y200)?subst_alpha(*it,0xFF):subst_alpha(*it,0x00); - for (u32 ref=254; ref>0; ref--) - _ApplyBorders(tgt_data,w,h,ref); - for (int t=0; t200) ? subst_alpha(*it, 0xFF) : subst_alpha(*it, 0x00); + for (u32 ref = 254; ref>0; ref--) + _ApplyBorders(tgt_data, w, h, ref); + for (int t = 0; tGetFaceCount(),obj->GetVertexCount()); + psDeviceFlags.set(rsStatistic|rsDrawGrid, FALSE); + // u32 cc = EPrefs.scene_clear_color; + // EPrefs.scene_clear_color = 0x00333333; + + U32Vec pixels; + u32 w = 512, h = 512; + if (EDevice.MakeScreenshot(pixels, w, h)) + { + EObjectThumbnail tex(tex_name, false); + tex.CreateFromData(pixels.begin(), w, h, obj->GetFaceCount(), obj->GetVertexCount()); tex.Save(age); - }else{ - bResult = FALSE; - ELog.DlgMsg(mtError,"Can't make screenshot."); + } + else + { + bResult = FALSE; + ELog.DlgMsg(mtError, "Can't make screenshot."); } // restore render params - psDeviceFlags = old_flag; -// EPrefs.scene_clear_color = cc; + psDeviceFlags = old_flag; + // EPrefs.scene_clear_color = cc; return bResult; } -void CImageManager::RemoveTexture(LPCSTR fname, EItemType type, bool& res) +void CImageManager::RemoveTexture(LPCSTR fname, EItemType type, bool &res) { - if (TYPE_FOLDER==type){ - FS.dir_delete (_textures_,fname,FALSE); - FS.dir_delete (_game_textures_,fname,FALSE); - res = true; + if (TYPE_FOLDER==type) + { + FS.dir_delete(_textures_, fname, FALSE); + FS.dir_delete(_game_textures_, fname, FALSE); + res = true; return; - }else if (TYPE_OBJECT==type) + } + else if (TYPE_OBJECT==type) { xr_string src_name; - src_name = EFS.ChangeFileExt(fname,".tga"); - if (FS.exist(_textures_,src_name.c_str())) + src_name = EFS.ChangeFileExt(fname, ".tga"); + if (FS.exist(_textures_, src_name.c_str())) { - xr_string base_name= EFS.ChangeFileExt(fname,""); - xr_string thm_name = EFS.ChangeFileExt(fname,".thm"); - xr_string game_name= EFS.ChangeFileExt(fname,".dds"); - xr_string game_name2=EFS.ChangeFileExt(fname,"#.dds"); + xr_string base_name = EFS.ChangeFileExt(fname, ""); + xr_string thm_name = EFS.ChangeFileExt(fname, ".thm"); + xr_string game_name = EFS.ChangeFileExt(fname, ".dds"); + xr_string game_name2 = EFS.ChangeFileExt(fname, "#.dds"); // source - FS.file_delete (_textures_,src_name.c_str()); + FS.file_delete(_textures_, src_name.c_str()); // thumbnail - FS.file_delete (_textures_,thm_name.c_str()); + FS.file_delete(_textures_, thm_name.c_str()); // game - FS.file_delete (_game_textures_,game_name.c_str()); + FS.file_delete(_game_textures_, game_name.c_str()); // game 2 - FS.file_delete (_game_textures_,game_name2.c_str()); + FS.file_delete(_game_textures_, game_name2.c_str()); return; } } - res = false; + res = false; } -EImageThumbnail* CImageManager::CreateThumbnail(LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad) +EImageThumbnail *CImageManager::CreateThumbnail(LPCSTR src_name, ECustomThumbnail::THMType type, bool bLoad) { - switch (type){ - case ECustomThumbnail::ETObject: return xr_new (src_name,bLoad); - case ECustomThumbnail::ETTexture: return xr_new(src_name,bLoad); - default: NODEFAULT; + switch (type) + { + case ECustomThumbnail::ETObject: return xr_new(src_name, bLoad); + case ECustomThumbnail::ETTexture: return xr_new(src_name, bLoad); + default: NODEFAULT; } return 0; } @@ -652,68 +757,79 @@ EImageThumbnail* CImageManager::CreateThumbnail(LPCSTR src_name, ECustomThumbnai // если передан параметр modif - обновляем DX-Surface only и только из списка // иначе полная синхронизация //------------------------------------------------------------------------------ -void CImageManager::RefreshTextures(AStringVec* modif) +void CImageManager::RefreshTextures(AStringVec *modif) { - if (FS.can_write_to_alias(_textures_)){ - if (modif) EDevice.Resources->ED_UpdateTextures(modif); - else{ + if (FS.can_write_to_alias(_textures_)) + { + if (modif) + EDevice.Resources->ED_UpdateTextures(modif); + else + { UI->SetStatus("Refresh textures..."); AStringVec modif_files; - ImageLib.SynchronizeTextures(true,true,false,0,&modif_files); + ImageLib.SynchronizeTextures(true, true, false, 0, &modif_files); EDevice.Resources->ED_UpdateTextures(&modif_files); UI->SetStatus(""); } - }else{ + } + else + { Log("#!You don't have permisions to modify textures."); } } -void __stdcall pb_callback(void* data, float& v) +void __stdcall pb_callback(void *data, float &v) { - SPBItem* PB = (SPBItem*)(data); - PB->Update(v); + SPBItem*PB = (SPBItem*)(data); + PB->Update(v); } -#include "ETools.h" +#include "utils/ETools/ETools.h" + BOOL CImageManager::CreateSmallerCubeMap(LPCSTR src_name, LPCSTR dst_name) { U32Vec data; u32 w, wf, h, a; - string_path full_name; - FS.update_path (full_name,_textures_,src_name); - strcat (full_name,".tga"); - - if (Surface_Load(full_name,data,wf,h,a)){ - w = wf/6; - u32 sm_w=32, sm_wf=6*sm_w, sm_h=32; - if (!btwIsPow2(h)||(h*6!=wf)||(wfProgressStart(1.f,"Cube Map: scale image..."); - CTimer T; T.Start(); - ETOOLS::SimplifyCubeMap (data.begin(),w,h,sm_data.begin(),sm_w,sm_h,16.f,pb_callback,PB); - float tm_scm = T.GetElapsed_sec(); - UI->ProgressEnd (PB); + U32Vec sm_data(sm_wf*sm_h, 0); + SPBItem*PB = UI->ProgressStart(1.f, "Cube Map: scale image..."); + CTimer T; + T.Start(); + ETOOLS::SimplifyCubeMap(data.begin(), w, h, sm_data.begin(), sm_w, sm_h, 16.f, pb_callback, PB); + float tm_scm = T.GetElapsed_sec(); + UI->ProgressEnd(PB); // write texture string_path out_name; - FS.update_path (out_name,_game_textures_,dst_name); + FS.update_path(out_name, _game_textures_, dst_name); strcat(out_name, ".dds"); - STextureParams tp; - tp.width = sm_wf; - tp.height = sm_h; - tp.fmt = STextureParams::tfRGBA; - tp.type = STextureParams::ttCubeMap; - tp.flags.zero (); - if (!MakeGameTexture(out_name,&*sm_data.begin(),tp)) - return FALSE; - ELog.DlgMsg(mtInformation,"Smaller cubemap successfylly created [%3.2f sec].",tm_scm); + STextureParams tp; + tp.width = sm_wf; + tp.height = sm_h; + tp.fmt = STextureParams::tfRGBA; + tp.type = STextureParams::ttCubeMap; + tp.flags.zero(); + if (!MakeGameTexture(out_name, &*sm_data.begin(), tp)) + return FALSE; + ELog.DlgMsg(mtInformation, "Smaller cubemap successfylly created [%3.2f sec].", tm_scm); return TRUE; - }else{ - ELog.Msg(mtError,"Can't load texture '%s'.",src_name); + } + else + { + ELog.Msg(mtError, "Can't load texture '%s'.", src_name); } return FALSE; } diff --git a/src/editors/ECore/Editor/ImageManager.h b/src/editors/ECore/Editor/ImageManager.h index f4ddee2118d..25b54f2584c 100644 --- a/src/editors/ECore/Editor/ImageManager.h +++ b/src/editors/ECore/Editor/ImageManager.h @@ -2,72 +2,95 @@ #ifndef ImageManagerH #define ImageManagerH -#include "../xrEProps/folderlib.h" -#include "../Layers/xrRender/etextureparams.h" -#include "../ECore/Editor/EThumbnail.h" +#include "editors/xrEProps/FolderLib.h" +#include "Layers/xrRender/ETextureParams.h" +#include "editors/ECore/Editor/EThumbnail.h" class CEditableObject; -struct SSimpleImage{ - shared_str name; - DEFINE_VECTOR(U32Vec,DATAVec,DATAIt); - DATAVec layers; - u32 w,h,a; - u32 tag; - int LongestEdge()const {return (w>h)?w:h;} - int Area()const {return w*h;} +struct SSimpleImage +{ + shared_str name; + DEFINE_VECTOR(U32Vec, DATAVec, DATAIt); + DATAVec layers; + u32 w, h, a; + u32 tag; + + int LongestEdge() const + { + return (w>h) ? w : h; + } + + int Area() const + { + return w*h; + } }; -IC bool operator == (const SSimpleImage& a, shared_str nm){return a.name==nm;} -IC bool operator < (const SSimpleImage& a, const SSimpleImage& b){return a.name=(ss_x+px)); R_ASSERT(ds_y>=(ss_y+py)); - for (u32 y=0; y=(ss_y+px)); R_ASSERT(ds_y>=(ss_x+py)); - for (u32 y=0; y=dest_width) return false; - if (R.rb.y>=dest_height) return false; + if (R.rb.x>=dest_width) + return false; + if (R.rb.y>=dest_height) + return false; // Normal (and fastest way) - for (u32 y=0; yitem1.Area())||(item0.LongestEdge()>item1.LongestEdge()));} -extern bool Surface_Load(LPCSTR full_name, U32Vec& data, u32& w, u32& h, u32& a); - -int CImageManager::CreateMergedTexture(u32 layer_cnt, SSimpleImageVec& src_images, SSimpleImage& dst_image, int dest_width, int dest_height, Fvector2Vec& dest_offset, Fvector2Vec& dest_scale, boolVec& dest_rotate, U32Vec& dest_remap) +bool item_area_sort_pred(const SSimpleImage &item0, const SSimpleImage &item1) { - if (src_images.empty()) return -1; + return ((item0.Area()>item1.Area())||(item0.LongestEdge()>item1.LongestEdge())); +} - dest_offset.clear (); - dest_scale.clear (); - dest_rotate.clear (); - dest_remap.resize (src_images.size()); +extern bool Surface_Load(LPCSTR full_name, U32Vec &data, u32 &w, u32 &h, u32 &a); - SSimpleImage::DATAVec dest_layers(layer_cnt); - for (SSimpleImage::DATAIt layer_it=dest_layers.begin(); layer_it!=dest_layers.end(); layer_it++) - layer_it->resize(dest_width*dest_height,0); - U8Vec dest_mask (dest_width*dest_height,0); +int CImageManager::CreateMergedTexture(u32 layer_cnt, SSimpleImageVec &src_images, SSimpleImage &dst_image, int dest_width, int dest_height, Fvector2Vec &dest_offset, Fvector2Vec &dest_scale, boolVec &dest_rotate, U32Vec &dest_remap) +{ + if (src_images.empty()) + return -1; - int max_area = dest_width*dest_height; - int calc_area = 0; + dest_offset.clear(); + dest_scale.clear(); + dest_rotate.clear(); + dest_remap.resize(src_images.size()); - for (SSimpleImageVecIt s_it=src_images.begin(); s_it!=src_images.end(); s_it++){ - s_it->tag = s_it-src_images.begin(); - calc_area += (s_it->w*s_it->h); - if (calc_area>max_area) return 0; + SSimpleImage::DATAVec dest_layers(layer_cnt); + for (SSimpleImage::DATAIt layer_it = dest_layers.begin(); layer_it!=dest_layers.end(); layer_it++) + layer_it->resize(dest_width*dest_height, 0); + U8Vec dest_mask(dest_width*dest_height, 0); + + int max_area = dest_width*dest_height; + int calc_area = 0; + + for (SSimpleImageVecIt s_it = src_images.begin(); s_it!=src_images.end(); s_it++) + { + s_it->tag = s_it-src_images.begin(); + calc_area += (s_it->w*s_it->h); + if (calc_area>max_area) + return 0; } - std::sort (src_images.begin(),src_images.end(),item_area_sort_pred); + std::sort(src_images.begin(), src_images.end(), item_area_sort_pred); - for (s_it=src_images.begin(); s_it!=src_images.end(); s_it++) - dest_remap[s_it->tag] = s_it-src_images.begin(); + for (s_it = src_images.begin(); s_it!=src_images.end(); s_it++) + dest_remap[s_it->tag] = s_it-src_images.begin(); - for (s_it = src_images.begin(); s_it!=src_images.end(); s_it++){ - Irect R; R.set(0,0, s_it->w-1,s_it->h-1); + for (s_it = src_images.begin(); s_it!=src_images.end(); s_it++) + { + Irect R; + R.set(0, 0, s_it->w-1, s_it->h-1); BOOL bRotated; - if (!_rect_place(dest_mask,dest_width,dest_height,R,bRotated)) return 0; - Fvector2 offs,scale; - offs.x = float(R.lt.x)/float(dest_width); - offs.y = float(R.lt.y)/float(dest_height); - scale.x = float(R.width()+1)/float(dest_width); - scale.y = float(R.height()+1)/float(dest_height); - dest_offset.push_back (offs); - dest_scale.push_back (scale); - dest_rotate.push_back (bRotated); + if (!_rect_place(dest_mask, dest_width, dest_height, R, bRotated)) + return 0; + Fvector2 offs, scale; + offs.x = float(R.lt.x)/float(dest_width); + offs.y = float(R.lt.y)/float(dest_height); + scale.x = float(R.width()+1)/float(dest_width); + scale.y = float(R.height()+1)/float(dest_height); + dest_offset.push_back(offs); + dest_scale.push_back(scale); + dest_rotate.push_back(bRotated); // Perform BLIT - VERIFY (s_it->layers.size()==layer_cnt); - for (u32 k=0; klayers[k].begin(),s_it->w,s_it->h,R.lt.x,R.lt.y); - else blit_r (dest_layers[k].begin(),dest_width,dest_height,s_it->layers[k].begin(),s_it->w,s_it->h,R.lt.x,R.lt.y); + VERIFY(s_it->layers.size()==layer_cnt); + for (u32 k = 0; klayers[k].begin(), s_it->w, s_it->h, R.lt.x, R.lt.y); + else + blit_r(dest_layers[k].begin(), dest_width, dest_height, s_it->layers[k].begin(), s_it->w, s_it->h, R.lt.x, R.lt.y); } } - dst_image.w = dest_width; - dst_image.h = dest_height; - dst_image.a = TRUE; - dst_image.layers = dest_layers; + dst_image.w = dest_width; + dst_image.h = dest_height; + dst_image.a = TRUE; + dst_image.layers = dest_layers; return 1; } -int CImageManager::CreateMergedTexture (u32 layer_cnt, SSimpleImageVec& src_images, SSimpleImage& dst_image, int dest_width_min, int dest_width_max, int dest_height_min, int dest_height_max, Fvector2Vec& dest_offset, Fvector2Vec& dest_scale, boolVec& dest_rotate, U32Vec& dest_remap) +int CImageManager::CreateMergedTexture(u32 layer_cnt, SSimpleImageVec &src_images, SSimpleImage &dst_image, int dest_width_min, int dest_width_max, int dest_height_min, int dest_height_max, Fvector2Vec &dest_offset, Fvector2Vec &dest_scale, boolVec &dest_rotate, U32Vec &dest_remap) { - int res = 0; - int w = dest_width_min; - int h = dest_height_min; - do{ - res = ImageLib.CreateMergedTexture(layer_cnt, src_images,dst_image,w,h,dest_offset,dest_scale,dest_rotate,dest_remap); - if (0==res){ - if ((w<=h)&&(wlayers.resize(1); - string_path t_name; -//. FS.update_path (t_name,_textures_,**n_it); - FS.update_path (t_name,_game_textures_,**n_it); - if (!Surface_Load(EFS.ChangeFileExt(t_name,".dds"/*".tga"*/).c_str(),s_it->layers.back(),s_it->w,s_it->h,s_it->a)){ - ELog.DlgMsg (mtError,"Can't load texture '%s'. Check file existence.",**n_it); + if (_names.empty()) + return -1; + + dest_offset.clear(); + dest_scale.clear(); + dest_rotate.clear(); + + RStringVec src_names = _names; + dest_remap.resize(src_names.size()); + std::sort(src_names.begin(), src_names.end()); + src_names.erase(std::unique(src_names.begin(), src_names.end()), src_names.end()); + + U32Vec dest_pixels(dest_width*dest_height, 0); + U8Vec dest_mask(dest_width*dest_height, 0); + + int max_area = dest_width*dest_height; + int calc_area = 0; + + SSimpleImageVec src_items(src_names.size()); + SSimpleImageVecIt s_it = src_items.begin(); + for (RStringVecIt n_it = src_names.begin(); n_it!=src_names.end(); n_it++,s_it++) + { + s_it->layers.resize(1); + string_path t_name; + //. FS.update_path (t_name,_textures_,**n_it); + FS.update_path(t_name, _game_textures_, **n_it); + if (!Surface_Load(EFS.ChangeFileExt(t_name, ".dds"/*".tga"*/).c_str(), s_it->layers.back(), s_it->w, s_it->h, s_it->a)) + { + ELog.DlgMsg(mtError, "Can't load texture '%s'. Check file existence.", **n_it); return -1; } - calc_area += (s_it->w*s_it->h); - if (calc_area>max_area) - return 0; - s_it->name = *n_it; + calc_area += (s_it->w*s_it->h); + if (calc_area>max_area) + return 0; + s_it->name = *n_it; } - std::sort (src_items.begin(),src_items.end(),item_area_sort_pred); + std::sort(src_items.begin(), src_items.end(), item_area_sort_pred); - for (u32 k=0; k<_names.size(); k++){ - shared_str nm = _names[k]; - s_it = std::find(src_items.begin(),src_items.end(),nm); VERIFY(s_it!=src_items.end()); - dest_remap[k] = s_it-src_items.begin(); + for (u32 k = 0; k<_names.size(); k++) + { + shared_str nm = _names[k]; + s_it = std::find(src_items.begin(), src_items.end(), nm); + VERIFY(s_it!=src_items.end()); + dest_remap[k] = s_it-src_items.begin(); } - - for (s_it = src_items.begin(); s_it!=src_items.end(); s_it++){ - Irect R; R.set(0,0, s_it->w-1,s_it->h-1); + + for (s_it = src_items.begin(); s_it!=src_items.end(); s_it++) + { + Irect R; + R.set(0, 0, s_it->w-1, s_it->h-1); BOOL bRotated; - if (!_rect_place(dest_mask,dest_width,dest_height,R,bRotated)) return 0; - Fvector2 offs,scale; - offs.x = float(R.lt.x)/float(dest_width); - offs.y = float(R.lt.y)/float(dest_height); - scale.x = float(R.width()+1)/float(dest_width); - scale.y = float(R.height()+1)/float(dest_height); - dest_offset.push_back (offs); - dest_scale.push_back (scale); - dest_rotate.push_back (bRotated); + if (!_rect_place(dest_mask, dest_width, dest_height, R, bRotated)) + return 0; + Fvector2 offs, scale; + offs.x = float(R.lt.x)/float(dest_width); + offs.y = float(R.lt.y)/float(dest_height); + scale.x = float(R.width()+1)/float(dest_width); + scale.y = float(R.height()+1)/float(dest_height); + dest_offset.push_back(offs); + dest_scale.push_back(scale); + dest_rotate.push_back(bRotated); // Perform BLIT - if (!bRotated) blit (dest_pixels.begin(),dest_width,dest_height,s_it->layers.back().begin(),s_it->w,s_it->h,R.lt.x,R.lt.y); - else blit_r (dest_pixels.begin(),dest_width,dest_height,s_it->layers.back().begin(),s_it->w,s_it->h,R.lt.x,R.lt.y); + if (!bRotated) + blit(dest_pixels.begin(), dest_width, dest_height, s_it->layers.back().begin(), s_it->w, s_it->h, R.lt.x, R.lt.y); + else + blit_r(dest_pixels.begin(), dest_width, dest_height, s_it->layers.back().begin(), s_it->w, s_it->h, R.lt.x, R.lt.y); } // all right. make texture. - AnsiString fn = ChangeFileExt (dest_name,".dds"); - STextureParams tp; - tp.width = dest_width; - tp.height = dest_height; - tp.fmt = fmt; - tp.type = STextureParams::ttImage; - tp.mip_filter = STextureParams::kMIPFilterAdvanced; - tp.flags.assign (STextureParams::flDitherColor|STextureParams::flGenerateMipMaps); - MakeGameTexture (fn.c_str(),dest_pixels.begin(),tp); + AnsiString fn = ChangeFileExt(dest_name, ".dds"); + STextureParams tp; + tp.width = dest_width; + tp.height = dest_height; + tp.fmt = fmt; + tp.type = STextureParams::ttImage; + tp.mip_filter = STextureParams::kMIPFilterAdvanced; + tp.flags.assign(STextureParams::flDitherColor|STextureParams::flGenerateMipMaps); + MakeGameTexture(fn.c_str(), dest_pixels.begin(), tp); return 1; } -int CImageManager::CreateMergedTexture (const RStringVec& src_names, LPCSTR dest_name, STextureParams::ETFormat fmt, int dest_width_min, int dest_width_max, int dest_height_min, int dest_height_max, Fvector2Vec& dest_offset, Fvector2Vec& dest_scale, boolVec& dest_rotate, U32Vec& remap) +int CImageManager::CreateMergedTexture(const RStringVec &src_names, LPCSTR dest_name, STextureParams::ETFormat fmt, int dest_width_min, int dest_width_max, int dest_height_min, int dest_height_max, Fvector2Vec &dest_offset, Fvector2Vec &dest_scale, boolVec &dest_rotate, U32Vec &remap) { - int res = 0; - int w = dest_width_min; - int h = dest_height_min; - do{ - res = ImageLib.CreateMergedTexture(src_names,dest_name,fmt,w,h,dest_offset,dest_scale,dest_rotate,remap); - if (0==res){ - if ((w<=h)&&(wscene_clear_color; EPrefs.scene_clear_color = 0x0000000; psDeviceFlags.zero (); - psDeviceFlags.set (rsFilterLinear,TRUE); - EDevice.dwFillMode = D3DFILL_SOLID; + psDeviceFlags.set (rsFilterLinear,TRUE); + EDevice.dwFillMode = D3DFILL_SOLID; EDevice.dwShadeMode = D3DSHADE_GOURAUD; SetCamera(0,C,S.y,R,D); for (int frame=0; framee_mesh->GetSurfaceByFaceID(R->tag); VERIFY(surf); - Shader_xrLC* c_sh = EDevice.ShaderXRLC.Get(surf->_ShaderXRLCName()); - if (!c_sh->flags.bRendering) return FALSE; - const Fvector2* cuv[3]; - R->e_mesh->GetFaceTC (R->tag,cuv); + CSurface*surf = R->e_mesh->GetSurfaceByFaceID(R->tag); + VERIFY(surf); + Shader_xrLC *c_sh = EDevice.ShaderXRLC.Get(surf->_ShaderXRLCName()); + if (!c_sh->flags.bRendering) + return FALSE; + const Fvector2 *cuv[3]; + R->e_mesh->GetFaceTC(R->tag, cuv); // barycentric coords // note: W,U,V order Fvector B; - B.set (1.0f - R->u - R->v,R->u,R->v); + B.set(1.0f-R->u-R->v, R->u, R->v); // calc UV - Fvector2 uv; - uv.x = cuv[0]->x*B.x + cuv[1]->x*B.y + cuv[2]->x*B.z; - uv.y = cuv[0]->y*B.x + cuv[1]->y*B.y + cuv[2]->y*B.z; - - int U = iFloor(uv.x*float(surf->m_ImageData->w) + .5f); - int V = iFloor(uv.y*float(surf->m_ImageData->h)+ .5f); - U %= surf->m_ImageData->w; if (U<0) U+=surf->m_ImageData->w; - V %= surf->m_ImageData->h; if (V<0) V+=surf->m_ImageData->h; - -/* -// float filter_core[3][3]={{0.0125,0.0125,0.0125},{0.0125,0.9,0.0125},{0.0125,0.0125,0.0125}}; -// float filter_core[3][3]={{0.0625,0.0625,0.0625},{0.0625,0.5,0.0625},{0.0625,0.0625,0.0625}}; -// float filter_core[3][3]={{0,0,0},{0,1,0},{0,0,0}}; - Fvector4 C={0,0,0,0}; - u32 cnt=0; - for (int y=-1; y<=1; y++){ - int v = V+y; - if (v<0||v>=(int)surf->m_ImageData->h) continue; - for (int x=-1; x<=1; x++){ - int u = U+x; - if (u<0||u>=(int)surf->m_ImageData->w) continue; - Fvector4 c; - color = surf->m_ImageData->layers.back()[v*surf->m_ImageData->w+u]; - float f = filter_core[x+1][y+1]; - c.set (f*color_get_R(color),f*color_get_G(color),f*color_get_B(color),f*color_get_A(color)); - C.add (c); - cnt++; + Fvector2 uv; + uv.x = cuv[0]->x*B.x+cuv[1]->x*B.y+cuv[2]->x*B.z; + uv.y = cuv[0]->y*B.x+cuv[1]->y*B.y+cuv[2]->y*B.z; + + int U = iFloor(uv.x*float(surf->m_ImageData->w)+.5f); + int V = iFloor(uv.y*float(surf->m_ImageData->h)+.5f); + U %= surf->m_ImageData->w; + if (U<0) + U += surf->m_ImageData->w; + V %= surf->m_ImageData->h; + if (V<0) + V += surf->m_ImageData->h; + + /* + // float filter_core[3][3]={{0.0125,0.0125,0.0125},{0.0125,0.9,0.0125},{0.0125,0.0125,0.0125}}; + // float filter_core[3][3]={{0.0625,0.0625,0.0625},{0.0625,0.5,0.0625},{0.0625,0.0625,0.0625}}; + // float filter_core[3][3]={{0,0,0},{0,1,0},{0,0,0}}; + Fvector4 C={0,0,0,0}; + u32 cnt=0; + for (int y=-1; y<=1; y++){ + int v = V+y; + if (v<0||v>=(int)surf->m_ImageData->h) continue; + for (int x=-1; x<=1; x++){ + int u = U+x; + if (u<0||u>=(int)surf->m_ImageData->w) continue; + Fvector4 c; + color = surf->m_ImageData->layers.back()[v*surf->m_ImageData->w+u]; + float f = filter_core[x+1][y+1]; + c.set (f*color_get_R(color),f*color_get_G(color),f*color_get_B(color),f*color_get_A(color)); + C.add (c); + cnt++; + } } - } -// if (0!=cnt) C.div(cnt); - color = color_rgba(C.x,C.y,C.z,C.w); -*/ - color = surf->m_ImageData->layers.back()[V*surf->m_ImageData->w+U]; + // if (0!=cnt) C.div(cnt); + color = color_rgba(C.x,C.y,C.z,C.w); + */ + color = surf->m_ImageData->layers.back()[V*surf->m_ImageData->w+U]; alpha = color_get_A(color); return TRUE; } -struct SBuildLight{ - Flight light; - float energy; +struct SBuildLight +{ + Flight light; + float energy; }; -DEFINE_VECTOR (SBuildLight,BLVec,BLIt); -ICF static void simple_hemi_callback(float x, float y, float z, float E, LPVOID P) + +DEFINE_VECTOR(SBuildLight, BLVec, BLIt); +ICF static + +void simple_hemi_callback(float x, float y, float z, float E, LPVOID P) { - BLVec* dst = (BLVec*)P; - SBuildLight T; - T.energy = E; - T.light.direction.set (x,y,z); - dst->push_back (T); + BLVec *dst = (BLVec*)P; + SBuildLight T; + T.energy = E; + T.light.direction.set(x, y, z); + dst->push_back(T); } -const u32 lod_ss_quality = 8; +const u32 lod_ss_quality = 8; -void CreateLODSamples(const Fbox& bbox, U32Vec& tgt_data, u32 tgt_w, u32 tgt_h) +void CreateLODSamples(const Fbox &bbox, U32Vec &tgt_data, u32 tgt_w, u32 tgt_h) { - U32Vec s_pixels,d_pixels; - Fmatrix save_projection = EDevice.mProject; - Fmatrix save_view = EDevice.mView; + U32Vec s_pixels, d_pixels; + Fmatrix save_projection = EDevice.mProject; + Fmatrix save_view = EDevice.mView; // save render params - Flags32 old_flag = psDeviceFlags; - u32 old_dwFillMode = EDevice.dwFillMode; - u32 old_dwShadeMode = EDevice.dwShadeMode; + Flags32 old_flag = psDeviceFlags; + u32 old_dwFillMode = EDevice.dwFillMode; + u32 old_dwShadeMode = EDevice.dwShadeMode; // set render params - u32 cc = EPrefs->scene_clear_color; - EPrefs->scene_clear_color = 0x0000000; - psDeviceFlags.zero (); - psDeviceFlags.set (rsFilterLinear,TRUE); - EDevice.dwFillMode = D3DFILL_SOLID; - EDevice.dwShadeMode = D3DSHADE_GOURAUD; + u32 cc = EPrefs->scene_clear_color; + EPrefs->scene_clear_color = 0x0000000; + psDeviceFlags.zero(); + psDeviceFlags.set(rsFilterLinear, TRUE); + EDevice.dwFillMode = D3DFILL_SOLID; + EDevice.dwShadeMode = D3DSHADE_GOURAUD; + + Fvector vP, vD, vN, vR; + Fmatrix mV, mP; - Fvector vP,vD,vN,vR; - Fmatrix mV,mP; - Fvector S; - bbox.getradius (S); - float R = 2.f*_max(S.x,S.z); + bbox.getradius(S); + float R = 2.f*_max(S.x, S.z); - u32 pitch = tgt_w*LOD_SAMPLE_COUNT; - tgt_data.resize (pitch*tgt_h); - for (int frame=0; framescene_clear_color = cc; + EDevice.dwFillMode = old_dwFillMode; + EDevice.dwShadeMode = old_dwShadeMode; + psDeviceFlags = old_flag; + EPrefs->scene_clear_color = cc; - RCache.set_xform_view (save_view); - RCache.set_xform_project (save_projection); + RCache.set_xform_view(save_view); + RCache.set_xform_project(save_projection); } -void CImageManager::CreateLODTexture(CEditableObject* OBJECT, U32Vec& lod_pixels, U32Vec& nm_pixels, u32 tgt_w, u32 tgt_h, int _samples, int quality) +void CImageManager::CreateLODTexture(CEditableObject *OBJECT, U32Vec &lod_pixels, U32Vec &nm_pixels, u32 tgt_w, u32 tgt_h, int _samples, int quality) { - // build hemi light - BLVec simple_hemi; + // build hemi light + BLVec simple_hemi; // fill simple hemi - simple_hemi.clear (); - xrHemisphereBuild (1,2.f,simple_hemi_callback,&simple_hemi); + simple_hemi.clear(); + xrHemisphereBuild(1, 2.f, simple_hemi_callback, &simple_hemi); - Fbox bb = OBJECT->GetBox(); + Fbox bb = OBJECT->GetBox(); // build lod normals - lod_pixels.resize (LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,0); - nm_pixels.resize (LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,0); - U32Vec hemi_tmp (LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,0); - Fvector o_center, o_size; - Fmatrix M, Mi; - bb.getradius (o_size); - bb.getcenter (o_center); - SPBItem* PB = UI->ProgressStart(LOD_SAMPLE_COUNT*LOD_IMAGE_SIZE,OBJECT->GetName()); - float dW = _max(o_size.x,o_size.z)/(LOD_IMAGE_SIZE/2); - float dH = o_size.y/(LOD_IMAGE_SIZE/2); - float dR = bb.getradius(); - float d2R = dR*2.f; - ETOOLS::ray_options (CDB::OPT_CULL); - - CreateLODSamples (bb,lod_pixels,LOD_IMAGE_SIZE,LOD_IMAGE_SIZE); - - float tN=0.f,tH=0.f,tT=0.f,tR=0.f; - - float LOD_CALC_SAMPLES = quality; - s32 LOD_CALC_SAMPLES_LIM= LOD_CALC_SAMPLES/2; + lod_pixels.resize(LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT, 0); + nm_pixels.resize(LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT, 0); + U32Vec hemi_tmp(LOD_IMAGE_SIZE*LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT, 0); + Fvector o_center, o_size; + Fmatrix M, Mi; + bb.getradius(o_size); + bb.getcenter(o_center); + SPBItem*PB = UI->ProgressStart(LOD_SAMPLE_COUNT*LOD_IMAGE_SIZE, OBJECT->GetName()); + float dW = _max(o_size.x, o_size.z)/(LOD_IMAGE_SIZE/2); + float dH = o_size.y/(LOD_IMAGE_SIZE/2); + float dR = bb.getradius(); + float d2R = dR*2.f; + ETOOLS::ray_options(CDB::OPT_CULL); + + CreateLODSamples(bb, lod_pixels,LOD_IMAGE_SIZE,LOD_IMAGE_SIZE); + + float tN = 0.f, tH = 0.f, tT = 0.f, tR = 0.f; + + float LOD_CALC_SAMPLES = quality; + s32 LOD_CALC_SAMPLES_LIM = LOD_CALC_SAMPLES/2; // preload textures - for (SurfaceIt surf_it=OBJECT->Surfaces().begin(); surf_it!=OBJECT->Surfaces().end(); surf_it++){ - CSurface* surf = *surf_it; - Shader_xrLC* c_sh = EDevice.ShaderXRLC.Get(surf->_ShaderXRLCName()); - if (!c_sh->flags.bRendering) continue; - if (0==surf->m_ImageData)surf->CreateImageData(); - } + for (SurfaceIt surf_it = OBJECT->Surfaces().begin(); surf_it!=OBJECT->Surfaces().end(); surf_it++) + { + CSurface*surf = *surf_it; + Shader_xrLC *c_sh = EDevice.ShaderXRLC.Get(surf->_ShaderXRLCName()); + if (!c_sh->flags.bRendering) + continue; + if (0==surf->m_ImageData) + surf->CreateImageData(); + } // calculate - for (u32 sample_idx=0; sample_idxInc (); - float Y = (iH-(LOD_IMAGE_SIZE-1)/2)*dH; - for (s32 iW=0; iWInc(); + float Y = (iH-(LOD_IMAGE_SIZE-1)/2)*dH; + for (s32 iW = 0; iWRayQuery (PQ); - if (PQ.r_count()){ + start.mad(M.k, -dR); + PQ.prepare_rq(start, M.k, d2R, CDB::OPT_CULL); + OBJECT->RayQuery(PQ); + if (PQ.r_count()) + { PQ.r_sort(); - Fvector N = {0,0,0}; -///. Fcolor C = {0,0,0,0}; - for (s32 k=PQ.r_count()-1; k>=0; k--){ - SPickQuery::SResult* R = PQ.r_begin()+k; - u32 uA, uC; - if (!GetPointColor(R,uA,uC)) continue; - float fA = float(uA)/255.f; - if (uA){ - Fvector pt; pt.mad(PQ.m_Start,PQ.m_Direction,R->range-EPS_L); - Fvector4 ptt; ptt.set(pt.x,pt.y,pt.z,fA); + Fvector N = {0,0,0}; + ///. Fcolor C = {0,0,0,0}; + for (s32 k = PQ.r_count()-1; k>=0; k--) + { + SPickQuery::SResult *R = PQ.r_begin()+k; + u32 uA, uC; + if (!GetPointColor(R, uA, uC)) + continue; + float fA = float(uA)/255.f; + if (uA) + { + Fvector pt; + pt.mad(PQ.m_Start, PQ.m_Direction, R->range-EPS_L); + Fvector4 ptt; + ptt.set(pt.x, pt.y, pt.z, fA); sample_pt_vec.push_back(ptt); } // normal Fvector Nn; - Nn.mknormal (R->verts[0],R->verts[1],R->verts[2]); - Nn.mul (fA); + Nn.mknormal(R->verts[0], R->verts[1], R->verts[2]); + Nn.mul(fA); - N.mul (1.f-fA); - N.add (Nn); + N.mul(1.f-fA); + N.add(Nn); // color -///. Fcolor Cn; -///. Cn.set (uC); -///. if (Cn.a>=(200.f/255.f)) C.lerp(C,Cn,Cn.a); + ///. Fcolor Cn; + ///. Cn.set (uC); + ///. if (Cn.a>=(200.f/255.f)) C.lerp(C,Cn,Cn.a); } - float n_mag = N.magnitude(); - if (!fis_zero(n_mag,EPS)) - n_vec.push_back (N.div(n_mag)); -///. c_vec.push_back (Fvector4().set(C.r,C.g,C.b,C.a)); + float n_mag = N.magnitude(); + if (!fis_zero(n_mag, EPS)) + n_vec.push_back(N.div(n_mag)); + ///. c_vec.push_back (Fvector4().set(C.r,C.g,C.b,C.a)); } } } -tN+=TT.GetElapsed_sec(); -///. Fvector4 cC = {0,0,0,0}; -///. for (Fvector4It c_it=c_vec.begin(); c_it!=c_vec.end(); c_it++) -///. cC.add (*c_it); -///. cC.div (c_vec.size()); -///. cC.mul (255.f); -///. tgt_c = color_rgba(iFloor(cC.x),iFloor(cC.y),iFloor(cC.z),iFloor(cC.w)>200.f?255:0); - - Fvector N={0,0,0}; - if (!n_vec.empty()){ - for (FvectorIt it=n_vec.begin(); it!=n_vec.end(); it++) N.add(*it); - N.div (n_vec.size()); - N.normalize_safe(); - Mi.transform_dir(N); + tN += TT.GetElapsed_sec(); + ///. Fvector4 cC = {0,0,0,0}; + ///. for (Fvector4It c_it=c_vec.begin(); c_it!=c_vec.end(); c_it++) + ///. cC.add (*c_it); + ///. cC.div (c_vec.size()); + ///. cC.mul (255.f); + ///. tgt_c = color_rgba(iFloor(cC.x),iFloor(cC.y),iFloor(cC.z),iFloor(cC.w)>200.f?255:0); + + Fvector N = {0,0,0}; + if (!n_vec.empty()) + { + for (FvectorIt it = n_vec.begin(); it!=n_vec.end(); it++) + N.add(*it); + N.div(n_vec.size()); + N.normalize_safe(); + Mi.transform_dir(N); } - N.mul (0.5f); - N.add (0.5f); - N.mul (255.f); - tgt_n = color_rgba(iFloor(N.x),iFloor(N.y),iFloor(N.z),color_get_A(tgt_c)); - - if (0==color_get_A(tgt_c)) continue; -TT.Start(); + N.mul(0.5f); + N.add(0.5f); + N.mul(255.f); + tgt_n = color_rgba(iFloor(N.x), iFloor(N.y), iFloor(N.z), color_get_A(tgt_c)); + + if (0==color_get_A(tgt_c)) + continue; + TT.Start(); // light points - float res_transp = 0.f; - for (Fvector4It pt_it=sample_pt_vec.begin(); pt_it!=sample_pt_vec.end(); pt_it++){ - float avg_transp = 0.f; - for (BLIt it=simple_hemi.begin(); it!=simple_hemi.end(); it++){ -TT1.Start(); - Fvector start; - start.mad (Fvector().set(pt_it->x,pt_it->y,pt_it->z),it->light.direction,-dR); - PQ.prepare_rq (start,it->light.direction,dR,CDB::OPT_CULL); - OBJECT->RayQuery (PQ); -tR+=TT1.GetElapsed_sec(); - float ray_transp= 1.f; - if (PQ.r_count()){ - for (s32 k=0; kx, pt_it->y, pt_it->z), it->light.direction, -dR); + PQ.prepare_rq(start, it->light.direction, dR, CDB::OPT_CULL); + OBJECT->RayQuery(PQ); + tR += TT1.GetElapsed_sec(); + float ray_transp = 1.f; + if (PQ.r_count()) + { + for (s32 k = 0; kw)+avg_transp*pt_it->w; + avg_transp /= simple_hemi.size(); + res_transp = res_transp*(1.f-pt_it->w)+avg_transp*pt_it->w; } -tH+=TT.GetElapsed_sec(); - u8 h = (u8)iFloor (res_transp*255.f); - tgt_h = color_rgba(h,h,h,color_get_A(tgt_c)); + tH += TT.GetElapsed_sec(); + u8 h = (u8)iFloor(res_transp*255.f); + tgt_h = color_rgba(h, h, h, color_get_A(tgt_c)); } } } - Msg("Normal: %3.2fsec, Hemi: %3.2f, PC: %3.2f, RP: %3.2f",tN,tH,tT,tR); - ImageLib.ApplyBorders (lod_pixels,LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); - ImageLib.ApplyBorders (nm_pixels, LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); - ImageLib.ApplyBorders (hemi_tmp, LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); + Msg("Normal: %3.2fsec, Hemi: %3.2f, PC: %3.2f, RP: %3.2f", tN, tH, tT, tR); + ImageLib.ApplyBorders(lod_pixels,LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); + ImageLib.ApplyBorders(nm_pixels, LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); + ImageLib.ApplyBorders(hemi_tmp, LOD_IMAGE_SIZE*LOD_SAMPLE_COUNT,LOD_IMAGE_SIZE); // fill alpha to N-channel (HEMI) - for (int px_idx=0; px_idxProgressEnd(PB); } //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -void CImageManager::CreateLODTexture(CEditableObject* OBJECT, LPCSTR tex_name, u32 tgt_w, u32 tgt_h, int samples, int age, int quality) +void CImageManager::CreateLODTexture(CEditableObject *OBJECT, LPCSTR tex_name, u32 tgt_w, u32 tgt_h, int samples, int age, int quality) { - U32Vec lod_pixels, nm_pixels; + U32Vec lod_pixels, nm_pixels; - CreateLODTexture (OBJECT,lod_pixels,nm_pixels,tgt_w,tgt_h,samples,quality); + CreateLODTexture(OBJECT, lod_pixels, nm_pixels, tgt_w, tgt_h, samples, quality); - string_path out_name,src_name; - CImage* I = xr_new(); + string_path out_name, src_name; + CImage *I = xr_new(); // save lod - strcpy (src_name,tex_name); + strcpy(src_name, tex_name); - strcpy (src_name, EFS.ChangeFileExt(src_name,".thm").c_str()); - FS.file_delete (_textures_,src_name); + strcpy(src_name, EFS.ChangeFileExt(src_name, ".thm").c_str()); + FS.file_delete(_textures_, src_name); - strcpy (src_name, EFS.ChangeFileExt(src_name,".tga").c_str()); - FS.update_path (out_name,_textures_,src_name); - I->Create (tgt_w*samples,tgt_h,lod_pixels.begin()); -// I->Vflip (); - I->SaveTGA (out_name); - FS.set_file_age (out_name,age); - SynchronizeTexture (src_name,age); + strcpy(src_name, EFS.ChangeFileExt(src_name, ".tga").c_str()); + FS.update_path(out_name, _textures_, src_name); + I->Create(tgt_w*samples, tgt_h, lod_pixels.begin()); + // I->Vflip (); + I->SaveTGA(out_name); + FS.set_file_age(out_name, age); + SynchronizeTexture(src_name, age); // save normal map - strconcat (sizeof(src_name),src_name, tex_name, "_nm"); - strcpy (src_name,EFS.ChangeFileExt(src_name,".thm").c_str()); - FS.file_delete (_textures_,src_name); - - strcpy (src_name, EFS.ChangeFileExt(src_name,".tga").c_str()); - FS.update_path (out_name,_textures_,src_name); - I->Create (tgt_w*samples,tgt_h,nm_pixels.begin()); -// I->Vflip (); - I->SaveTGA (out_name); - FS.set_file_age (out_name,age); - SynchronizeTexture (src_name,age); - - xr_delete (I); + strconcat(sizeof(src_name), src_name, tex_name, "_nm"); + strcpy(src_name, EFS.ChangeFileExt(src_name, ".thm").c_str()); + FS.file_delete(_textures_, src_name); + + strcpy(src_name, EFS.ChangeFileExt(src_name, ".tga").c_str()); + FS.update_path(out_name, _textures_, src_name); + I->Create(tgt_w*samples, tgt_h, nm_pixels.begin()); + // I->Vflip (); + I->SaveTGA(out_name); + FS.set_file_age(out_name, age); + SynchronizeTexture(src_name, age); + + xr_delete(I); } - diff --git a/src/editors/ECore/Editor/LW_ShaderDef.h b/src/editors/ECore/Editor/LW_ShaderDef.h index ee0ce7586c3..aed53555b47 100644 --- a/src/editors/ECore/Editor/LW_ShaderDef.h +++ b/src/editors/ECore/Editor/LW_ShaderDef.h @@ -4,17 +4,19 @@ /* our instance data */ #pragma pack(push,1) -typedef struct st_XRShader{ - char en_name[64]; - int en_idx; - char lc_name[64]; - int lc_idx; - char gm_name[64]; - int gm_idx; - char* desc; +typedef struct st_XRShader +{ + char en_name[64]; + int en_idx; + char lc_name[64]; + int lc_idx; + char gm_name[64]; + int gm_idx; + char *desc; } XRShader; #pragma pack(pop) #define SH_PLUGIN_NAME "!XRayShader" #endif + diff --git a/src/editors/ECore/Editor/Library.cpp b/src/editors/ECore/Editor/Library.cpp index c289ebc34f2..bcb50b8caaf 100644 --- a/src/editors/ECore/Editor/Library.cpp +++ b/src/editors/ECore/Editor/Library.cpp @@ -5,267 +5,316 @@ #include "stdafx.h" #pragma hdrstop -#include "Log.h" +#include "xrCore/Log.h" #include "Library.h" #include "EditObject.h" #include "ui_main.h" //---------------------------------------------------- ELibrary Lib; + //---------------------------------------------------- ELibrary::ELibrary() { - m_bReady = false; + m_bReady = false; } + //---------------------------------------------------- -ELibrary::~ELibrary() -{ -} +ELibrary::~ELibrary() {} + //---------------------------------------------------- void ELibrary::OnCreate() { -// EDevice.seqDevCreate.Add (this,REG_PRIORITY_NORMAL); -// EDevice.seqDevDestroy.Add(this,REG_PRIORITY_NORMAL); + // EDevice.seqDevCreate.Add (this,REG_PRIORITY_NORMAL); + // EDevice.seqDevDestroy.Add(this,REG_PRIORITY_NORMAL); m_bReady = true; } + //---------------------------------------------------- void ELibrary::OnDestroy() { - VERIFY(m_bReady); + VERIFY(m_bReady); m_bReady = false; -// EDevice.seqDevCreate.Remove(this); -// EDevice.seqDevDestroy.Remove(this); + // EDevice.seqDevCreate.Remove(this); + // EDevice.seqDevDestroy.Remove(this); // remove all instance CEditableObject - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); - for(; O!=E; O++){ - if (0!=O->second->m_RefCount){ -//. ELog.DlgMsg(mtError,"Object '%s' still referenced.",O->first.c_str()); -//. R_ASSERT(0==O->second->m_RefCount); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); + for (; O!=E; O++) + { + if (0!=O->second->m_RefCount) + { + //. ELog.DlgMsg(mtError,"Object '%s' still referenced.",O->first.c_str()); + //. R_ASSERT(0==O->second->m_RefCount); } - xr_delete(O->second); + xr_delete(O->second); } - m_EditObjects.clear(); + m_EditObjects.clear(); } + //---------------------------------------------------- void ELibrary::CleanLibrary() { - VERIFY(m_bReady); + VERIFY(m_bReady); // remove all unused instance CEditableObject - for(EditObjPairIt O = m_EditObjects.begin(); O!=m_EditObjects.end(); ){ - if (0==O->second->m_RefCount){ - EditObjPairIt D = O; O++; - xr_delete (D->second); - m_EditObjects.erase (D); - }else O++; + for (EditObjPairIt O = m_EditObjects.begin(); O!=m_EditObjects.end();) + { + if (0==O->second->m_RefCount) + { + EditObjPairIt D = O; + O++; + xr_delete(D->second); + m_EditObjects.erase(D); + } + else + O++; } } + //---------------------------------------------------- void ELibrary::ReloadObject(LPCSTR nm) { - VERIFY(m_bReady); - R_ASSERT(nm&&nm[0]); - string512 name; strcpy(name,nm); strlwr(name); - EditObjPairIt it = m_EditObjects.find(name); + VERIFY(m_bReady); + R_ASSERT(nm&&nm[0]); + string512 name; + strcpy(name, nm); + strlwr(name); + EditObjPairIt it = m_EditObjects.find(name); if (it!=m_EditObjects.end()) - it->second->Reload(); + it->second->Reload(); } + //--------------------------------------------------------------------------- -void ELibrary::ReloadObjects(){ - VERIFY(m_bReady); - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); - for(; O!=E; O++) - O->second->Reload(); +void ELibrary::ReloadObjects() +{ + VERIFY(m_bReady); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); + for (; O!=E; O++) + O->second->Reload(); } + //---------------------------------------------------- -void ELibrary::OnDeviceCreate(){ - VERIFY(m_bReady); - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); - for(; O!=E; O++) - O->second->OnDeviceCreate(); +void ELibrary::OnDeviceCreate() +{ + VERIFY(m_bReady); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); + for (; O!=E; O++) + O->second->OnDeviceCreate(); } + //--------------------------------------------------------------------------- -void ELibrary::OnDeviceDestroy(){ - VERIFY(m_bReady); - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); - for(; O!=E; O++) - O->second->OnDeviceDestroy(); +void ELibrary::OnDeviceDestroy() +{ + VERIFY(m_bReady); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); + for (; O!=E; O++) + O->second->OnDeviceDestroy(); } + //--------------------------------------------------------------------------- void ELibrary::EvictObjects() { - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); - for(; O!=E; O++) - O->second->EvictObject(); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); + for (; O!=E; O++) + O->second->EvictObject(); } + //---------------------------------------------------- -CEditableObject* ELibrary::LoadEditObject(LPCSTR name) +CEditableObject *ELibrary::LoadEditObject(LPCSTR name) { - VERIFY(m_bReady); - CEditableObject* m_EditObject = xr_new(name); + VERIFY(m_bReady); + CEditableObject*m_EditObject = xr_new(name); string_path fn; - FS.update_path(fn,_objects_,EFS.ChangeFileExt(name,".object").c_str()); + FS.update_path(fn, _objects_, EFS.ChangeFileExt(name, ".object").c_str()); if (FS.exist(fn)) { - if (m_EditObject->Load(fn)) return m_EditObject; - }else{ - ELog.Msg(mtError,"Can't find file '%s'",fn); + if (m_EditObject->Load(fn)) + return m_EditObject; + } + else + { + ELog.Msg(mtError, "Can't find file '%s'", fn); } xr_delete(m_EditObject); - return 0; + return 0; } + //--------------------------------------------------------------------------- -CEditableObject* ELibrary::CreateEditObject(LPCSTR nm) +CEditableObject *ELibrary::CreateEditObject(LPCSTR nm) { - VERIFY(m_bReady); + VERIFY(m_bReady); R_ASSERT(nm&&nm[0]); -//. UI->ProgressInfo (nm); - AnsiString name = AnsiString(nm).LowerCase(); + //. UI->ProgressInfo (nm); + AnsiString name = AnsiString(nm).LowerCase(); // file exist - find in already loaded - CEditableObject* m_EditObject = 0; - EditObjPairIt it = m_EditObjects.find(name); - if (it!=m_EditObjects.end()) m_EditObject = it->second; - else if (0!=(m_EditObject=LoadEditObject(name.c_str()))) - m_EditObjects[name] = m_EditObject; - if (m_EditObject) m_EditObject->m_RefCount++; - return m_EditObject; + CEditableObject*m_EditObject = 0; + EditObjPairIt it = m_EditObjects.find(name); + if (it!=m_EditObjects.end()) + m_EditObject = it->second; + else if (0!=(m_EditObject = LoadEditObject(name.c_str()))) + m_EditObjects[name] = m_EditObject; + if (m_EditObject) + m_EditObject->m_RefCount++; + return m_EditObject; } + //--------------------------------------------------------------------------- -void ELibrary::RemoveEditObject(CEditableObject*& object) +void ELibrary::RemoveEditObject(CEditableObject *&object) { - if (object){ - object->m_RefCount--; - R_ASSERT(object->m_RefCount>=0); - if ((object->m_RefCount==0)&&EPrefs->object_flags.is(epoDiscardInstance)) - if (!object->IsModified()) UnloadEditObject(object->GetName()); - object=0; - } + if (object) + { + object->m_RefCount--; + R_ASSERT(object->m_RefCount>=0); + if ((object->m_RefCount==0)&&EPrefs->object_flags.is(epoDiscardInstance)) + if (!object->IsModified()) + UnloadEditObject(object->GetName()); + object = 0; + } } + //--------------------------------------------------------------------------- -void ELibrary::Save(FS_FileSet* modif_map) +void ELibrary::Save(FS_FileSet *modif_map) { - VERIFY(m_bReady); - EditObjPairIt O = m_EditObjects.begin(); - EditObjPairIt E = m_EditObjects.end(); + VERIFY(m_bReady); + EditObjPairIt O = m_EditObjects.begin(); + EditObjPairIt E = m_EditObjects.end(); if (modif_map) { - for(; O!=E; O++) - if (modif_map->end()!=modif_map->find(FS_File(O->second->GetName()))) + for (; O!=E; O++) + if (modif_map->end()!=modif_map->find(FS_File(O->second->GetName()))) { - string_path nm; - FS.update_path (nm,_objects_,O->second->GetName()); - strcpy(nm, EFS.ChangeFileExt(nm,".object").c_str()); + string_path nm; + FS.update_path(nm, _objects_, O->second->GetName()); + strcpy(nm, EFS.ChangeFileExt(nm, ".object").c_str()); if (!O->second->Save(nm)) - Log ("!Can't save object:",nm); + Log("!Can't save object:", nm); } - }else + } + else { - for(; O!=E; O++) + for (; O!=E; O++) if (O->second->IsModified()) { - string_path nm; - FS.update_path (nm,_objects_,O->second->GetName()); - strcpy (nm, EFS.ChangeFileExt(nm,".object").c_str()); + string_path nm; + FS.update_path(nm, _objects_, O->second->GetName()); + strcpy(nm, EFS.ChangeFileExt(nm, ".object").c_str()); if (!O->second->Save(nm)) - Log ("!Can't save object:",nm); + Log("!Can't save object:", nm); } } } + //--------------------------------------------------------------------------- -int ELibrary::GetObjects(FS_FileSet& files) +int ELibrary::GetObjects(FS_FileSet &files) { - return FS.file_list(files,_objects_,FS_ListFiles|FS_ClampExt,"*.object"); + return FS.file_list(files, _objects_, FS_ListFiles|FS_ClampExt, "*.object"); } + //--------------------------------------------------------------------------- -void ELibrary::RemoveObject(LPCSTR _fname, EItemType type, bool& res) +void ELibrary::RemoveObject(LPCSTR _fname, EItemType type, bool &res) { - if (TYPE_FOLDER==type){ - FS.dir_delete (_objects_,_fname,FALSE); - res = true; - return; - }else if (TYPE_OBJECT==type){ - string_path fname,src_name; - strcpy(fname,EFS.ChangeFileExt(_fname,".object").c_str()); - FS.update_path (src_name,_objects_,fname); + if (TYPE_FOLDER==type) + { + FS.dir_delete(_objects_, _fname, FALSE); + res = true; + return; + } + else if (TYPE_OBJECT==type) + { + string_path fname, src_name; + strcpy(fname, EFS.ChangeFileExt(_fname, ".object").c_str()); + FS.update_path(src_name, _objects_, fname); if (FS.exist(src_name)) { - xr_string thm_name = EFS.ChangeFileExt(fname,".thm"); + xr_string thm_name = EFS.ChangeFileExt(fname, ".thm"); // source - FS.file_delete (src_name); + FS.file_delete(src_name); // thumbnail - FS.file_delete (_objects_,thm_name.c_str()); + FS.file_delete(_objects_, thm_name.c_str()); + + UnloadEditObject(_fname); - UnloadEditObject (_fname); - res = true; return; } - }else THROW; + } + else + THROW; res = false; } + //--------------------------------------------------------------------------- void ELibrary::RenameObject(LPCSTR nm0, LPCSTR nm1, EItemType type) { - if (TYPE_FOLDER==type){ - FS.dir_delete (_objects_,nm0,FALSE); - }else if (TYPE_OBJECT==type){ - string_path fn0,fn1,temp; + if (TYPE_FOLDER==type) + { + FS.dir_delete(_objects_, nm0, FALSE); + } + else if (TYPE_OBJECT==type) + { + string_path fn0, fn1, temp; // rename base file - FS.update_path(fn0,_objects_,nm0); - strcat(fn0,".object"); - FS.update_path(fn1,_objects_,nm1); - strcat(fn1,".object"); - FS.file_rename(fn0,fn1,false); + FS.update_path(fn0, _objects_, nm0); + strcat(fn0, ".object"); + FS.update_path(fn1, _objects_, nm1); + strcat(fn1, ".object"); + FS.file_rename(fn0, fn1, false); // rename thm - FS.update_path(fn0,_objects_,nm0); - strcat(fn0,".thm"); - FS.update_path(fn1,_objects_,nm1); - strcat(fn1,".thm"); - FS.file_rename(fn0,fn1,false); + FS.update_path(fn0, _objects_, nm0); + strcat(fn0, ".thm"); + FS.update_path(fn1, _objects_, nm1); + strcat(fn1, ".thm"); + FS.file_rename(fn0, fn1, false); // rename in cache - EditObjPairIt it = m_EditObjects.find(nm0); - if (it!=m_EditObjects.end()){ - m_EditObjects[nm1] = it->second; - m_EditObjects.erase (it); + EditObjPairIt it = m_EditObjects.find(nm0); + if (it!=m_EditObjects.end()) + { + m_EditObjects[nm1] = it->second; + m_EditObjects.erase(it); } - } + } } + //--------------------------------------------------------------------------- void ELibrary::UnloadEditObject(LPCSTR full_name) { - EditObjPairIt it = m_EditObjects.find(full_name); - if (it!=m_EditObjects.end()){ - if (0!=it->second->m_RefCount){ - ELog.DlgMsg(mtError,"Object '%s' still referenced.",it->first.c_str()); + EditObjPairIt it = m_EditObjects.find(full_name); + if (it!=m_EditObjects.end()) + { + if (0!=it->second->m_RefCount) + { + ELog.DlgMsg(mtError, "Object '%s' still referenced.", it->first.c_str()); THROW; } - m_EditObjects.erase(it); - xr_delete (it->second); + m_EditObjects.erase(it); + xr_delete(it->second); } } + //--------------------------------------------------------------------------- + diff --git a/src/editors/ECore/Editor/Library.h b/src/editors/ECore/Editor/Library.h index 56f5ee93b18..3df38d789c7 100644 --- a/src/editors/ECore/Editor/Library.h +++ b/src/editors/ECore/Editor/Library.h @@ -6,45 +6,45 @@ #define LibraryH #include "pure.h" -#include "../xrEProps/FolderLib.h" +#include "editors/xrEProps/FolderLib.h" //---------------------------------------------------- class CEditableObject; -DEFINE_MAP_PRED(AnsiString,CEditableObject*,EditObjMap,EditObjPairIt,astr_pred); +DEFINE_MAP_PRED(AnsiString, CEditableObject *, EditObjMap, EditObjPairIt, astr_pred); //---------------------------------------------------- class ECORE_API ELibrary//: public pureDeviceCreate, public pureDeviceDestroy { - bool m_bReady; - friend class TfrmChoseObject; - EditObjMap m_EditObjects; + bool m_bReady; + friendclass TfrmChoseObject; + EditObjMap m_EditObjects; - CEditableObject* LoadEditObject (LPCSTR full_name); - void UnloadEditObject (LPCSTR full_name); -public: - ELibrary (); - virtual ~ELibrary (); - - void __stdcall RemoveObject (LPCSTR fname, EItemType type, bool& res); - void __stdcall RenameObject (LPCSTR fn0, LPCSTR fn1, EItemType type); + CEditableObject*LoadEditObject(LPCSTR full_name); + void UnloadEditObject(LPCSTR full_name); + public: + ELibrary(); + virtual ~ELibrary(); - void OnCreate (); - void OnDestroy (); - void Save (FS_FileSet* modif_map=0); + void__stdcall RemoveObject(LPCSTR fname, EItemType type, bool& res); + void__stdcall RenameObject(LPCSTR fn0, LPCSTR fn1, EItemType type); - void ReloadObjects (); - void CleanLibrary (); - void ReloadObject (LPCSTR name); + void OnCreate(); + void OnDestroy(); + void Save(FS_FileSet*modif_map = 0); - CEditableObject* CreateEditObject (LPCSTR name); - void RemoveEditObject (CEditableObject*& object); + void ReloadObjects(); + void CleanLibrary(); + void ReloadObject(LPCSTR name); - int GetObjects (FS_FileSet& files); - int ObjectCount (){return m_EditObjects.size();} + CEditableObject*CreateEditObject(LPCSTR name); + void RemoveEditObject(CEditableObject*& object); - void EvictObjects (); + int GetObjects(FS_FileSet&files); + int ObjectCount(){return m_EditObjects.size();} - virtual void OnDeviceCreate (); - virtual void OnDeviceDestroy (); + void EvictObjects(); + + virtual void OnDeviceCreate(); + virtual void OnDeviceDestroy(); }; extern ECORE_API ELibrary Lib; diff --git a/src/editors/ECore/Editor/LogForm.cpp b/src/editors/ECore/Editor/LogForm.cpp index 3861031c6c9..f1e7271514d 100644 --- a/src/editors/ECore/Editor/LogForm.cpp +++ b/src/editors/ECore/Editor/LogForm.cpp @@ -8,57 +8,75 @@ #pragma link "mxPlacemnt" #pragma link "MxMenus" #pragma resource "*.dfm" -TfrmLog *TfrmLog::form=0; +TfrmLog *TfrmLog::form = 0; + //--------------------------------------------------------------------------- -__fastcall TfrmLog::TfrmLog(TComponent* Owner) +__fastcall TfrmLog::TfrmLog(TComponent *Owner) : TForm(Owner) { - DEFINE_INI(fsStorage); + DEFINE_INI(fsStorage); } + //--------------------------------------------------------------------------- -void __fastcall TfrmLog::CreateLog(){ - VERIFY(!form); - form = xr_new((TComponent*)0); +void __fastcall TfrmLog::CreateLog() +{ + VERIFY(!form); + form = xr_new((TComponent*)0); } -void __fastcall TfrmLog::DestroyLog(){ - xr_delete(form); + +void __fastcall TfrmLog::DestroyLog() +{ + xr_delete(form); } -void __fastcall TfrmLog::ShowLog(){ - VERIFY(form); - form->Show(); + +void __fastcall TfrmLog::ShowLog() +{ + VERIFY(form); + form->Show(); } -void __fastcall TfrmLog::HideLog(){ - VERIFY(form); - form->Close(); + +void __fastcall TfrmLog::HideLog() +{ + VERIFY(form); + form->Close(); } void __fastcall TfrmLog::ebClearClick(TObject *Sender) { - lbLog->Items->Clear(); + lbLog->Items->Clear(); } + //--------------------------------------------------------------------------- -void __fastcall TfrmLog::AddDlgMessage(TMsgDlgType mt, const AnsiString& msg) -{ +void __fastcall TfrmLog::AddDlgMessage(TMsgDlgType mt, const AnsiString &msg) +{ ExecCommand(COMMAND_RENDER_FOCUS); - MessageDlg(msg, mt, TMsgDlgButtons() << mbOK, 0); - AddMessage(mt,msg); + MessageDlg(msg, mt, TMsgDlgButtons()<lbLog->Items->AddObject(M,(TObject*)mt); + form->lbLog->Items->AddObject(M, (TObject*)mt); form->lbLog->ItemIndex = form->lbLog->Items->Count-1; - if ((mt==mtError)&&!form->Visible) form->Show(); + if ((mt==mtError)&&!form->Visible) + form->Show(); } + //--------------------------------------------------------------------------- #define MSG_ERROR 0x00C4C4FF @@ -67,99 +85,122 @@ void __fastcall TfrmLog::AddMessage(TMsgDlgType mt, const AnsiString& msg) #define MSG_DEF 0x00E8E8E8 void __fastcall TfrmLog::lbLogDrawItem(TWinControl *Control, int Index, - TRect &Rect, TOwnerDrawState State) -{ - TListBox* lb = ((TListBox *)Control); - TCanvas *pCanvas = lb->Canvas; - if (!State.Contains(odSelected)){ - pCanvas->Brush->Color = TColor(MSG_DEF); - TMsgDlgType mt = (TMsgDlgType)lb->Items->Objects[Index]; - switch(mt){ - case mtError: pCanvas->Brush->Color=TColor(MSG_ERROR);break; - case mtInformation: pCanvas->Brush->Color=TColor(MSG_INFO); break; - case mtConfirmation: pCanvas->Brush->Color=TColor(MSG_CONF); break; - } + TRect &Rect, TOwnerDrawState State) +{ + TListBox *lb = ((TListBox *)Control); + TCanvas *pCanvas = lb->Canvas; + if (!State.Contains(odSelected)) + { + pCanvas->Brush->Color = TColor(MSG_DEF); + TMsgDlgType mt = (TMsgDlgType)lb->Items->Objects[Index]; + switch (mt) + { + case mtError: pCanvas->Brush->Color = TColor(MSG_ERROR); + break; + case mtInformation: pCanvas->Brush->Color = TColor(MSG_INFO); + break; + case mtConfirmation: pCanvas->Brush->Color = TColor(MSG_CONF); + break; + } } - pCanvas->FillRect(Rect); - int Offset = 2; // default text offset width - pCanvas->TextOut(Rect.Left + Offset, Rect.Top, lb->Items->Strings[Index]); + pCanvas->FillRect(Rect); + int Offset = 2; // default text offset width + pCanvas->TextOut(Rect.Left+Offset, Rect.Top, lb->Items->Strings[Index]); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::FormKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift) + TShiftState Shift) { - if (Key==VK_ESCAPE) Close(); - else{ - UI->ApplyGlobalShortCut(Key, Shift); + if (Key==VK_ESCAPE) + Close(); + else + { + UI->ApplyGlobalShortCut(Key, Shift); } } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::ebClearSelectedClick(TObject *Sender) { - for (int i = 0; i < lbLog->Items->Count; i++){ - if (lbLog->Selected[i]){ - lbLog->Items->Delete(i); + for (int i = 0; iItems->Count; i++) + { + if (lbLog->Selected[i]) + { + lbLog->Items->Delete(i); i--; } } } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::ebCloseClick(TObject *Sender) { - Close(); + Close(); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::FormShow(TObject *Sender) { - // check window position - UI->CheckWindowPos(this); + // check window position + UI->CheckWindowPos(this); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::ebFlushClick(TObject *Sender) { - FlushLog(); + FlushLog(); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::lbLogKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift) + TShiftState Shift) { - if (Shift.Contains(ssCtrl)&&(Key=='C')){ - imCopyClick (Sender); - }else if (Shift.Contains(ssCtrl)&&(Key=='A')){ - imSelectAllClick(Sender); + if (Shift.Contains(ssCtrl)&&(Key=='C')) + { + imCopyClick(Sender); + } + else if (Shift.Contains(ssCtrl)&&(Key=='A')) + { + imSelectAllClick(Sender); } } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::imCopyClick(TObject *Sender) { - TClipboard* clp = Clipboard(); - clp->Clear (); - xr_string tmp; - for (int i = 0; i < lbLog->Items->Count; i++) - if (lbLog->Selected[i]){ - tmp = tmp+lbLog->Items->Strings[i].c_str()+"\r\n"; + TClipboard *clp = Clipboard(); + clp->Clear(); + xr_string tmp; + for (int i = 0; iItems->Count; i++) + if (lbLog->Selected[i]) + { + tmp = tmp+lbLog->Items->Strings[i].c_str()+"\r\n"; } - clp->SetTextBuf ((LPSTR)tmp.c_str()); + clp->SetTextBuf((LPSTR)tmp.c_str()); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::imSelectAllClick(TObject *Sender) { - lbLog->SelectAll(); + lbLog->SelectAll(); } + //--------------------------------------------------------------------------- void __fastcall TfrmLog::lbLogKeyPress(TObject *Sender, char &Key) { - Key = 0; + Key = 0; } + //--------------------------------------------------------------------------- diff --git a/src/editors/ECore/Editor/LogForm.h b/src/editors/ECore/Editor/LogForm.h index a7b9278f19a..fab80cf6e1b 100644 --- a/src/editors/ECore/Editor/LogForm.h +++ b/src/editors/ECore/Editor/LogForm.h @@ -12,51 +12,55 @@ #include "MxMenus.hpp" #include -class ECORE_API TfrmLog : public TForm +class ECORE_API TfrmLog : + +public +TForm { -__published: // IDE-managed Components + __published: // IDE-managed Components TPanel *Panel1; - TPanel *Panel2; - TListBox *lbLog; - TExtBtn *ebClear; - TExtBtn *ebClearSelected; - TExtBtn *ebClose; - TFormStorage *fsStorage; - TExtBtn *ebFlush; - TMxPopupMenu *MxPopupMenu1; - TMenuItem *imCopy; - TMenuItem *imSelectAll; - TMenuItem *ClearAll1; - TMenuItem *ClearSelected1; - TMenuItem *N1; - void __fastcall ebClearClick(TObject *Sender); - void __fastcall lbLogDrawItem(TWinControl *Control, int Index, - TRect &Rect, TOwnerDrawState State); - void __fastcall FormKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift); - void __fastcall ebClearSelectedClick(TObject *Sender); - void __fastcall ebCloseClick(TObject *Sender); - void __fastcall FormShow(TObject *Sender); - void __fastcall ebFlushClick(TObject *Sender); - void __fastcall lbLogKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift); - void __fastcall imCopyClick(TObject *Sender); - void __fastcall imSelectAllClick(TObject *Sender); - void __fastcall lbLogKeyPress(TObject *Sender, char &Key); -private: // User declarations - static TfrmLog *form; -public: // User declarations + TPanel *Panel2; + TListBox *lbLog; + TExtBtn *ebClear; + TExtBtn *ebClearSelected; + TExtBtn *ebClose; + TFormStorage *fsStorage; + TExtBtn *ebFlush; + TMxPopupMenu *MxPopupMenu1; + TMenuItem *imCopy; + TMenuItem *imSelectAll; + TMenuItem *ClearAll1; + TMenuItem *ClearSelected1; + TMenuItem *N1; + void __fastcall ebClearClick(TObject *Sender); + void __fastcall lbLogDrawItem(TWinControl *Control, int Index, + TRect &Rect, TOwnerDrawState State); + void __fastcall FormKeyDown(TObject *Sender, WORD &Key, + TShiftState Shift); + void __fastcall ebClearSelectedClick(TObject *Sender); + void __fastcall ebCloseClick(TObject *Sender); + void __fastcall FormShow(TObject *Sender); + void __fastcall ebFlushClick(TObject *Sender); + void __fastcall lbLogKeyDown(TObject *Sender, WORD &Key, + TShiftState Shift); + void __fastcall imCopyClick(TObject *Sender); + void __fastcall imSelectAllClick(TObject *Sender); + void __fastcall lbLogKeyPress(TObject *Sender, char &Key); + private: // User declarations + static TfrmLog *form; + public: // User declarations __fastcall TfrmLog(TComponent* Owner); - static void __fastcall AddMessage (TMsgDlgType mt, const AnsiString& msg); - static void __fastcall AddMessage (const AnsiString& msg){AddMessage(mtCustom,msg);} - static void __fastcall AddDlgMessage(TMsgDlgType mt, const AnsiString& msg); - static void __fastcall AddDlgMessage(const AnsiString& msg){AddDlgMessage(mtCustom,msg);} - static void __fastcall ShowLog (); - static void __fastcall HideLog (); - static void __fastcall CreateLog (); - static void __fastcall DestroyLog (); - static void __fastcall ChangeVisible(){if (form->Visible) HideLog(); else ShowLog();} - static bool __fastcall IsVisible (){return form->Visible;} + static void __fastcall AddMessage (TMsgDlgType mt, const AnsiString& msg); + static void __fastcall AddMessage (const AnsiString& msg){AddMessage(mtCustom,msg);} +static void __fastcall AddDlgMessage(TMsgDlgType mt, const AnsiString& msg); +static void __fastcall AddDlgMessage(const AnsiString& msg){AddDlgMessage(mtCustom,msg);} +static void __fastcall ShowLog (); +static void __fastcall HideLog (); +static void __fastcall CreateLog (); +static void __fastcall DestroyLog (); +static void __fastcall ChangeVisible(){if (form->Visible) HideLog(); else ShowLog();} +static bool __fastcall IsVisible (){return form->Visible;} }; //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/MinimapEditor.cpp b/src/editors/ECore/Editor/MinimapEditor.cpp index a2df63d690f..e3fc190f700 100644 --- a/src/editors/ECore/Editor/MinimapEditor.cpp +++ b/src/editors/ECore/Editor/MinimapEditor.cpp @@ -13,20 +13,21 @@ #pragma link "ElACtrls" #pragma resource "*.dfm" -TTMinimapEditor* TTMinimapEditor::form = NULL; +TTMinimapEditor *TTMinimapEditor::form = NULL; + //.TTMinimapEditor *TMinimapEditor; //--------------------------------------------------------------------------- -__fastcall TTMinimapEditor::TTMinimapEditor(TComponent* Owner) - : TForm(Owner) -{ -} +__fastcall TTMinimapEditor::TTMinimapEditor(TComponent *Owner) + : TForm(Owner) {} + #include "ui_main.h" void __fastcall TTMinimapEditor::Show() { - if (!form){ - form = xr_new((TComponent*)0); -//. form->Caption = title; + if (!form) + { + form = xr_new((TComponent*)0); + //. form->Caption = title; } form->ShowModal(); @@ -35,158 +36,169 @@ void __fastcall TTMinimapEditor::Show() void __fastcall TTMinimapEditor::Hide() { - if (form){ - form->Close(); + if (form) + { + form->Close(); } } + //--------------------------------------------------------------------------- #include "freeimage/freeimage.h" #include "Image.h" -bool Surface_Load(LPCSTR full_name, U32Vec& data, u32& w, u32& h, u32& a); +bool Surface_Load(LPCSTR full_name, U32Vec &data, u32 &w, u32 &h, u32 &a); void __fastcall TTMinimapEditor::btnLoadClick(TObject *Sender) { - xr_string fn; - image_data.clear (); - - if(EFS.GetOpenName("$app_root$", fn, false, NULL, 0)) + xr_string fn; + image_data.clear(); + + if (EFS.GetOpenName("$app_root$", fn, false, NULL, 0)) { - if (Surface_Load(fn.c_str(),image_data,image_w,image_h,image_a)) + if (Surface_Load(fn.c_str(), image_data, image_w, image_h, image_a)) { - - u32* line = xr_alloc(image_w); - u32 sz_ln=sizeof(u32)*image_w; - u32 y2 = image_w-1; - for (int y=0; y(image_w); + u32 sz_ln = sizeof(u32)*image_w; + u32 y2 = image_w-1; + for (int y = 0; yValue = map_bb.min.x; + ElFloatSpinEditZ1->Value = map_bb.min.y; + + ElFloatSpinEditX2->Value = map_bb.max.x; + ElFloatSpinEditZ2->Value = map_bb.max.y; + b_block = false; + } + else { - b_block = true; - ElFloatSpinEditX1->Value = map_bb.min.x; - ElFloatSpinEditZ1->Value = map_bb.min.y; - - ElFloatSpinEditX2->Value = map_bb.max.x; - ElFloatSpinEditZ2->Value = map_bb.max.y; - b_block = false; - }else - { - map_bb.min.x = ElFloatSpinEditX1->Value; - map_bb.min.y = ElFloatSpinEditZ1->Value; - - map_bb.max.x = ElFloatSpinEditX2->Value; - map_bb.max.y = ElFloatSpinEditZ2->Value; - } - - string512 buff; - sprintf(buff,"bound_rect = %3.3f, %3.3f, %3.3f, %3.3f",map_bb.min.x,map_bb.min.y,map_bb.max.x,map_bb.max.y); - result_edit->ReadOnly = false; - result_edit->Text = buff; - result_edit->ReadOnly = true; - imgPanel->Repaint (); + map_bb.min.x = ElFloatSpinEditX1->Value; + map_bb.min.y = ElFloatSpinEditZ1->Value; + + map_bb.max.x = ElFloatSpinEditX2->Value; + map_bb.max.y = ElFloatSpinEditZ2->Value; + } + + string512 buff; + sprintf(buff, "bound_rect = %3.3f, %3.3f, %3.3f, %3.3f", map_bb.min.x, map_bb.min.y, map_bb.max.x, map_bb.max.y); + result_edit->ReadOnly = false; + result_edit->Text = buff; + result_edit->ReadOnly = true; + imgPanel->Repaint(); } -#include "FolderLib.h" -void DrawThumbnail(TCanvas* pCanvas, TRect& r, U32Vec& data, bool bDrawWithAlpha, int _w, int _h) +#include "editors/xrEProps/FolderLib.h" + +void DrawThumbnail(TCanvas *pCanvas, TRect &r, U32Vec &data, bool bDrawWithAlpha, int _w, int _h) { - pCanvas->CopyMode = cmSrcCopy; + pCanvas->CopyMode = cmSrcCopy; Graphics::TBitmap *pBitmap = xr_new(); - pBitmap->PixelFormat = pf24bit; //pf32bit; - pBitmap->Height = _h; - pBitmap->Width = _w; - + pBitmap->PixelFormat = pf24bit; //pf32bit; + pBitmap->Height = _h; + pBitmap->Width = _w; + if (bDrawWithAlpha) { - Fcolor back; - back.set (bgr2rgb(pCanvas->Brush->Color)); back.mul_rgb(255.f); - for (int y = 0; y < pBitmap->Height; y++) + Fcolor back; + back.set(bgr2rgb(pCanvas->Brush->Color)); + back.mul_rgb(255.f); + for (int y = 0; yHeight; y++) { - u32* ptr = (u32*)pBitmap->ScanLine[y]; - for (int x = 0; x < pBitmap->Width; x++){ - u32 src = data[(_h-1-y)*_w+x]; - float a = float(color_get_A(src))/255.f; - float inv_a = 1.f-a;; - u32 r = iFloor(float(color_get_R(src))*a+back.r*inv_a); - u32 g = iFloor(float(color_get_G(src))*a+back.g*inv_a); - u32 b = iFloor(float(color_get_B(src))*a+back.b*inv_a); - ptr[x] = color_rgba(r,g,b,0); + u32 *ptr = (u32*)pBitmap->ScanLine[y]; + for (int x = 0; xWidth; x++) + { + u32 src = data[(_h-1-y)*_w+x]; + float a = float(color_get_A(src))/255.f; + float inv_a = 1.f-a;; + u32 r = iFloor(float(color_get_R(src))*a+back.r*inv_a); + u32 g = iFloor(float(color_get_G(src))*a+back.g*inv_a); + u32 b = iFloor(float(color_get_B(src))*a+back.b*inv_a); + ptr[x] = color_rgba(r, g, b, 0); } } - }else{ - for (int y = 0; y < pBitmap->Height; y++) + } + else + { + for (int y = 0; yHeight; y++) { - u32* ptr = (u32*)pBitmap->ScanLine[y]; - Memory.mem_copy (ptr,&data[(_h-1-y)*_w],_w*4); + u32 *ptr = (u32*)pBitmap->ScanLine[y]; + Memory.mem_copy(ptr, &data[(_h-1-y)*_w], _w*4); } } - pCanvas->StretchDraw(r,pBitmap); + pCanvas->StretchDraw(r, pBitmap); xr_delete(pBitmap); } void __fastcall TTMinimapEditor::imgPanelPaint(TObject *Sender) { - if(image_data.size()==0) return; - - Irect R; - R.x1 = 0; - R.y1 = 0; - R.x2 = image_draw_size.x; - R.y2 = image_draw_size.y; -//. FHelper.DrawThumbnail(imgPanel->Canvas->Handle, R, &*image_data.begin(), image_w, image_h); - -/* - RECT R1; - R1.left = 0; - R1.top = 0; - R1.right = image_draw_size.x; - R1.bottom = image_draw_size.y; - DrawThumbnail(imgPanel->Canvas, R1, image_data, false, image_w, image_h); -*/ - float kw = (map_bb_loaded.max.x-map_bb_loaded.min.x) / (float)image_draw_size.x; - float kh = (map_bb_loaded.max.y-map_bb_loaded.min.y) / (float)image_draw_size.y; - - TRect R2; - R2.Left = iFloor((map_bb.min.x-map_bb_loaded.min.x)/kw); - R2.Top = iFloor((map_bb.min.y-map_bb_loaded.min.y)/kh); - R2.Right = R2.Left + iFloor((map_bb.max.x-map_bb.min.x)/kw); - R2.Bottom = R2.Top + iFloor((map_bb.max.y-map_bb.min.y)/kh); + if (image_data.size()==0) + return; + + Irect R; + R.x1 = 0; + R.y1 = 0; + R.x2 = image_draw_size.x; + R.y2 = image_draw_size.y; + //. FHelper.DrawThumbnail(imgPanel->Canvas->Handle, R, &*image_data.begin(), image_w, image_h); + + /* + RECT R1; + R1.left = 0; + R1.top = 0; + R1.right = image_draw_size.x; + R1.bottom = image_draw_size.y; + DrawThumbnail(imgPanel->Canvas, R1, image_data, false, image_w, image_h); + */ + float kw = (map_bb_loaded.max.x-map_bb_loaded.min.x)/(float)image_draw_size.x; + float kh = (map_bb_loaded.max.y-map_bb_loaded.min.y)/(float)image_draw_size.y; + + TRect R2; + R2.Left = iFloor((map_bb.min.x-map_bb_loaded.min.x)/kw); + R2.Top = iFloor((map_bb.min.y-map_bb_loaded.min.y)/kh); + R2.Right = R2.Left+iFloor((map_bb.max.x-map_bb.min.x)/kw); + R2.Bottom = R2.Top+iFloor((map_bb.max.y-map_bb.min.y)/kh); FHelper.DrawThumbnail(imgPanel->Canvas->Handle, R, &*image_data.begin(), image_w, image_h); @@ -194,50 +206,58 @@ void __fastcall TTMinimapEditor::imgPanelPaint(TObject *Sender) imgPanel->Canvas->Pen->Style = psSolid; imgPanel->Canvas->Rectangle(R2); } + //--------------------------------------------------------------------------- void __fastcall TTMinimapEditor::imgPanelResize(TObject *Sender) { - if(image_data.size()==0) return; - float _k_img = (float)image_w/(float)image_h; - float _k_panel = (float)imgPanel->Width/(float)imgPanel->Height; - - if(_k_img>_k_panel) - { //align to width - image_draw_size.set (imgPanel->Width, iFloor(imgPanel->Width/_k_img) ); - }else - { //align to height - image_draw_size.set (iFloor(imgPanel->Height*_k_img), imgPanel->Height); + if (image_data.size()==0) + return; + float _k_img = (float)image_w/(float)image_h; + float _k_panel = (float)imgPanel->Width/(float)imgPanel->Height; + + if (_k_img>_k_panel) + { //align to width + image_draw_size.set(imgPanel->Width, iFloor(imgPanel->Width/_k_img)); } - VERIFY (image_draw_size.x<=imgPanel->Width && image_draw_size.y<=imgPanel->Height); + else + { //align to height + image_draw_size.set(iFloor(imgPanel->Height*_k_img), imgPanel->Height); + } + VERIFY(image_draw_size.x<=imgPanel->Width&&image_draw_size.y<=imgPanel->Height); } + //--------------------------------------------------------------------------- void __fastcall TTMinimapEditor::imgPanelMouseDown(TObject *Sender, - TMouseButton Button, TShiftState Shift, int X, int Y) + TMouseButton Button, TShiftState Shift, int X, int Y) { - if(X>image_draw_size.x || Y>image_draw_size.y) return; - float kw = (map_bb_loaded.max.x-map_bb_loaded.min.x) / (float)image_draw_size.x; - float kh = (map_bb_loaded.max.y-map_bb_loaded.min.y) / (float)image_draw_size.y; - - if( X<(image_draw_size.x/2) && Y<(image_draw_size.y/2) ) - { //LT - map_bb.min.x = map_bb_loaded.min.x + X*kw; - map_bb.min.y = map_bb_loaded.min.y + Y*kh; - } - - if( X>(image_draw_size.x/2) && Y>(image_draw_size.y/2) ) - { //RB - map_bb.max.x = map_bb_loaded.min.x + X*kw; - map_bb.max.y = map_bb_loaded.min.y + Y*kh; - } - ApplyPoints (true); + if (X>image_draw_size.x||Y>image_draw_size.y) + return; + float kw = (map_bb_loaded.max.x-map_bb_loaded.min.x)/(float)image_draw_size.x; + float kh = (map_bb_loaded.max.y-map_bb_loaded.min.y)/(float)image_draw_size.y; + + if (X<(image_draw_size.x/2)&&Y<(image_draw_size.y/2)) + { //LT + map_bb.min.x = map_bb_loaded.min.x+X*kw; + map_bb.min.y = map_bb_loaded.min.y+Y*kh; + } + + if (X>(image_draw_size.x/2)&&Y>(image_draw_size.y/2)) + { //RB + map_bb.max.x = map_bb_loaded.min.x+X*kw; + map_bb.max.y = map_bb_loaded.min.y+Y*kh; + } + ApplyPoints(true); } + //--------------------------------------------------------------------------- void __fastcall TTMinimapEditor::ElFloatSpinEditX1Change(TObject *Sender) { - ApplyPoints (false); + ApplyPoints(false); } + //--------------------------------------------------------------------------- + diff --git a/src/editors/ECore/Editor/MinimapEditor.h b/src/editors/ECore/Editor/MinimapEditor.h index cadb55296a8..6d61cb93184 100644 --- a/src/editors/ECore/Editor/MinimapEditor.h +++ b/src/editors/ECore/Editor/MinimapEditor.h @@ -18,8 +18,8 @@ //--------------------------------------------------------------------------- class TTMinimapEditor : public TForm { -__published: // IDE-managed Components - TPanel *Panel1; + __published: // IDE-managed Components + TPanel*Panel1; TExtBtn *btnLoad; TMxPanel *imgPanel; TMxLabel *MxLabel1; @@ -34,26 +34,32 @@ class TTMinimapEditor : public TForm void __fastcall imgPanelPaint(TObject *Sender); void __fastcall imgPanelResize(TObject *Sender); void __fastcall imgPanelMouseDown(TObject *Sender, TMouseButton Button, - TShiftState Shift, int X, int Y); + TShiftState Shift, int X, int Y); void __fastcall ElFloatSpinEditX1Change(TObject *Sender); -private: // User declarations -static TTMinimapEditor* form; - U32Vec image_data; - u32 image_w; - u32 image_h; - u32 image_a; - Fbox2 map_bb; - Fbox2 map_bb_loaded; - Ivector2 image_draw_size; - void ApplyPoints(bool to_controls); -public: // User declarations - __fastcall TTMinimapEditor(TComponent* Owner); +private: // User declarations + static TTMinimapEditor *form; + U32Vec image_data; + u32 image_w; + u32 image_h; + u32 image_a; + Fbox2 map_bb; + Fbox2 map_bb_loaded; + Ivector2 image_draw_size; + void ApplyPoints(bool to_controls); +public: // User declarations + __fastcall TTMinimapEditor(TComponent *Owner); - static void __fastcall Show (); - static void __fastcall Hide (); - static bool __fastcall Visible (){return !!form;} + static void __fastcall Show(); + static void __fastcall Hide(); + + static bool __fastcall Visible() + { + return !!form; + } }; + //--------------------------------------------------------------------------- //. extern PACKAGE TTMinimapEditor *TMinimapEditor; //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/ParticleEffectActions.cpp b/src/editors/ECore/Editor/ParticleEffectActions.cpp index c9f82b14300..4fd270bf581 100644 --- a/src/editors/ECore/Editor/ParticleEffectActions.cpp +++ b/src/editors/ECore/Editor/ParticleEffectActions.cpp @@ -4,5 +4,5 @@ #include "ParticleEffectActions.h" -_CreateEAction pCreateEAction=0; +_CreateEAction pCreateEAction = 0; diff --git a/src/editors/ECore/Editor/ParticleEffectActions.h b/src/editors/ECore/Editor/ParticleEffectActions.h index a1b7ae9b499..b9733612ccc 100644 --- a/src/editors/ECore/Editor/ParticleEffectActions.h +++ b/src/editors/ECore/Editor/ParticleEffectActions.h @@ -2,358 +2,465 @@ #ifndef ParticleEffectActionsH #define ParticleEffectActionsH -struct PBool{ - BOOL val; - PBool ():val(FALSE){} - PBool (BOOL _val):val(_val){} - void set(BOOL v){val=v;} -}; -struct PFloat{ - float val; - float mn; - float mx; - PFloat () {val=0.f;mn=0.f;mx=0.f;} - PFloat (float _val, float _mn, float _mx):val(_val),mn(_mn),mx(_mx){} - void set(float v){val=v;} -}; -struct PInt{ - int val; - int mn; - int mx; - PInt () {val=0;mn=0;mx=0;} - PInt (int _val, int _mn, int _mx):val(_val),mn(_mn),mx(_mx){} - void set(int v){val=v;} -}; -struct PVector{ - Fvector val; - float mn; - float mx; - enum EType{ +struct PBool +{ + BOOL val; + + PBool(): val(FALSE) {} + + PBool(BOOL _val): val(_val) {} + + void set(BOOL v) + { + val = v; + } +}; + +struct PFloat +{ + float val; + float mn; + float mx; + + PFloat() + { + val = 0.f; + mn = 0.f; + mx = 0.f; + } + + PFloat(float _val, float _mn, float _mx): val(_val), mn(_mn), mx(_mx) {} + + void set(float v) + { + val = v; + } +}; + +struct PInt +{ + int val; + int mn; + int mx; + + PInt() + { + val = 0; + mn = 0; + mx = 0; + } + + PInt(int _val, int _mn, int _mx): val(_val), mn(_mn), mx(_mx) {} + + void set(int v) + { + val = v; + } +}; + +struct PVector +{ + Fvector val; + float mn; + float mx; + + enum EType + { vNum, vAngle, vColor, _force_u32 = u32(-1), }; - EType type; - PVector (){val.set(0,0,0);mn=0.f;mx=0.f;} - PVector (EType t, Fvector _val, float _mn, float _mx):type(t),val(_val),mn(_mn),mx(_mx){} - void set(const Fvector& v){val.set(v);} - void set(float x, float y, float z){val.set(x,y,z);} + + EType type; + + PVector() + { + val.set(0, 0, 0); + mn = 0.f; + mx = 0.f; + } + + PVector(EType t, Fvector _val, float _mn, float _mx): type(t), val(_val), mn(_mn), mx(_mx) {} + + void set(const Fvector &v) + { + val.set(v); + } + + void set(float x, float y, float z) + { + val.set(x, y, z); + } }; + struct PDomain { public: - PAPI::PDomainEnum type; - union{ - float f[9]; - Fvector v[3]; + PAPI::PDomainEnum type; + + union + { + float f[9]; + Fvector v[3]; }; - enum EType{ + + enum EType + { vNum, vAngle, vColor, _force_u32 = u32(-1), }; - enum { - flRenderable = (1<<0) + + enum + { + flRenderable = (1<<0) }; - EType e_type; - Flags32 flags; - u32 clr; + + EType e_type; + Flags32 flags; + u32 clr; protected: - void __stdcall PDomain::OnTypeChange(PropValue* sender); + void __stdcall PDomain::OnTypeChange(PropValue *sender); public: - PDomain (){} - PDomain (EType et, BOOL renderable, u32 color=0x00000000, PAPI::PDomainEnum type = PAPI::PDPoint, - float inA0 = 0.0f, float inA1 = 0.0f, float inA2 = 0.0f, - float inA3 = 0.0f, float inA4 = 0.0f, float inA5 = 0.0f, - float inA6 = 0.0f, float inA7 = 0.0f, float inA8 = 0.0f ); - ~PDomain (); - PDomain (const PDomain &in); - - void MoveXYZ (float x, float y, float z); - void RotateXYZ (float x, float y, float z); - void ScaleXYZ (float x, float y, float z); - - Fvector& GetCenter(); - - void Load (IReader& F); - void Save (IWriter& F); - - void Load2 (CInifile& ini, const shared_str& sect); - void Save2 (CInifile& ini, const shared_str& sect); - - void Render (u32 color, const Fmatrix& parent); - void FillProp (PropItemVec& items, LPCSTR pref, u32 clr); + PDomain() {} + + PDomain(EType et, BOOL renderable, u32 color = 0x00000000, PAPI::PDomainEnum type = PAPI::PDPoint, + float inA0 = 0.0f, float inA1 = 0.0f, float inA2 = 0.0f, + float inA3 = 0.0f, float inA4 = 0.0f, float inA5 = 0.0f, + float inA6 = 0.0f, float inA7 = 0.0f, float inA8 = 0.0f); + ~PDomain(); + PDomain(const PDomain &in); + + void MoveXYZ(float x, float y, float z); + void RotateXYZ(float x, float y, float z); + void ScaleXYZ(float x, float y, float z); + + Fvector &GetCenter(); + + void Load(IReader &F); + void Save(IWriter &F); + + void Load2(CInifile &ini, const shared_str §); + void Save2(CInifile &ini, const shared_str §); + + void Render(u32 color, const Fmatrix &parent); + void FillProp(PropItemVec &items, LPCSTR pref, u32 clr); }; + struct EParticleAction { - DEFINE_MAP(AnsiString,PDomain, PDomainMap, PDomainMapIt); - DEFINE_MAP(AnsiString,PBool, PBoolMap, PBoolMapIt); - DEFINE_MAP(AnsiString,PFloat, PFloatMap, PFloatMapIt); - DEFINE_MAP(AnsiString,PInt, PIntMap, PIntMapIt); - DEFINE_MAP(AnsiString,PVector, PVectorMap, PVectorMapIt); - - shared_str actionName; - shared_str actionType; - shared_str hint; - enum{ - flEnabled = (1<<0), - flDraw = (1<<1), + DEFINE_MAP(AnsiString, PDomain, PDomainMap, PDomainMapIt); + DEFINE_MAP(AnsiString, PBool, PBoolMap, PBoolMapIt); + DEFINE_MAP(AnsiString, PFloat, PFloatMap, PFloatMapIt); + DEFINE_MAP(AnsiString, PInt, PIntMap, PIntMapIt); + DEFINE_MAP(AnsiString, PVector, PVectorMap, PVectorMapIt); + + shared_str actionName; + shared_str actionType; + shared_str hint; + + enum + { + flEnabled = (1<<0), + flDraw = (1<<1), }; - Flags32 flags; - PAPI::PActionEnum type; - PDomainMap domains; - PBoolMap bools; - PFloatMap floats; - PIntMap ints; - PVectorMap vectors; + Flags32 flags; + PAPI::PActionEnum type; + + PDomainMap domains; + PBoolMap bools; + PFloatMap floats; + PIntMap ints; + PVectorMap vectors; - enum EValType{ - tpDomain, + enum EValType + { + tpDomain, tpVector, tpFloat, tpBool, tpInt, }; - struct SOrder{ - EValType type; - AnsiString name; - SOrder(EValType _type, AnsiString _name):type(_type),name(_name){} + + struct SOrder + { + EValType type; + AnsiString name; + + SOrder(EValType _type, AnsiString _name): type(_type), name(_name) {} }; - DEFINE_VECTOR (SOrder, OrderVec, OrderVecIt); - OrderVec orders; - - EParticleAction (PAPI::PActionEnum _type) + + DEFINE_VECTOR(SOrder, OrderVec, OrderVecIt); + OrderVec orders; + + EParticleAction(PAPI::PActionEnum _type) + { + flags.assign(flEnabled); + type = _type; + } + +public: + void appendFloat(LPCSTR name, float v, float mn, float mx); + void appendInt(LPCSTR name, int v, int mn = -P_MAXINT, int mx = P_MAXINT); + void appendVector(LPCSTR name, PVector::EType type, float vx, float vy, float vz, float mn = -P_MAXFLOAT, float mx = P_MAXFLOAT); + void appendDomain(LPCSTR name, PDomain v); + void appendBool(LPCSTR name, BOOL b); + + PFloat &_float(LPCSTR name) + { + PFloatMapIt it = floats.find(name); + R_ASSERT2(it!=floats.end(), name); + return it->second; + } + + PInt &_int(LPCSTR name) + { + PIntMapIt it = ints.find(name); + R_ASSERT2(it!=ints.end(), name); + return it->second; + } + + PVector &_vector(LPCSTR name) + { + PVectorMapIt it = vectors.find(name); + R_ASSERT2(it!=vectors.end(), name); + return it->second; + } + + PDomain &_domain(LPCSTR name) { - flags.assign(flEnabled); - type = _type; + PDomainMapIt it = domains.find(name); + R_ASSERT2(it!=domains.end(), name); + return it->second; } + + PBool &_bool(LPCSTR name) + { + PBoolMapIt it = bools.find(name); + R_ASSERT2(it!=bools.end(), name); + return it->second; + } + + PBool *_bool_safe(LPCSTR name) + { + PBoolMapIt it = bools.find(name); + return (it!=bools.end()) ? &it->second : 0; + } + public: - void appendFloat (LPCSTR name, float v, float mn, float mx); - void appendInt (LPCSTR name, int v, int mn=-P_MAXINT, int mx=P_MAXINT); - void appendVector(LPCSTR name, PVector::EType type, float vx, float vy, float vz, float mn=-P_MAXFLOAT, float mx=P_MAXFLOAT); - void appendDomain(LPCSTR name, PDomain v); - void appendBool (LPCSTR name, BOOL b); - PFloat& _float (LPCSTR name){PFloatMapIt it=floats.find(name); R_ASSERT2(it!=floats.end(),name); return it->second;} - PInt& _int (LPCSTR name){PIntMapIt it=ints.find(name); R_ASSERT2(it!=ints.end(),name); return it->second;} - PVector& _vector (LPCSTR name){PVectorMapIt it=vectors.find(name); R_ASSERT2(it!=vectors.end(),name); return it->second;} - PDomain& _domain (LPCSTR name){PDomainMapIt it=domains.find(name); R_ASSERT2(it!=domains.end(),name); return it->second;} - PBool& _bool (LPCSTR name){PBoolMapIt it=bools.find(name); R_ASSERT2(it!=bools.end(),name); return it->second;} - PBool* _bool_safe (LPCSTR name){PBoolMapIt it=bools.find(name); return (it!=bools.end())?&it->second:0;} -public: - virtual void Compile (IWriter& F)=0; - virtual void FillProp (PropItemVec& items, LPCSTR pref, u32 clr); - - virtual void Load (IReader& F); - virtual void Save (IWriter& F); - virtual void Load2 (CInifile& ini, const shared_str& sect); - virtual void Save2 (CInifile& ini, const shared_str& sect); - virtual void Render (const Fmatrix& parent); + virtual void Compile(IWriter &F) =0; + virtual void FillProp(PropItemVec &items, LPCSTR pref, u32 clr); + + virtual void Load(IReader &F); + virtual void Save(IWriter &F); + virtual void Load2(CInifile &ini, const shared_str §); + virtual void Save2(CInifile &ini, const shared_str §); + virtual void Render(const Fmatrix &parent); }; struct EPAAvoid : public EParticleAction { - EPAAvoid (); - virtual void Compile (IWriter& F); + EPAAvoid(); + virtual void Compile(IWriter &F); }; - + struct EPABounce : public EParticleAction { - EPABounce (); - virtual void Compile (IWriter& F); + EPABounce(); + virtual void Compile(IWriter &F); }; struct EPACopyVertexB : public EParticleAction { - EPACopyVertexB(); - virtual void Compile (IWriter& F); + EPACopyVertexB(); + virtual void Compile(IWriter &F); }; struct EPADamping : public EParticleAction { - EPADamping (); - virtual void Compile (IWriter& F); + EPADamping(); + virtual void Compile(IWriter &F); }; struct EPAExplosion : public EParticleAction { - EPAExplosion(); - virtual void Compile (IWriter& F); + EPAExplosion(); + virtual void Compile(IWriter &F); }; struct EPAFollow : public EParticleAction { - EPAFollow (); - virtual void Compile (IWriter& F); + EPAFollow(); + virtual void Compile(IWriter &F); }; struct EPAGravitate : public EParticleAction { - EPAGravitate(); - virtual void Compile (IWriter& F); + EPAGravitate(); + virtual void Compile(IWriter &F); }; struct EPAGravity : public EParticleAction { - EPAGravity (); - virtual void Compile (IWriter& F); + EPAGravity(); + virtual void Compile(IWriter &F); }; struct EPAJet : public EParticleAction { - EPAJet (); - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPAJet(); + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; struct EPAKillOld : public EParticleAction { - EPAKillOld (); - virtual void Compile (IWriter& F); + EPAKillOld(); + virtual void Compile(IWriter &F); }; struct EPAMatchVelocity : public EParticleAction { - EPAMatchVelocity(); - virtual void Compile (IWriter& F); + EPAMatchVelocity(); + virtual void Compile(IWriter &F); }; struct EPAMove : public EParticleAction { - EPAMove (); - virtual void Compile (IWriter& F); + EPAMove(); + virtual void Compile(IWriter &F); }; struct EPAOrbitLine : public EParticleAction { - EPAOrbitLine(); - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPAOrbitLine(); + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; struct EPAOrbitPoint : public EParticleAction { - EPAOrbitPoint(); - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPAOrbitPoint(); + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; struct EPARandomAccel : public EParticleAction { - EPARandomAccel(); - virtual void Compile (IWriter& F); + EPARandomAccel(); + virtual void Compile(IWriter &F); }; struct EPARandomDisplace : public EParticleAction { - EPARandomDisplace(); - virtual void Compile (IWriter& F); + EPARandomDisplace(); + virtual void Compile(IWriter &F); }; struct EPARandomVelocity : public EParticleAction { - EPARandomVelocity(); - virtual void Compile (IWriter& F); + EPARandomVelocity(); + virtual void Compile(IWriter &F); }; struct EPARestore : public EParticleAction { - EPARestore (); - virtual void Compile (IWriter& F); + EPARestore(); + virtual void Compile(IWriter &F); }; struct EPAScatter : public EParticleAction { - EPAScatter (); - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPAScatter(); + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; struct EPASink : public EParticleAction { - EPASink (); - virtual void Compile (IWriter& F); + EPASink(); + virtual void Compile(IWriter &F); }; struct EPASinkVelocity : public EParticleAction { - EPASinkVelocity(); - virtual void Compile (IWriter& F); + EPASinkVelocity(); + virtual void Compile(IWriter &F); }; struct EPASpeedLimit : public EParticleAction { - EPASpeedLimit(); - virtual void Compile (IWriter& F); + EPASpeedLimit(); + virtual void Compile(IWriter &F); }; struct EPASource : public EParticleAction { - EPASource (); - virtual void Compile (IWriter& F); + EPASource(); + virtual void Compile(IWriter &F); }; struct EPATargetColor : public EParticleAction { - EPATargetColor(); - virtual void Compile (IWriter& F); + EPATargetColor(); + virtual void Compile(IWriter &F); }; struct EPATargetSize : public EParticleAction { - EPATargetSize(); - virtual void Compile (IWriter& F); + EPATargetSize(); + virtual void Compile(IWriter &F); }; struct EPATargetRotate : public EParticleAction { - EPATargetRotate(); - virtual void Compile (IWriter& F); + EPATargetRotate(); + virtual void Compile(IWriter &F); }; struct EPATargetVelocity : public EParticleAction { - EPATargetVelocity(); - virtual void Compile (IWriter& F); + EPATargetVelocity(); + virtual void Compile(IWriter &F); }; struct EPAVortex : public EParticleAction { - EPAVortex (); - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPAVortex(); + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; struct EPATurbulence : public EParticleAction { - float ***nval; - float age; + float ***nval; + float age; public: - EPATurbulence(); - - virtual void Compile (IWriter& F); - virtual void Render (const Fmatrix& parent); + EPATurbulence(); + + virtual void Compile(IWriter &F); + virtual void Render(const Fmatrix &parent); }; -extern xr_token2 actions_token[]; +extern xr_token2 actions_token[]; -typedef EParticleAction* (*_CreateEAction)(PAPI::PActionEnum type); -extern ECORE_API _CreateEAction pCreateEAction; +typedef EParticleAction * (*_CreateEAction)(PAPI::PActionEnum type); +extern ECORE_API _CreateEAction pCreateEAction; //--------------------------------------------------------------------------- #endif /* - void pTargetVelocityD(float scale, PDomainEnum dtype, - float a0 = 0.0f, float a1 = 0.0f, float a2 = 0.0f, - float a3 = 0.0f, float a4 = 0.0f, float a5 = 0.0f, - float a6 = 0.0f, float a7 = 0.0f, float a8 = 0.0f, BOOL allow_translate=TRUE, BOOL allow_rotate=TRUE); + void pTargetVelocityD(float scale, PDomainEnum dtype, + float a0 = 0.0f, float a1 = 0.0f, float a2 = 0.0f, + float a3 = 0.0f, float a4 = 0.0f, float a5 = 0.0f, + float a6 = 0.0f, float a7 = 0.0f, float a8 = 0.0f, BOOL allow_translate=TRUE, BOOL allow_rotate=TRUE); - void pVertex(float x, float y, float z); + void pVertex(float x, float y, float z); } */ - diff --git a/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.cpp b/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.cpp index 7e5724eff74..79ffa6d52a6 100644 --- a/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.cpp +++ b/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.cpp @@ -2,8 +2,9 @@ #pragma hdrstop #include "PhysicsShellHolderEditorBase.h" -#include "../../xrphysics/physicsshell.h" -# include "GameMtlLib.h" +#include "xrPhysics/PhysicsShell.h" +#include "xrEngine/GameMtlLib.h" + //CObjectList Objects; static void SetBoneMaterials( IKinematics &K ) { diff --git a/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.h b/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.h index b75d67e1ca1..383c4e3ee27 100644 --- a/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.h +++ b/src/editors/ECore/Editor/PhysicsShellHolderEditorBase.h @@ -1,7 +1,7 @@ #ifndef _PHYSICS_SHELL_HOLDER_EDITOR_BASE_ #define _PHYSICS_SHELL_HOLDER_EDITOR_BASE_ -#include "../../../xrphysics/iphysicsshellholder.h" +#include "xrPhysics/IPhysicsShellHolder.h" class ECORE_API CPhysicsShellHolderEditorBase: public IPhysicsShellHolder { diff --git a/src/editors/ECore/Editor/PropSlimTools.h b/src/editors/ECore/Editor/PropSlimTools.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/PropSlimTools.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/SkeletonFace.h b/src/editors/ECore/Editor/SkeletonFace.h index 90260758b90..127f5af58e1 100644 --- a/src/editors/ECore/Editor/SkeletonFace.h +++ b/src/editors/ECore/Editor/SkeletonFace.h @@ -5,30 +5,42 @@ #include "SkeletonVert.h" struct st_SFACE; -void RegisterSFACE(st_SFACE* f); - -struct st_SFACE { - st_SVERT* v[3]; - DWORD m; - - st_SFACE(){ - RegisterSFACE(this); - } - void VSet(int id, st_SVERT* V){ - v[id]=V; - } - void SetVerts(st_SVERT* v1, st_SVERT* v2, st_SVERT* v3) - { - VSet(0,v1); - VSet(1,v2); - VSet(2,v3); - } - void ReplaceVert(st_SVERT* from, st_SVERT* to) - { - if (v[0]==from) VSet(0,to); - if (v[1]==from) VSet(1,to); - if (v[2]==from) VSet(2,to); - } +void RegisterSFACE(st_SFACE *f); + +struct st_SFACE +{ + st_SVERT *v[3]; + DWORD m; + + st_SFACE() + { + RegisterSFACE(this); + } + + void VSet(int id, st_SVERT *V) + { + v[id] = V; + } + + void SetVerts(st_SVERT *v1, st_SVERT *v2, st_SVERT *v3) + { + VSet(0, v1); + VSet(1, v2); + VSet(2, v3); + } + + void ReplaceVert(st_SVERT *from, st_SVERT *to) + { + if (v[0]==from) + VSet(0, to); + if (v[1]==from) + VSet(1, to); + if (v[2]==from) + VSet(2, to); + } }; -DEFINE_VECTOR(st_SFACE*,vSFACE,SFACEIt); + +DEFINE_VECTOR(st_SFACE *, vSFACE, SFACEIt); #endif // _SkeletonFace_H_ + + diff --git a/src/editors/ECore/Editor/SkeletonVert.h b/src/editors/ECore/Editor/SkeletonVert.h index 9fb07157660..6e97fad9cfa 100644 --- a/src/editors/ECore/Editor/SkeletonVert.h +++ b/src/editors/ECore/Editor/SkeletonVert.h @@ -3,45 +3,66 @@ #pragma once struct st_SVERT; -void RegisterSVERT(st_SVERT* v); +void RegisterSVERT(st_SVERT *v); -const DWORD BONE_NONE = 0xffffffff; +const DWORD BONE_NONE = 0xffffffff; -struct st_SVERT { - Fvector P; - Fvector O; - Fvector N; - DWORD sm_group; +struct st_SVERT +{ + Fvector P; + Fvector O; + Fvector N; + DWORD sm_group; Fvector2Vec uv; - DWORD bone; + DWORD bone; - st_SVERT(){ - P.set (0,0,0); - N.set (0,1,0); + st_SVERT() + { + P.set(0, 0, 0); + N.set(0, 1, 0); uv.clear(); - bone = BONE_NONE; - RegisterSVERT(this); - } - void AppendUV(float _u, float _v){ - uv.push_back(Fvector2()); - uv.back().set(_u,_v); - } - void SetBone(DWORD B){ - if (bone==BONE_NONE){ - bone = B; - } else R_ASSERT(bone==B); - } - BOOL similar(st_SVERT& V){ - if (bone!=V.bone) return FALSE; - if (uv.size()!=V.uv.size()) return FALSE; - for(DWORD i=0; iSetModifiedEvent (fastdelegate::bind(this,&TfrmSoundLib::OnModified)); - m_ItemList = TItemList::CreateForm ("Items",paItems,alClient,TItemList::ilMultiSelect/*|TItemList::ilEditMenu|TItemList::ilDragAllowed*/); - m_ItemList->SetOnItemsFocusedEvent (fastdelegate::bind(this,&TfrmSoundLib::OnItemsFocused)); - TOnItemRemove on_remove; on_remove.bind (this,&TfrmSoundLib::RemoveSound); - TOnItemRename on_rename; on_rename.bind (this,&TfrmSoundLib::RenameSound); - m_ItemList->SetOnItemRemoveEvent (on_remove); - m_ItemList->SetOnItemRenameEvent (on_rename); - m_ItemList->SetImages (ImageList); - bAutoPlay = FALSE; + m_ItemProps = TProperties::CreateForm("SoundED", paProperties, alClient); + m_ItemProps->SetModifiedEvent(fastdelegate::bind(this, &TfrmSoundLib::OnModified)); + m_ItemList = TItemList::CreateForm("Items", paItems, alClient, TItemList::ilMultiSelect/*|TItemList::ilEditMenu|TItemList::ilDragAllowed*/); + m_ItemList->SetOnItemsFocusedEvent(fastdelegate::bind(this, &TfrmSoundLib::OnItemsFocused)); + TOnItemRemove on_remove; + on_remove.bind(this, &TfrmSoundLib::RemoveSound); + TOnItemRename on_rename; + on_rename.bind(this, &TfrmSoundLib::RenameSound); + m_ItemList->SetOnItemRemoveEvent(on_remove); + m_ItemList->SetOnItemRenameEvent(on_rename); + m_ItemList->SetImages(ImageList); + bAutoPlay = FALSE; } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::FormDestroy(TObject *Sender) { TProperties::DestroyForm(m_ItemProps); - TItemList::DestroyForm (m_ItemList); - m_Snd.destroy (); + TItemList::DestroyForm(m_ItemList); + m_Snd.destroy(); } + //--------------------------------------------------------------------------- -void __fastcall TfrmSoundLib::EditLib(AnsiString& title) +void __fastcall TfrmSoundLib::EditLib(AnsiString &title) { - if (!form){ - form = xr_new((TComponent*)0); - form->Caption = title; - form->modif_map.clear(); - m_Flags.zero (); - form->InitItemsList (); - if (!FS.can_write_to_alias(_sounds_)){ - Log ("#!You don't have permisions to modify sounds."); - form->ebOk->Enabled = false; - form->m_ItemProps->SetReadOnly (TRUE); - m_Flags.set (flReadOnly,TRUE); - form->bAutoPlay = TRUE; + if (!form) + { + form = xr_new((TComponent*)0); + form->Caption = title; + form->modif_map.clear(); + m_Flags.zero(); + form->InitItemsList(); + if (!FS.can_write_to_alias(_sounds_)) + { + Log("#!You don't have permisions to modify sounds."); + form->ebOk->Enabled = false; + form->m_ItemProps->SetReadOnly(TRUE); + m_Flags.set(flReadOnly, TRUE); + form->bAutoPlay = TRUE; } } - form->ShowModal (); - UI->RedrawScene (); + form->ShowModal(); + UI->RedrawScene(); } + //--------------------------------------------------------------------------- void TfrmSoundLib::OnModified() { - m_ItemProps->RefreshForm(); + m_ItemProps->RefreshForm(); } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::UpdateLib() { - RegisterModifiedTHM (); - SaveUsedTHM (); + RegisterModifiedTHM(); + SaveUsedTHM(); // save game sounds - if (modif_map.size()){ - AStringVec modif; - LockForm (); - SndLib->SynchronizeSounds (true,true,true,&modif_map,0); -// SndLib->ChangeFileAgeTo (&modif_map,time(NULL)); - UnlockForm (); + if (modif_map.size()) + { + AStringVec modif; + LockForm(); + SndLib->SynchronizeSounds(true, true, true, &modif_map, 0); + // SndLib->ChangeFileAgeTo (&modif_map,time(NULL)); + UnlockForm(); SndLib->RefreshSounds(false); - modif_map.clear (); + modif_map.clear(); } } bool __fastcall TfrmSoundLib::HideLib() { - if (form){ - form->Close(); - modif_map.clear(); + if (form) + { + form->Close(); + modif_map.clear(); } return true; } + //--------------------------------------------------------------------------- void TfrmSoundLib::AppendModif(LPCSTR nm) { - FS_File dest; - string_path fname; - FS.update_path (fname,_sounds_,ChangeFileExt(nm,".wav").c_str()); - BOOL bFind = FS.file_find(fname,dest); R_ASSERT(bFind); + FS_File dest; + string_path fname; + FS.update_path(fname, _sounds_, ChangeFileExt(nm, ".wav").c_str()); + BOOL bFind = FS.file_find(fname, dest); + R_ASSERT(bFind); modif_map.insert(dest); } + //--------------------------------------------------------------------------- -void TfrmSoundLib::RemoveSound(LPCSTR fname, EItemType type, bool& res) +void TfrmSoundLib::RemoveSound(LPCSTR fname, EItemType type, bool &res) { - // delete it from modif map - FS_FileSetIt it=modif_map.find(FS_File(fname)); - if (it!=modif_map.end()) modif_map.erase(it); - // remove sound source - res = SndLib->RemoveSound(fname,type); + // delete it from modif map + FS_FileSetIt it = modif_map.find(FS_File(fname)); + if (it!=modif_map.end()) + modif_map.erase(it); + // remove sound source + res = SndLib->RemoveSound(fname, type); } + //--------------------------------------------------------------------------- void TfrmSoundLib::RenameSound(LPCSTR p0, LPCSTR p1, EItemType type) { // rename sound source - SndLib->RenameSound(p0,p1,type); - // delete old from map - FS_FileSetIt old_it=modif_map.find(FS_File(p0)); - if (old_it!=modif_map.end()){ - modif_map.erase (old_it); - AppendModif (p1); - } + SndLib->RenameSound(p0, p1, type); + // delete old from map + FS_FileSetIt old_it = modif_map.find(FS_File(p0)); + if (old_it!=modif_map.end()) + { + modif_map.erase(old_it); + AppendModif(p1); + } } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::FormShow(TObject *Sender) { - // check window position - UI->CheckWindowPos (this); + // check window position + UI->CheckWindowPos(this); } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::FormClose(TObject *Sender, TCloseAction &Action) { - if (!form) return; - form->Enabled = false; - DestroyUsedTHM (); - form = 0; - Action = caFree; + if (!form) + return; + form->Enabled = false; + DestroyUsedTHM(); + form = 0; + Action = caFree; } + //--------------------------------------------------------------------------- void TfrmSoundLib::InitItemsList() { - FS_FileSet sound_map; - SndLib->GetSounds(sound_map,TRUE); + FS_FileSet sound_map; + SndLib->GetSounds(sound_map, TRUE); - ListItemsVec items; + ListItemsVec items; // fill items - FS_FileSetIt it = sound_map.begin(); - FS_FileSetIt _E = sound_map.end(); + FS_FileSetIt it = sound_map.begin(); + FS_FileSetIt _E = sound_map.end(); for (; it!=_E; it++) - LHelper().CreateItem(items,it->name.c_str(),0); + LHelper().CreateItem(items, it->name.c_str(), 0); - m_ItemList->AssignItems(items,false,true); + m_ItemList->AssignItems(items, false, true); } //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::FormKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift) -{ - if (Shift.Contains(ssCtrl)){ - if (Key==VK_CANCEL) ExecCommand(COMMAND_BREAK_LAST_OPERATION); - }else{ - if (Key==VK_ESCAPE){ - if (bFormLocked) ExecCommand(COMMAND_BREAK_LAST_OPERATION); + TShiftState Shift) +{ + if (Shift.Contains(ssCtrl)) + { + if (Key==VK_CANCEL) + ExecCommand(COMMAND_BREAK_LAST_OPERATION); + } + else + { + if (Key==VK_ESCAPE) + { + if (bFormLocked) + ExecCommand(COMMAND_BREAK_LAST_OPERATION); Key = 0; // :-) нужно для того чтобы AccessVoilation не вылазил по ESCAPE } } } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::ebOkClick(TObject *Sender) { - if (bFormLocked) return; - m_Snd.destroy (); - - UpdateLib (); - HideLib (); + if (bFormLocked) + return; + m_Snd.destroy(); + + UpdateLib(); + HideLib(); } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::ebCancelClick(TObject *Sender) { - if (bFormLocked){ - ExecCommand(COMMAND_BREAK_LAST_OPERATION); - return; + if (bFormLocked) + { + ExecCommand(COMMAND_BREAK_LAST_OPERATION); + return; } - HideLib (); + HideLib(); } + //--------------------------------------------------------------------------- -ESoundThumbnail* TfrmSoundLib::FindUsedTHM(LPCSTR name) +ESoundThumbnail *TfrmSoundLib::FindUsedTHM(LPCSTR name) { - for (THMIt it=m_THM_Used.begin(); it!=m_THM_Used.end(); it++) - if (0==strcmp((*it)->SrcName(),name)) return *it; + for (THMIt it = m_THM_Used.begin(); it!=m_THM_Used.end(); it++) + if (0==strcmp((*it)->SrcName(), name)) + return *it; return 0; } + //--------------------------------------------------------------------------- void TfrmSoundLib::SaveUsedTHM() { - int m_age = time(NULL); - for (THMIt t_it=m_THM_Used.begin(); t_it!=m_THM_Used.end(); t_it++) - (*t_it)->Save(m_age,0); + int m_age = time(NULL); + for (THMIt t_it = m_THM_Used.begin(); t_it!=m_THM_Used.end(); t_it++) + (*t_it)->Save(m_age, 0); } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::RegisterModifiedTHM() { - if (m_ItemProps->IsModified()){ - for (THMIt t_it=m_THM_Current.begin(); t_it!=m_THM_Current.end(); t_it++){ -//. (*t_it)->Save (0,0); - AppendModif ((*t_it)->SrcName()); + if (m_ItemProps->IsModified()) + { + for (THMIt t_it = m_THM_Current.begin(); t_it!=m_THM_Current.end(); t_it++) + { + //. (*t_it)->Save (0,0); + AppendModif((*t_it)->SrcName()); } } } void __fastcall TfrmSoundLib::fsStorageRestorePlacement(TObject *Sender) { - m_ItemProps->RestoreParams(fsStorage); + m_ItemProps->RestoreParams(fsStorage); m_ItemList->LoadParams(fsStorage); - if (!m_Flags.is(flReadOnly)){ - bAutoPlay = fsStorage->ReadInteger("auto_play",FALSE); + if (!m_Flags.is(flReadOnly)) + { + bAutoPlay = fsStorage->ReadInteger("auto_play", FALSE); } } + //--------------------------------------------------------------------------- void __fastcall TfrmSoundLib::fsStorageSavePlacement(TObject *Sender) { - m_ItemProps->SaveParams(fsStorage); + m_ItemProps->SaveParams(fsStorage); m_ItemList->SaveParams(fsStorage); - if (!m_Flags.is(flReadOnly)){ - fsStorage->WriteInteger("auto_play",bAutoPlay); + if (!m_Flags.is(flReadOnly)) + { + fsStorage->WriteInteger("auto_play", bAutoPlay); } } + //--------------------------------------------------------------------------- -void __fastcall TfrmSoundLib::OnControlClick(ButtonValue* V, bool& bModif, bool& bSafe) +void __fastcall TfrmSoundLib::OnControlClick(ButtonValue *V, bool &bModif, bool &bSafe) { - switch (V->btn_num){ - case 0: m_Snd.play(0,sm_2D); break; - case 1: m_Snd.stop(); break; - case 2:{ - bAutoPlay=!bAutoPlay; - V->value[V->btn_num] = shared_str().printf("Auto (%s)",bAutoPlay?"on":"off"); - }break; - } + switch (V->btn_num) + { + case 0: m_Snd.play(0, sm_2D); + break; + case 1: m_Snd.stop(); + break; + case 2: + { + bAutoPlay = !bAutoPlay; + V->value[V->btn_num] = shared_str().printf("Auto (%s)", bAutoPlay ? "on" : "off"); + } + break; + } bModif = false; } + //------------------------------------------------------------------------------ -void __fastcall TfrmSoundLib::OnControl2Click(ButtonValue* V, bool& bModif, bool& bSafe) +void __fastcall TfrmSoundLib::OnControl2Click(ButtonValue *V, bool &bModif, bool &bSafe) { - switch (V->btn_num){ - case 0:{ - bAutoPlay=!bAutoPlay; - V->value[V->btn_num] = bAutoPlay?"on":"off"; - }break; - } + switch (V->btn_num) + { + case 0: + { + bAutoPlay = !bAutoPlay; + V->value[V->btn_num] = bAutoPlay ? "on" : "off"; + } + break; + } bModif = false; } + //------------------------------------------------------------------------------ void TfrmSoundLib::DestroyUsedTHM() { - for (THMIt it=m_THM_Used.begin(); it!=m_THM_Used.end(); it++) - xr_delete(*it); + for (THMIt it = m_THM_Used.begin(); it!=m_THM_Used.end(); it++) + xr_delete(*it); m_THM_Used.clear(); } + //------------------------------------------------------------------------------ #define X_GRID 10 #define Y_GRID 5 -void TfrmSoundLib::OnAttenuationDraw(CanvasValue* sender, void* _canvas, const Irect& _rect) + +void TfrmSoundLib::OnAttenuationDraw(CanvasValue *sender, void *_canvas, const Irect &_rect) { - TCanvas* canvas = (TCanvas*)_canvas; - const TRect& rect = *((TRect*)&_rect); -// canvas + TCanvas *canvas = (TCanvas*)_canvas; + const TRect &rect = *((TRect*)&_rect); + // canvas int w = rect.Width(); int h = rect.Height(); - int x0= rect.left; - int y0= rect.top; + int x0 = rect.left; + int y0 = rect.top; canvas->Brush->Color = clBlack; canvas->FillRect(rect); canvas->Pen->Color = TColor(0x00006600); - canvas->MoveTo(x0,y0); - for (int i=0; iLineTo(x0+i*w/X_GRID,y0+h); - canvas->MoveTo(x0+(i+1)*w/X_GRID,y0+0); + canvas->MoveTo(x0, y0); + for (int i = 0; iLineTo(x0+i*w/X_GRID, y0+h); + canvas->MoveTo(x0+(i+1)*w/X_GRID, y0+0); } - canvas->MoveTo(x0+0,y0+0); - for (int j=0; jLineTo(x0+w,y0+j*h/Y_GRID); - canvas->MoveTo(x0+0,y0+(j+1)*h/Y_GRID); + canvas->MoveTo(x0+0, y0+0); + for (int j = 0; jLineTo(x0+w, y0+j*h/Y_GRID); + canvas->MoveTo(x0+0, y0+(j+1)*h/Y_GRID); } canvas->Pen->Color = clYellow; - canvas->MoveTo(x0+0,y0+iFloor(float(h)-float(h)*0.01f)); // snd cull = 0.01f - canvas->LineTo(x0+w,y0+iFloor(float(h)-float(h)*0.01f)); + canvas->MoveTo(x0+0, y0+iFloor(float(h)-float(h)*0.01f)); // snd cull = 0.01f + canvas->LineTo(x0+w, y0+iFloor(float(h)-float(h)*0.01f)); - ESoundThumbnail* thm = m_THM_Current.back(); - float d_cost = thm->MaxDist()/w; + ESoundThumbnail*thm = m_THM_Current.back(); + float d_cost = thm->MaxDist()/w; AnsiString temp; -// float v = m_D3D.range; -// temp.sprintf("Range = %.2f",v); lbRange->Caption = temp; + // float v = m_D3D.range; + // temp.sprintf("Range = %.2f",v); lbRange->Caption = temp; canvas->Pen->Color = clLime; - for (int d=1; dMinDist()/(psSoundRolloff*R); -// float b = m_Brightness/(m_Attenuation0+m_Attenuation1*R+m_Attenuation2*R*R); + float b = thm->MinDist()/(psSoundRolloff*R); + // float b = m_Brightness/(m_Attenuation0+m_Attenuation1*R+m_Attenuation2*R*R); float bb = h-(h*b); - int y = iFloor(y0+bb); clamp(y,int(rect.Top),int(rect.Bottom)); - if (1==d) canvas->MoveTo(x0+d,y); - else canvas->LineTo(x0+d,y); + int y = iFloor(y0+bb); + clamp(y, int(rect.Top), int(rect.Bottom)); + if (1==d) + canvas->MoveTo(x0+d, y); + else + canvas->LineTo(x0+d, y); } } -void __stdcall TfrmSoundLib::OnAttClick(ButtonValue* V, bool& bModif, bool& bSafe) +void __stdcall TfrmSoundLib::OnAttClick(ButtonValue *V, bool &bModif, bool &bSafe) { bModif = true; - ESoundThumbnail* thm = m_THM_Current.back(); - switch (V->btn_num){ - case 0:{ - float dist = thm->MinDist()/(0.01f*psSoundRolloff); - thm->SetMaxDist (dist+0.1f*dist); - }break; - case 1:{ - float dist = psSoundRolloff*(thm->MaxDist()-(0.1f/1.1f)*thm->MaxDist())*0.01f; - thm->SetMinDist (dist); - }break; - } + ESoundThumbnail*thm = m_THM_Current.back(); + switch (V->btn_num) + { + case 0: + { + float dist = thm->MinDist()/(0.01f*psSoundRolloff); + thm->SetMaxDist(dist+0.1f*dist); + } + break; + case 1: + { + float dist = psSoundRolloff*(thm->MaxDist()-(0.1f/1.1f)*thm->MaxDist())*0.01f; + thm->SetMinDist(dist); + } + break; + } } -void __fastcall TfrmSoundLib::OnItemsFocused(ListItemsVec& items) +void __fastcall TfrmSoundLib::OnItemsFocused(ListItemsVec &items) { - PropItemVec props; - - RegisterModifiedTHM (); - m_Snd.destroy (); - m_THM_Current.clear (); - - if (!items.empty()){ - for (ListItemsIt it=items.begin(); it!=items.end(); it++){ - ListItem* prop = *it; - if (prop){ - ESoundThumbnail* thm=FindUsedTHM(prop->Key()); - if (!thm) m_THM_Used.push_back(thm=xr_new(prop->Key())); + PropItemVec props; + + RegisterModifiedTHM(); + m_Snd.destroy(); + m_THM_Current.clear(); + + if (!items.empty()) + { + for (ListItemsIt it = items.begin(); it!=items.end(); it++) + { + ListItem *prop = *it; + if (prop) + { + ESoundThumbnail*thm = FindUsedTHM(prop->Key()); + if (!thm) + m_THM_Used.push_back(thm = xr_new(prop->Key())); m_THM_Current.push_back(thm); - thm->FillProp (props); + thm->FillProp(props); } } } - ButtonValue* B=0; + ButtonValue *B = 0; if (m_THM_Current.size()==1) { - ESoundThumbnail* thm=m_THM_Current.back(); - u32 size=0; - u32 time=0; + ESoundThumbnail*thm = m_THM_Current.back(); + u32 size = 0; + u32 time = 0; PlaySound(thm->SrcName(), size, time); - CanvasValue* C=0; - C=PHelper().CreateCanvas (props,"Attenuation", "", 64); - C->tag = (int)this; - C->OnDrawCanvasEvent.bind (this,&TfrmSoundLib::OnAttenuationDraw); -// C->OnTestEqual.bind (this,&TfrmSoundLib::OnPointDataTestEqual); - B=PHelper().CreateButton (props,"Auto Att", "By Min,By Max",ButtonValue::flFirstOnly); - B->OnBtnClickEvent.bind (this,&TfrmSoundLib::OnAttClick); - - PHelper().CreateCaption (props,"File Length", shared_str().printf("%.2f Kb",float(size)/1024.f)); - PHelper().CreateCaption (props,"Total Time", shared_str().printf("%.2f sec",float(time)/1000.f)); - if (!m_Flags.is(flReadOnly)){ - B=PHelper().CreateButton(props,"Control", "Play,Stop",ButtonValue::flFirstOnly); - B->OnBtnClickEvent.bind (this,&TfrmSoundLib::OnControlClick); + CanvasValue *C = 0; + C = PHelper().CreateCanvas(props, "Attenuation", "", 64); + C->tag = (int)this; + C->OnDrawCanvasEvent.bind(this, &TfrmSoundLib::OnAttenuationDraw); + // C->OnTestEqual.bind (this,&TfrmSoundLib::OnPointDataTestEqual); + B = PHelper().CreateButton(props, "Auto Att", "By Min,By Max", ButtonValue::flFirstOnly); + B->OnBtnClickEvent.bind(this, &TfrmSoundLib::OnAttClick); + + PHelper().CreateCaption(props, "File Length", shared_str().printf("%.2f Kb", float(size)/1024.f)); + PHelper().CreateCaption(props, "Total Time", shared_str().printf("%.2f sec", float(time)/1000.f)); + if (!m_Flags.is(flReadOnly)) + { + B = PHelper().CreateButton(props, "Control", "Play,Stop", ButtonValue::flFirstOnly); + B->OnBtnClickEvent.bind(this, &TfrmSoundLib::OnControlClick); } } if (!m_Flags.is(flReadOnly)) { - B=PHelper().CreateButton (props,"Auto Play", bAutoPlay?"on":"off",ButtonValue::flFirstOnly); - B->OnBtnClickEvent.bind (this,&TfrmSoundLib::OnControl2Click); + B = PHelper().CreateButton(props, "Auto Play", bAutoPlay ? "on" : "off", ButtonValue::flFirstOnly); + B->OnBtnClickEvent.bind(this, &TfrmSoundLib::OnControl2Click); } - if (!m_Flags.is(flReadOnly) && m_THM_Current.size()) + if (!m_Flags.is(flReadOnly)&&m_THM_Current.size()) { - B=PHelper().CreateButton(props,"MANAGE", "SyncCurrent", ButtonValue::flFirstOnly); - B->OnBtnClickEvent.bind (this,&TfrmSoundLib::OnSyncCurrentClick); + B = PHelper().CreateButton(props, "MANAGE", "SyncCurrent", ButtonValue::flFirstOnly); + B->OnBtnClickEvent.bind(this, &TfrmSoundLib::OnSyncCurrentClick); } - m_ItemProps->AssignItems (props); + m_ItemProps->AssignItems(props); } + //--------------------------------------------------------------------------- -void TfrmSoundLib::PlaySound(LPCSTR name, u32& size, u32& time) +void TfrmSoundLib::PlaySound(LPCSTR name, u32 &size, u32 &time) { - string_path fname; - FS.update_path (fname,_game_sounds_,ChangeFileExt(name,".ogg").c_str()); + string_path fname; + FS.update_path(fname, _game_sounds_, ChangeFileExt(name, ".ogg").c_str()); FS_File F; - if (FS.file_find(fname,F)) + if (FS.file_find(fname, F)) { - m_Snd.create (name,st_Effect,sg_Undefined); - m_Snd.play (0,sm_2D); - CSoundRender_Source* src= (CSoundRender_Source*)m_Snd._handle(); VERIFY(src); - size = F.size; - time = iFloor(src->fTimeTotal/1000.0f); - if (!bAutoPlay) m_Snd.stop(); + m_Snd.create(name, st_Effect, sg_Undefined); + m_Snd.play(0, sm_2D); + CSoundRender_Source *src = (CSoundRender_Source*)m_Snd._handle(); + VERIFY(src); + size = F.size; + time = iFloor(src->fTimeTotal/1000.0f); + if (!bAutoPlay) + m_Snd.stop(); } } void TfrmSoundLib::OnFrame() { - if (form){ - if (m_Flags.is(flUpdateProperties)){ - form->m_ItemList->FireOnItemFocused(); - m_Flags.set(flUpdateProperties,FALSE); + if (form) + { + if (m_Flags.is(flUpdateProperties)) + { + form->m_ItemList->FireOnItemFocused(); + m_Flags.set(flUpdateProperties, FALSE); } } } -void __fastcall TfrmSoundLib::OnSyncCurrentClick(ButtonValue* V, bool& bModif, bool& bSafe) +void __fastcall TfrmSoundLib::OnSyncCurrentClick(ButtonValue *V, bool &bModif, bool &bSafe) { -//. - THMIt it = m_THM_Current.begin(); - THMIt it_e = m_THM_Current.end(); + //. + THMIt it = m_THM_Current.begin(); + THMIt it_e = m_THM_Current.end(); - for(;it!=it_e; ++it) + for (; it!=it_e; ++it) { - ESoundThumbnail* pTHM = *it; + ESoundThumbnail*pTHM = *it; - string_path src_name, game_name; - FS.update_path (src_name,_sounds_,pTHM->SrcName()); - strconcat (sizeof(src_name),src_name,src_name,".wav"); + string_path src_name, game_name; + FS.update_path(src_name, _sounds_, pTHM->SrcName()); + strconcat(sizeof(src_name), src_name, src_name, ".wav"); - FS.update_path (game_name,_game_sounds_,pTHM->SrcName()); - strconcat (sizeof(game_name),game_name,game_name,".ogg"); + FS.update_path(game_name, _game_sounds_, pTHM->SrcName()); + strconcat(sizeof(game_name), game_name, game_name, ".ogg"); - Msg ("synchronizing [%s]", game_name); - SndLib->MakeGameSound (pTHM, src_name, game_name); + Msg("synchronizing [%s]", game_name); + SndLib->MakeGameSound(pTHM, src_name, game_name); } - Msg ("Done."); + Msg("Done."); } diff --git a/src/editors/ECore/Editor/SoundEditor.h b/src/editors/ECore/Editor/SoundEditor.h index 05222f0a136..4a1ef30baa7 100644 --- a/src/editors/ECore/Editor/SoundEditor.h +++ b/src/editors/ECore/Editor/SoundEditor.h @@ -19,87 +19,112 @@ // refs class ESoundThumbnail; class TProperties; + //--------------------------------------------------------------------------- class TfrmSoundLib : public TForm { -__published: // IDE-managed Components - TPanel *paRight; - TFormStorage *fsStorage; - TPanel *paCommand; - TExtBtn *ebOk; - TPanel *paProperties; - TPanel *paItems; - TSplitter *Splitter1; - TImageList *ImageList; - TExtBtn *ebCancel; - TPanel *Panel1; - TPanel *Panel3; + __published: // IDE-managed Components + TPanel*paRight; + TFormStorage *fsStorage; + TPanel *paCommand; + TExtBtn *ebOk; + TPanel *paProperties; + TPanel *paItems; + TSplitter *Splitter1; + TImageList *ImageList; + TExtBtn *ebCancel; + TPanel *Panel1; + TPanel *Panel3; void __fastcall ebOkClick(TObject *Sender); void __fastcall FormShow(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormKeyDown(TObject *Sender, WORD &Key, - TShiftState Shift); - void __fastcall fsStorageRestorePlacement(TObject *Sender); - void __fastcall fsStorageSavePlacement(TObject *Sender); - void __fastcall FormCreate(TObject *Sender); - void __fastcall ebCancelClick(TObject *Sender); - void __fastcall FormDestroy(TObject *Sender); + TShiftState Shift); + void __fastcall fsStorageRestorePlacement(TObject *Sender); + void __fastcall fsStorageSavePlacement(TObject *Sender); + void __fastcall FormCreate(TObject *Sender); + void __fastcall ebCancelClick(TObject *Sender); + void __fastcall FormDestroy(TObject *Sender); private: -// list functions - void InitItemsList (); - void __stdcall OnItemsFocused (ListItemsVec& items); - - void __stdcall RemoveSound (LPCSTR fname, EItemType type, bool& res); - void __stdcall RenameSound (LPCSTR p0, LPCSTR p1, EItemType type); - - enum{ - flUpdateProperties = (1<<0), - flReadOnly = (1<<1), - }; - static Flags32 m_Flags; -private: // User declarations - static TfrmSoundLib* form; - - DEFINE_VECTOR (ESoundThumbnail*,THMVec,THMIt); - THMVec m_THM_Used; - THMVec m_THM_Current; - TItemList* m_ItemList; - TProperties* m_ItemProps; - - ESoundThumbnail* FindUsedTHM (LPCSTR name); - void SaveUsedTHM (); - void DestroyUsedTHM (); - - void __fastcall RegisterModifiedTHM (); - - void OnModified (); - void __fastcall UpdateLib (); - - bool bFormLocked; - BOOL bAutoPlay; - - void LockForm (){ bFormLocked = true; form->paProperties->Enabled = false; form->paItems->Enabled = false; } - void UnlockForm (){ bFormLocked = false; form->paProperties->Enabled = true; form->paItems->Enabled = true; } - - static FS_FileSet modif_map; - ref_sound m_Snd; - void PlaySound (LPCSTR name, u32& size, u32& time); - void __stdcall OnControlClick (ButtonValue* sender, bool& bModif, bool& bSafe); - void __stdcall OnControl2Click (ButtonValue* sender, bool& bModif, bool& bSafe); - void __stdcall OnSyncCurrentClick (ButtonValue* sender, bool& bModif, bool& bSafe); - void __stdcall OnAttClick (ButtonValue* sender, bool& bModif, bool& bSafe); - void __stdcall OnAttenuationDraw (CanvasValue* sender, void* _canvas, const Irect& _rect); - - void AppendModif (LPCSTR nm); -public: // User declarations - __fastcall TfrmSoundLib (TComponent* Owner); -// static function - static void __fastcall EditLib (AnsiString& title); - static bool __fastcall HideLib (); - static bool __fastcall Visible (){return !!form;} - static void OnFrame (); - static void UpdateProperties (){m_Flags.set(flUpdateProperties,TRUE);} + // list functions + void InitItemsList(); + void __stdcall OnItemsFocused(ListItemsVec &items); + + void __stdcall RemoveSound(LPCSTR fname, EItemType type, bool &res); + void __stdcall RenameSound(LPCSTR p0, LPCSTR p1, EItemType type); + + enum + { + flUpdateProperties = (1<<0), + flReadOnly = (1<<1), + }; + + static Flags32 m_Flags; +private: // User declarations + static TfrmSoundLib *form; + + DEFINE_VECTOR(ESoundThumbnail *, THMVec, THMIt); + THMVec m_THM_Used; + THMVec m_THM_Current; + TItemList *m_ItemList; + TProperties *m_ItemProps; + + ESoundThumbnail *FindUsedTHM(LPCSTR name); + void SaveUsedTHM(); + void DestroyUsedTHM(); + + void __fastcall RegisterModifiedTHM(); + + void OnModified(); + void __fastcall UpdateLib(); + + bool bFormLocked; + BOOL bAutoPlay; + + void LockForm() + { + bFormLocked = true; + form->paProperties->Enabled = false; + form->paItems->Enabled = false; + } + + void UnlockForm() + { + bFormLocked = false; + form->paProperties->Enabled = true; + form->paItems->Enabled = true; + } + + static FS_FileSet modif_map; + ref_sound m_Snd; + void PlaySound(LPCSTR name, u32 &size, u32 &time); + void __stdcall OnControlClick(ButtonValue *sender, bool &bModif, bool &bSafe); + void __stdcall OnControl2Click(ButtonValue *sender, bool &bModif, bool &bSafe); + void __stdcall OnSyncCurrentClick(ButtonValue *sender, bool &bModif, bool &bSafe); + void __stdcall OnAttClick(ButtonValue *sender, bool &bModif, bool &bSafe); + void __stdcall OnAttenuationDraw(CanvasValue *sender, void *_canvas, const Irect &_rect); + + void AppendModif(LPCSTR nm); +public: // User declarations + __fastcall TfrmSoundLib(TComponent *Owner); + // static function + static void __fastcall EditLib(AnsiString &title); + static bool __fastcall HideLib(); + + static bool __fastcall Visible() + { + return !!form; + } + + static void OnFrame(); + + static void UpdateProperties() + { + m_Flags.set(flUpdateProperties, TRUE); + } }; + //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/SoundManager.cpp b/src/editors/ECore/Editor/SoundManager.cpp index 5a6929d3a80..534b86cf8f6 100644 --- a/src/editors/ECore/Editor/SoundManager.cpp +++ b/src/editors/ECore/Editor/SoundManager.cpp @@ -2,118 +2,134 @@ #pragma hdrstop #include "SoundManager.h" -#include "../../../xrSound/soundrender_environment.h" +#include "xrSound/SoundRender_Environment.h" #include "EThumbnail.h" #include "ui_main.h" -CSoundManager* SndLib=0; +CSoundManager *SndLib = 0; //--------------------------------------------------------------------------- #pragma package(smart_init) -extern "C" int ogg_enc(const char* in_fn, const char* out_fn, float quality, void* comment, int size); +extern "C" int ogg_enc(const char *in_fn, const char *out_fn, float quality, void *comment, int size); + //------------------------------------------------------------------------------ -xr_string CSoundManager::UpdateFileName(xr_string& fn) +xr_string CSoundManager::UpdateFileName(xr_string &fn) { - return EFS.AppendFolderToName(fn,-1,FALSE); + return EFS.AppendFolderToName(fn, -1, FALSE); } //------------------------------------------------------------------------------ // возвращает список всех звуков //------------------------------------------------------------------------------ -int CSoundManager::GetSounds(FS_FileSet& files, BOOL bFolders) +int CSoundManager::GetSounds(FS_FileSet &files, BOOL bFolders) { - return FS.file_list(files,_sounds_,(bFolders?FS_ListFolders:0)|FS_ListFiles|FS_ClampExt,"*.wav"); + return FS.file_list(files, _sounds_, (bFolders ? FS_ListFolders : 0)|FS_ListFiles|FS_ClampExt, "*.wav"); } -int CSoundManager::GetGameSounds(FS_FileSet& files) +int CSoundManager::GetGameSounds(FS_FileSet &files) { - return FS.file_list(files,_game_sounds_,FS_ListFiles|FS_ClampExt,"*.ogg"); + return FS.file_list(files, _game_sounds_, FS_ListFiles|FS_ClampExt, "*.ogg"); } -int CSoundManager::GetSoundEnvs(AStringVec& items) +int CSoundManager::GetSoundEnvs(AStringVec &items) { -/* - SoundEnvironment_LIB* Lib = Sound->get_env_library(); - if (Lib){ - for (SoundEnvironment_LIB::SE_IT it=Lib->Library().begin(); it!=Lib->Library().end(); it++) - items.push_back(*(*it)->name); - } - return items.size(); -*/ -return 0; + /* + SoundEnvironment_LIB* Lib = Sound->get_env_library(); + if (Lib){ + for (SoundEnvironment_LIB::SE_IT it=Lib->Library().begin(); it!=Lib->Library().end(); it++) + items.push_back(*(*it)->name); + } + return items.size(); + */ + return 0; } bool CSoundManager::OnCreate() { -//. psSoundFreq = sf_44K; -// psSoundFlags.set (ssHardware,FALSE); - CSound_manager_interface::_create (0); - CSound_manager_interface::_create (1); + //. psSoundFreq = sf_44K; + // psSoundFlags.set (ssHardware,FALSE); + CSound_manager_interface::_create(0); + CSound_manager_interface::_create(1); return true; } void CSoundManager::OnDestroy() { - CSound_manager_interface::_destroy (); + CSound_manager_interface::_destroy(); } void CSoundManager::OnFrame() { - ::psSoundVEffects = psDeviceFlags.is(rsMuteSounds)?0.f:1.f; - Sound->update (EDevice.m_Camera.GetPosition(), EDevice.m_Camera.GetDirection(), EDevice.m_Camera.GetNormal()); + ::psSoundVEffects = psDeviceFlags.is(rsMuteSounds) ? 0.f : 1.f; + Sound->update(EDevice.m_Camera.GetPosition(), EDevice.m_Camera.GetDirection(), EDevice.m_Camera.GetNormal()); } void CSoundManager::MuteSounds(BOOL bVal) { - if (bVal) ::psSoundVEffects = 0.f; - else ::psSoundVEffects = psDeviceFlags.is(rsMuteSounds)?0.f:1.f; + if (bVal) + ::psSoundVEffects = 0.f; + else + ::psSoundVEffects = psDeviceFlags.is(rsMuteSounds) ? 0.f : 1.f; } void CSoundManager::RenameSound(LPCSTR nm0, LPCSTR nm1, EItemType type) { - if (TYPE_FOLDER==type){ - FS.dir_delete (_sounds_,nm0,FALSE); - FS.dir_delete (_game_sounds_,nm0,FALSE); - }else if (TYPE_OBJECT==type){ - string_path fn0,fn1,temp; + if (TYPE_FOLDER==type) + { + FS.dir_delete(_sounds_, nm0, FALSE); + FS.dir_delete(_game_sounds_, nm0, FALSE); + } + else if (TYPE_OBJECT==type) + { + string_path fn0, fn1, temp; // rename base file - FS.update_path(fn0,_sounds_,nm0); strcat(fn0,".wav"); - FS.update_path(fn1,_sounds_,nm1); strcat(fn1,".wav"); - FS.file_rename(fn0,fn1,false); + FS.update_path(fn0, _sounds_, nm0); + strcat(fn0, ".wav"); + FS.update_path(fn1, _sounds_, nm1); + strcat(fn1, ".wav"); + FS.file_rename(fn0, fn1, false); // rename thm - FS.update_path(fn0,_sounds_,nm0); strcat(fn0,".thm"); - FS.update_path(fn1,_sounds_,nm1); strcat(fn1,".thm"); - FS.file_rename(fn0,fn1,false); + FS.update_path(fn0, _sounds_, nm0); + strcat(fn0, ".thm"); + FS.update_path(fn1, _sounds_, nm1); + strcat(fn1, ".thm"); + FS.file_rename(fn0, fn1, false); // rename ogg - FS.update_path(fn0,_game_sounds_,nm0); strcat(fn0,".ogg"); - FS.update_path(fn1,_game_sounds_,nm1); strcat(fn1,".ogg"); - FS.file_rename(fn0,fn1,false); + FS.update_path(fn0, _game_sounds_, nm0); + strcat(fn0, ".ogg"); + FS.update_path(fn1, _game_sounds_, nm1); + strcat(fn1, ".ogg"); + FS.file_rename(fn0, fn1, false); - Sound->refresh_sources(); - } + Sound->refresh_sources(); + } } BOOL CSoundManager::RemoveSound(LPCSTR fname, EItemType type) { - if (TYPE_FOLDER==type){ - FS.dir_delete (_sounds_,fname,FALSE); - FS.dir_delete (_game_sounds_,fname,FALSE); - return TRUE; - }else if (TYPE_OBJECT==type){ + if (TYPE_FOLDER==type) + { + FS.dir_delete(_sounds_, fname, FALSE); + FS.dir_delete(_game_sounds_, fname, FALSE); + return TRUE; + } + else if (TYPE_OBJECT==type) + { xr_string src_name; - src_name = EFS.ChangeFileExt(fname,".wav"); - if (FS.exist(_sounds_,src_name.c_str())){ - xr_string thm_name = EFS.ChangeFileExt(fname,".thm"); - xr_string game_name= EFS.ChangeFileExt(fname,".ogg"); + src_name = EFS.ChangeFileExt(fname, ".wav"); + if (FS.exist(_sounds_, src_name.c_str())) + { + xr_string thm_name = EFS.ChangeFileExt(fname, ".thm"); + xr_string game_name = EFS.ChangeFileExt(fname, ".ogg"); // source - FS.file_delete (_sounds_,src_name.c_str()); + FS.file_delete(_sounds_, src_name.c_str()); // thumbnail - FS.file_delete (_sounds_,thm_name.c_str()); + FS.file_delete(_sounds_, thm_name.c_str()); // game - FS.file_delete (_game_sounds_,game_name.c_str()); - Sound->refresh_sources(); + FS.file_delete(_game_sounds_, game_name.c_str()); + Sound->refresh_sources(); return TRUE; } } @@ -123,9 +139,9 @@ BOOL CSoundManager::RemoveSound(LPCSTR fname, EItemType type) //------------------------------------------------------------------------------ // возвращает список новых звуков //------------------------------------------------------------------------------ -int CSoundManager::GetLocalNewSounds(FS_FileSet& files) +int CSoundManager::GetLocalNewSounds(FS_FileSet &files) { - return FS.file_list (files,_import_,FS_ListFiles|FS_RootOnly|FS_ClampExt,"*.wav"); + return FS.file_list(files, _import_, FS_ListFiles|FS_RootOnly|FS_ClampExt, "*.wav"); } //------------------------------------------------------------------------------ @@ -141,22 +157,22 @@ void CSoundManager::SafeCopyLocalToServer(FS_FileSet& files) FS.update_path (p_sounds,_sounds_,""); FS_FileSetIt it = files.begin(); - FS_FileSetIt _E = files.end(); - for (; it!=_E; it++){ + FS_FileSetIt _E = files.end(); + for (; it!=_E; it++){ // copy thm - xr_string fn = EFS.ChangeFileExt(it->first,".thm"); - src_name = p_import + fn; - UpdateFileName (fn); - dest_name = p_sounds + fn; - FS.file_rename (src_name.c_str(),dest_name.c_str(),true); - // copy sources - fn = EFS.ChangeFileExt(it->first,".wav"); - src_name = p_import + fn; - UpdateFileName (fn); - dest_name = p_sounds + fn; + xr_string fn = EFS.ChangeFileExt(it->first,".thm"); + src_name = p_import + fn; + UpdateFileName (fn); + dest_name = p_sounds + fn; + FS.file_rename (src_name.c_str(),dest_name.c_str(),true); + // copy sources + fn = EFS.ChangeFileExt(it->first,".wav"); + src_name = p_import + fn; + UpdateFileName (fn); + dest_name = p_sounds + fn; if (FS.exist(dest_name.c_str())){ - EFS.BackupFile (_sounds_,EFS.ChangeFileExt(fn,".wav").c_str()); - EFS.BackupFile (_sounds_,EFS.ChangeFileExt(fn,".thm").c_str()); + EFS.BackupFile (_sounds_,EFS.ChangeFileExt(fn,".wav").c_str()); + EFS.BackupFile (_sounds_,EFS.ChangeFileExt(fn,".thm").c_str()); } FS.file_copy (src_name.c_str(),dest_name.c_str()); FS.set_file_age (dest_name.c_str(),FS.get_file_age(src_name.c_str())); @@ -168,38 +184,41 @@ void CSoundManager::SafeCopyLocalToServer(FS_FileSet& files) //------------------------------------------------------------------------------ // создает тхм //------------------------------------------------------------------------------ -void CSoundManager::CreateSoundThumbnail(ESoundThumbnail* THM, const AnsiString& src_name, LPCSTR initial, bool bSetDefParam) +void CSoundManager::CreateSoundThumbnail(ESoundThumbnail *THM, const AnsiString &src_name, LPCSTR initial, bool bSetDefParam) { - R_ASSERT(src_name.Length()); - string_path base_name; - if (initial) FS.update_path(base_name,initial,src_name.c_str()); - else FS.update_path(base_name,_sounds_,src_name.c_str()); - strcpy (base_name, EFS.ChangeFileExt(base_name,".wav").c_str()); + R_ASSERT(src_name.Length()); + string_path base_name; + if (initial) + FS.update_path(base_name, initial, src_name.c_str()); + else + FS.update_path(base_name, _sounds_, src_name.c_str()); + strcpy(base_name, EFS.ChangeFileExt(base_name, ".wav").c_str()); // выставить начальные параметры - if (bSetDefParam){ - THM->m_Age = FS.get_file_age(base_name); - THM->m_fQuality = 0.f; - THM->m_fMinDist = 1.f; - THM->m_uGameType = 0; + if (bSetDefParam) + { + THM->m_Age = FS.get_file_age(base_name); + THM->m_fQuality = 0.f; + THM->m_fMinDist = 1.f; + THM->m_uGameType = 0; } -} +} -void CSoundManager::MakeGameSound(ESoundThumbnail* THM, LPCSTR src_name, LPCSTR game_name) +void CSoundManager::MakeGameSound(ESoundThumbnail *THM, LPCSTR src_name, LPCSTR game_name) { - VerifyPath (game_name); - CMemoryWriter F; - F.w_u32 (OGG_COMMENT_VERSION); - F.w_float (THM->m_fMinDist); - F.w_float (THM->m_fMaxDist); - F.w_float (THM->m_fBaseVolume); - F.w_u32 (THM->m_uGameType); - F.w_float (THM->m_fMaxAIDist); - - if (!ogg_enc(src_name, game_name, THM->m_fQuality, F.pointer(), F.size())) + VerifyPath(game_name); + CMemoryWriter F; + F.w_u32(OGG_COMMENT_VERSION); + F.w_float(THM->m_fMinDist); + F.w_float(THM->m_fMaxDist); + F.w_float(THM->m_fBaseVolume); + F.w_u32(THM->m_uGameType); + F.w_float(THM->m_fMaxAIDist); + + if (!ogg_enc(src_name, game_name, THM->m_fQuality, F.pointer(), F.size())) { - FS.file_delete(game_name); - ELog.DlgMsg(mtError,"Can't make game sound '%s'.",game_name); + FS.file_delete(game_name); + ELog.DlgMsg(mtError, "Can't make game sound '%s'.", game_name); } } @@ -208,190 +227,192 @@ void CSoundManager::MakeGameSound(ESoundThumbnail* THM, LPCSTR src_name, LPCSTR // source_list - содержит список текстур с расширениями // sync_list - реально сохраненные файлы (после использования освободить) //------------------------------------------------------------------------------ -void CSoundManager::SynchronizeSounds(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet* source_list, AStringVec* sync_list, FS_FileSet* modif_map) -{ - FS_FileSet M_BASE; - FS_FileSet M_THUM; +void CSoundManager::SynchronizeSounds(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet *source_list, AStringVec *sync_list, FS_FileSet *modif_map) +{ + FS_FileSet M_BASE; + FS_FileSet M_THUM; FS_FileSet M_GAME; if (source_list) - M_BASE = *source_list; + M_BASE = *source_list; else - FS.file_list(M_BASE,_sounds_,FS_ListFiles|FS_ClampExt,"*.wav"); + FS.file_list(M_BASE, _sounds_, FS_ListFiles|FS_ClampExt, "*.wav"); if (M_BASE.empty()) - return; + return; if (sync_thm) - FS.file_list(M_THUM,_sounds_,FS_ListFiles|FS_ClampExt,"*.thm"); - + FS.file_list(M_THUM, _sounds_, FS_ListFiles|FS_ClampExt, "*.thm"); + if (sync_game) - FS.file_list(M_GAME,_game_sounds_,FS_ListFiles|FS_ClampExt,"*.ogg"); + FS.file_list(M_GAME, _game_sounds_, FS_ListFiles|FS_ClampExt, "*.ogg"); - bool bProgress = (M_BASE.size()>1); + bool bProgress = (M_BASE.size()>1); - int m_age = time(NULL); + int m_age = time(NULL); - SPBItem* pb = 0; + SPBItem*pb = 0; if (bProgress) - pb = UI->ProgressStart(M_BASE.size(),"Synchronize sounds..."); + pb = UI->ProgressStart(M_BASE.size(), "Synchronize sounds..."); - FS_FileSetIt it = M_BASE.begin(); - FS_FileSetIt it_e = M_BASE.end(); - for (; it!=it_e; ++it) + FS_FileSetIt it = M_BASE.begin(); + FS_FileSetIt it_e = M_BASE.end(); + for (; it!=it_e; ++it) { - BOOL bUpdated = FALSE; - xr_string base_name = EFS.ChangeFileExt(it->name,""); - xr_strlwr (base_name); - string_path fn; - FS.update_path (fn,_sounds_,EFS.ChangeFileExt(base_name,".wav").c_str()); - if (!FS.exist(fn)) - continue; + BOOL bUpdated = FALSE; + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + string_path fn; + FS.update_path(fn, _sounds_, EFS.ChangeFileExt(base_name, ".wav").c_str()); + if (!FS.exist(fn)) + continue; - FS_FileSetIt th = M_THUM.find(base_name); - bool bThm = ((th==M_THUM.end()) || ((th!=M_THUM.end())&&(th->time_write!=it->time_write))); - FS_FileSetIt gm = M_GAME.find(base_name); - bool bGame = bThm || ((gm==M_GAME.end()) || ((gm!=M_GAME.end())&&(gm->time_write!=it->time_write))); + FS_FileSetIt th = M_THUM.find(base_name); + bool bThm = ((th==M_THUM.end())||((th!=M_THUM.end())&&(th->time_write!=it->time_write))); + FS_FileSetIt gm = M_GAME.find(base_name); + bool bGame = bThm||((gm==M_GAME.end())||((gm!=M_GAME.end())&&(gm->time_write!=it->time_write))); - ESoundThumbnail* THM = 0; + ESoundThumbnail*THM = 0; // backup base sound - // check thumbnail - if (sync_thm&&bThm){ - THM = xr_new(it->name.c_str()); - THM->Save (m_age); - bUpdated = TRUE; + // check thumbnail + if (sync_thm&&bThm) + { + THM = xr_new(it->name.c_str()); + THM->Save(m_age); + bUpdated = TRUE; } // check game sounds - if (bForceGame||(sync_game&&bGame)) + if (bForceGame||(sync_game&&bGame)) { - if (!THM) THM = xr_new(it->name.c_str()); + if (!THM) + THM = xr_new(it->name.c_str()); R_ASSERT(THM); - string_path src_name; - strconcat (sizeof(src_name),src_name, base_name.c_str(), ".wav"); + string_path src_name; + strconcat(sizeof(src_name), src_name, base_name.c_str(), ".wav"); - FS.update_path (src_name,_sounds_,src_name); - string_path game_name; - strconcat (sizeof(game_name),game_name, base_name.c_str(), ".ogg"); - FS.update_path (game_name,_game_sounds_,game_name); - MakeGameSound (THM,src_name,game_name); + FS.update_path(src_name, _sounds_, src_name); + string_path game_name; + strconcat(sizeof(game_name), game_name, base_name.c_str(), ".ogg"); + FS.update_path(game_name, _game_sounds_, game_name); + MakeGameSound(THM, src_name, game_name); if (sync_list) - sync_list->push_back(base_name.c_str()); + sync_list->push_back(base_name.c_str()); if (modif_map) - modif_map->insert(*it); + modif_map->insert(*it); bUpdated = TRUE; - } + } - if (THM) - xr_delete(THM); + if (THM) + xr_delete(THM); - if (UI->NeedAbort()) - break; + if (UI->NeedAbort()) + break; if (bProgress) - pb->Inc (bUpdated?xr_string(base_name+" - UPDATED.").c_str():"",bUpdated); + pb->Inc(bUpdated ? xr_string(base_name+" - UPDATED.").c_str() : "", bUpdated); if (bUpdated) { - string_path wav_fn,thm_fn,ogg_fn; - FS.update_path (wav_fn,_sounds_, EFS.ChangeFileExt(base_name,".wav").c_str()); - FS.update_path (thm_fn,_sounds_, EFS.ChangeFileExt(base_name,".thm").c_str()); - FS.update_path (ogg_fn,_game_sounds_, EFS.ChangeFileExt(base_name,".ogg").c_str()); - FS.set_file_age (wav_fn,m_age); - FS.set_file_age (thm_fn,m_age); - FS.set_file_age (ogg_fn,m_age); + string_path wav_fn, thm_fn, ogg_fn; + FS.update_path(wav_fn, _sounds_, EFS.ChangeFileExt(base_name, ".wav").c_str()); + FS.update_path(thm_fn, _sounds_, EFS.ChangeFileExt(base_name, ".thm").c_str()); + FS.update_path(ogg_fn, _game_sounds_, EFS.ChangeFileExt(base_name, ".ogg").c_str()); + FS.set_file_age(wav_fn, m_age); + FS.set_file_age(thm_fn, m_age); + FS.set_file_age(ogg_fn, m_age); } } if (bProgress) - UI->ProgressEnd(pb); + UI->ProgressEnd(pb); } void CSoundManager::CleanupSounds() { - FS_FileSet M_BASE; - FS_FileSet M_THUM; - FS_FileSet M_GAME; - FS_FileSet M_GAME_DEL; - FS_FileSet M_THM_DEL; + FS_FileSet M_BASE; + FS_FileSet M_THUM; + FS_FileSet M_GAME; + FS_FileSet M_GAME_DEL; + FS_FileSet M_THM_DEL; - FS.file_list (M_BASE,_sounds_, FS_ListFiles|FS_ClampExt,"*.wav"); - FS.file_list (M_THUM,_sounds_, FS_ListFiles|FS_ClampExt,"*.thm"); - FS.file_list (M_GAME,_game_sounds_, FS_ListFiles|FS_ClampExt,"*.ogg"); + FS.file_list(M_BASE, _sounds_, FS_ListFiles|FS_ClampExt, "*.wav"); + FS.file_list(M_THUM, _sounds_, FS_ListFiles|FS_ClampExt, "*.thm"); + FS.file_list(M_GAME, _game_sounds_, FS_ListFiles|FS_ClampExt, "*.ogg"); - FS_FileSetIt it; - FS_FileSetIt it_e; + FS_FileSetIt it; + FS_FileSetIt it_e; // check source exist - it = M_GAME.begin(); - it_e = M_GAME.end(); + it = M_GAME.begin(); + it_e = M_GAME.end(); - for (; it!=it_e; ++it) + for (; it!=it_e; ++it) { - xr_string base_name = EFS.ChangeFileExt(it->name,""); - xr_strlwr (base_name); - FS_FileSetIt bs = M_BASE.find(base_name); + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + FS_FileSetIt bs = M_BASE.find(base_name); - if (bs==M_BASE.end()) - M_GAME_DEL.insert (*it); + if (bs==M_BASE.end()) + M_GAME_DEL.insert(*it); } - it = M_THUM.begin(); - it_e = M_THUM.end(); + it = M_THUM.begin(); + it_e = M_THUM.end(); - for (; it!=it_e; ++it) + for (; it!=it_e; ++it) { - xr_string base_name = EFS.ChangeFileExt(it->name,""); - xr_strlwr (base_name); - FS_FileSetIt bs = M_BASE.find(base_name); - if (bs==M_BASE.end()) - M_THM_DEL.insert (*it); + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + FS_FileSetIt bs = M_BASE.find(base_name); + if (bs==M_BASE.end()) + M_THM_DEL.insert(*it); } - SPBItem* pb = UI->ProgressStart(M_GAME_DEL.size()+M_THM_DEL.size(),"Cleanup sounds..."); + SPBItem*pb = UI->ProgressStart(M_GAME_DEL.size()+M_THM_DEL.size(), "Cleanup sounds..."); // mark game del sounds - it = M_GAME_DEL.begin(); - it_e = M_GAME_DEL.end(); + it = M_GAME_DEL.begin(); + it_e = M_GAME_DEL.end(); - for (; it!=it_e; ++it) + for (; it!=it_e; ++it) { - xr_string base_name = EFS.ChangeFileExt(it->name,""); - xr_strlwr (base_name); - string_path fn; - FS.update_path (fn,_game_sounds_,EFS.ChangeFileExt(base_name,".ogg").c_str()); - EFS.MarkFile (fn,true); - pb->Inc (); + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + string_path fn; + FS.update_path(fn, _game_sounds_, EFS.ChangeFileExt(base_name, ".ogg").c_str()); + EFS.MarkFile(fn, true); + pb->Inc(); } // mark thm sounds - it = M_THM_DEL.begin(); - it_e = M_THM_DEL.end(); - for (; it!=it_e; ++it) + it = M_THM_DEL.begin(); + it_e = M_THM_DEL.end(); + for (; it!=it_e; ++it) { - xr_string base_name = EFS.ChangeFileExt(it->name,""); - xr_strlwr (base_name); - string_path fn; - FS.update_path (fn,_sounds_,EFS.ChangeFileExt(base_name,".thm").c_str()); - EFS.MarkFile (fn,true); - pb->Inc (); + xr_string base_name = EFS.ChangeFileExt(it->name, ""); + xr_strlwr(base_name); + string_path fn; + FS.update_path(fn, _sounds_, EFS.ChangeFileExt(base_name, ".thm").c_str()); + EFS.MarkFile(fn, true); + pb->Inc(); } - UI->ProgressEnd (pb); + UI->ProgressEnd(pb); } /* void CSoundManager::ChangeFileAgeTo(FS_FileSet* tgt_map, int age) { - VERIFY(tgt_map); - FS_FileSet* M_BASE = tgt_map; + VERIFY(tgt_map); + FS_FileSet* M_BASE = tgt_map; // lock rescanning FS.lock_rescan (); // change - SPBItem* pb=0; + SPBItem* pb=0; if (M_BASE->size()>1) pb = UI->ProgressStart(M_BASE->size(),"Change sounds age..."); FS_FileSetIt it = M_BASE->begin(); - FS_FileSetIt _E = M_BASE->end(); - for (; it!=_E; it++){ + FS_FileSetIt _E = M_BASE->end(); + for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->first,""); xr_strlwr(base_name); xr_string wav_fn,thm_fn,ogg_fn; FS.update_path (wav_fn,_sounds_, EFS.ChangeFileExt(base_name,".wav").c_str()); @@ -413,15 +434,19 @@ void CSoundManager::ChangeFileAgeTo(FS_FileSet* tgt_map, int age) //------------------------------------------------------------------------------ void CSoundManager::RefreshSounds(bool bSync) { - if (FS.can_write_to_alias(_sounds_)){ + if (FS.can_write_to_alias(_sounds_)) + { UI->SetStatus("Refresh sounds..."); - if (bSync){ - SynchronizeSounds (true,true,false,0,0); - CleanupSounds (); + if (bSync) + { + SynchronizeSounds(true, true, false, 0, 0); + CleanupSounds(); } Sound->refresh_sources(); UI->SetStatus(""); - }else{ + } + else + { Log("#!You don't have permisions to modify sounds."); } } diff --git a/src/editors/ECore/Editor/SoundManager.h b/src/editors/ECore/Editor/SoundManager.h index 918d391867a..d7671d12409 100644 --- a/src/editors/ECore/Editor/SoundManager.h +++ b/src/editors/ECore/Editor/SoundManager.h @@ -2,47 +2,48 @@ #ifndef SoundManagerH #define SoundManagerH -#include "../xrEProps/folderlib.h" +#include "editors/xrEProps/FolderLib.h" // refs class ESoundThumbnail; class ECORE_API CSoundManager { -public: - void MakeGameSound (ESoundThumbnail* THM, LPCSTR src_name, LPCSTR game_name); - CSoundManager (){} - virtual ~CSoundManager (){;} - - BOOL __stdcall RemoveSound (LPCSTR fname, EItemType type); - void __stdcall RenameSound (LPCSTR p0, LPCSTR p1, EItemType type); + public: + void MakeGameSound(ESoundThumbnail*THM, LPCSTR src_name, LPCSTR game_name); + CSoundManager(){} + virtual ~CSoundManager(){;} - // texture routines - int GetSounds (FS_FileSet& files, BOOL bFolders=FALSE); - int GetGameSounds (FS_FileSet& files); - int GetSoundEnvs (AStringVec& items); + BOOL__stdcall RemoveSound(LPCSTR fname, EItemType type); + void__stdcall RenameSound(LPCSTR p0, LPCSTR p1, EItemType type); - int GetLocalNewSounds (FS_FileSet& files); -// void SafeCopyLocalToServer(FS_FileSet& files); - void SynchronizeSounds (bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet* source_map, AStringVec* sync_list_without_extention, FS_FileSet* modif_map=0); -// void ChangeFileAgeTo (FS_FileSet* tgt_map, int age); - void CreateSoundThumbnail(ESoundThumbnail* THM, const AnsiString& src_name, LPCSTR path=0, bool bSetDefParam=true); - void CleanupSounds (); + // texture routines + int GetSounds(FS_FileSet&files, BOOL bFolders = FALSE); + int GetGameSounds(FS_FileSet&files); + int GetSoundEnvs(AStringVec&items); - bool OnCreate (); - void OnDestroy (); + int GetLocalNewSounds(FS_FileSet&files); + // void SafeCopyLocalToServer(FS_FileSet& files); + void SynchronizeSounds(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet*source_map, AStringVec*sync_list_without_extention, FS_FileSet*modif_map = 0); + // void ChangeFileAgeTo (FS_FileSet* tgt_map, int age); + void CreateSoundThumbnail(ESoundThumbnail*THM, const AnsiString&src_name, LPCSTR path = 0, bool bSetDefParam = true); + void CleanupSounds(); - virtual void OnFrame (); + bool OnCreate(); + void OnDestroy(); - virtual bool Validate (){return true;} + virtual void OnFrame(); - void MuteSounds (BOOL bVal); + virtual bool Validate(){return true;} - void RefreshSounds (bool bSync); + void MuteSounds(BOOL bVal); - xr_string UpdateFileName (xr_string& fn); + void RefreshSounds(bool bSync); + + xr_string UpdateFileName(xr_string&fn); }; extern ECORE_API CSoundManager* SndLib; //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/TLSPRITE.CPP b/src/editors/ECore/Editor/TLSPRITE.CPP index f7e6e69447b..81ca90909fe 100644 --- a/src/editors/ECore/Editor/TLSPRITE.CPP +++ b/src/editors/ECore/Editor/TLSPRITE.CPP @@ -1,163 +1,187 @@ #include "stdafx.h" #pragma hdrstop -#include "tlsprite.h" -#include "texture.h" +#include "TLSprite.h" +#include "editors/ECore/Engine/Texture.h" #include "ui_main.h" -#include "d3dutils.h" +#include "D3DUtils.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CTLSprite::CTLSprite ( ) +CTLSprite::CTLSprite() { - mesh.setcolor (0xFFFFFFFF); - mesh.setdepth ( ); - mesh.settex (0,0,1,1); + mesh.setcolor(0xFFFFFFFF); + mesh.setdepth(); + mesh.settex(0, 0, 1, 1); } -CTLSprite::~CTLSprite( ) -{ -} +CTLSprite::~CTLSprite() {} void CTLSprite::Render(Fvector &pos, float radius, bool bFixedSize, u32 clr) { - FVF::TL P; - float cx,cy,sz; - - P.transform ( pos, EDevice.mFullTransform ); - cx = EDevice._x2real(P.p.x); - cy = EDevice._y2real(P.p.y); - if (bFixedSize) sz = EDevice._x2real(radius)-EDevice._x2real(0); - else sz = UI->GetRenderWidth()*radius/P.p.w; - mesh.m[0].p.x = cx-sz; mesh.m[0].p.y = cy+sz; - mesh.m[1].p.x = cx-sz; mesh.m[1].p.y = cy-sz; - mesh.m[3].p.x = cx+sz; mesh.m[3].p.y = cy-sz; - mesh.m[2].p.x = cx+sz; mesh.m[2].p.y = cy+sz; - mesh.setdepth ( P.p.z, P.p.w ); - mesh.setcolor ( clr ); - - DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP,2,(FVF::TL*)&mesh,4,false,false); + FVF::TL P; + float cx, cy, sz; + + P.transform(pos, EDevice.mFullTransform); + cx = EDevice._x2real(P.p.x); + cy = EDevice._y2real(P.p.y); + if (bFixedSize) + sz = EDevice._x2real(radius)-EDevice._x2real(0); + else + sz = UI->GetRenderWidth()*radius/P.p.w; + mesh.m[0].p.x = cx-sz; + mesh.m[0].p.y = cy+sz; + mesh.m[1].p.x = cx-sz; + mesh.m[1].p.y = cy-sz; + mesh.m[3].p.x = cx+sz; + mesh.m[3].p.y = cy-sz; + mesh.m[2].p.x = cx+sz; + mesh.m[2].p.y = cy+sz; + mesh.setdepth(P.p.z, P.p.w); + mesh.setcolor(clr); + + DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP, 2, (FVF::TL*)&mesh, 4, false, false); } void CTLSprite::Render(Fvector &pos, u32 color, float radius, float angle) { - FVF::TL P; + FVF::TL P; - P.transform (pos, EDevice.mFullTransform); - if (P.p.w<=0) return; + P.transform(pos, EDevice.mFullTransform); + if (P.p.w<=0) + return; - float cx = EDevice._x2real(P.p.x); - float cy = EDevice._y2real(P.p.y); + float cx = EDevice._x2real(P.p.x); + float cy = EDevice._y2real(P.p.y); - float sz = (UI->GetRenderWidth()*radius)/P.p.w; - if (sz<1.5f) return; + float sz = (UI->GetRenderWidth()*radius)/P.p.w; + if (sz<1.5f) + return; - // Rotation - float _sin1=_sin(angle),_cos1=_cos(angle); - float _sin2=_sin(angle+PI_DIV_2),_cos2=_cos(angle+PI_DIV_2); + // Rotation + float _sin1 = _sin(angle), _cos1 = _cos(angle); + float _sin2 = _sin(angle+PI_DIV_2), _cos2 = _cos(angle+PI_DIV_2); - mesh.m[0].p.x = cx+sz*_sin1; mesh.m[0].p.y = cy+sz*_cos1; - mesh.m[1].p.x = cx-sz*_sin2; mesh.m[1].p.y = cy-sz*_cos2; - mesh.m[2].p.x = cx+sz*_sin2; mesh.m[2].p.y = cy+sz*_cos2; - mesh.m[3].p.x = cx-sz*_sin1; mesh.m[3].p.y = cy-sz*_cos1; + mesh.m[0].p.x = cx+sz*_sin1; + mesh.m[0].p.y = cy+sz*_cos1; + mesh.m[1].p.x = cx-sz*_sin2; + mesh.m[1].p.y = cy-sz*_cos2; + mesh.m[2].p.x = cx+sz*_sin2; + mesh.m[2].p.y = cy+sz*_cos2; + mesh.m[3].p.x = cx-sz*_sin1; + mesh.m[3].p.y = cy-sz*_cos1; - mesh.setdepth (P.p.z, P.p.w); - mesh.setcolor (color); + mesh.setdepth(P.p.z, P.p.w); + mesh.setcolor(color); - DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP,2,(FVF::TL*)&mesh,4,false,false); + DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP, 2, (FVF::TL*)&mesh, 4, false, false); } -void CTLSprite::Render( Fvector &pos, u32 color, float radius, const Fvector& D ){ - Fvector P1,P2; - P1.mad (pos,D,-radius); - P2.mad (pos,D,radius); - - FVF::TL s1,s2; - s1.transform (P1,EDevice.mFullTransform); - s2.transform (P2,EDevice.mFullTransform); - - if ((s1.p.w<=0)||(s2.p.w<=0)) return; - - float l1 = radius/s1.p.w*1.4142f; - float l2 = radius/s2.p.w*1.4142f; - - Fvector2 dir,R; - dir.set (s2.p.x-s1.p.x,s2.p.y-s1.p.y); - dir.norm (); - R.cross (dir); - - mesh.m[0].p.x = EDevice._x2real(s1.p.x+l1*R.x); mesh.m[0].p.y = EDevice._y2real(s1.p.y+l1*R.y); mesh.m[0].p.z = s2.p.z; mesh.m[0].p.w = s2.p.w; - mesh.m[1].p.x = EDevice._x2real(s2.p.x+l2*R.x); mesh.m[1].p.y = EDevice._y2real(s2.p.y+l2*R.y); mesh.m[1].p.z = s2.p.z; mesh.m[1].p.w = s2.p.w; - mesh.m[2].p.x = EDevice._x2real(s1.p.x-l1*R.x); mesh.m[2].p.y = EDevice._y2real(s1.p.y-l1*R.y); mesh.m[2].p.z = s2.p.z; mesh.m[2].p.w = s2.p.w; - mesh.m[3].p.x = EDevice._x2real(s2.p.x-l2*R.x); mesh.m[3].p.y = EDevice._y2real(s2.p.y-l2*R.y); mesh.m[3].p.z = s2.p.z; mesh.m[3].p.w = s2.p.w; - - mesh.setcolor (color); - - DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP,2,(FVF::TL*)&mesh,4,false,false); -/* - float radius = size*0.5f; - - Fvector P1,P2; - P1.direct (pos,D,radius); - P2.direct (pos,D,-radius); +void CTLSprite::Render(Fvector &pos, u32 color, float radius, const Fvector &D) +{ + Fvector P1, P2; + P1.mad(pos, D, -radius); + P2.mad(pos, D, radius); - FVF::TL s1,s2; - s1.transform (P1,EDevice.m_FullTransform); - s2.transform (P2,EDevice.m_FullTransform); + FVF::TL s1, s2; + s1.transform(P1, EDevice.mFullTransform); + s2.transform(P2, EDevice.mFullTransform); - if ((s1.p.w<=0)||(s2.p.w<=0)) return; + if ((s1.p.w<=0)||(s2.p.w<=0)) + return; - float l1 = radius/s1.p.w*1.4142f; + float l1 = radius/s1.p.w*1.4142f; float l2 = radius/s2.p.w*1.4142f; - Fvector2 dir,R; - dir.set (s2.p.x-s1.p.x,s2.p.y-s1.p.y); - dir.norm (); - R.cross (dir); - - mesh.m[0].p.x = X_TO_REAL(s1.p.x+l1*R.x); mesh.m[0].p.y = Y_TO_REAL(s1.p.y+l1*R.y); mesh.m[0].p.z = s1.p.z; mesh.m[0].p.w = s1.p.w; - mesh.m[1].p.x = X_TO_REAL(s2.p.x+l2*R.x); mesh.m[1].p.y = Y_TO_REAL(s2.p.y+l2*R.y); mesh.m[1].p.z = s2.p.z; mesh.m[1].p.w = s2.p.w; - mesh.m[2].p.x = X_TO_REAL(s1.p.x-l1*R.x); mesh.m[2].p.y = Y_TO_REAL(s1.p.y-l1*R.y); mesh.m[2].p.z = s1.p.z; mesh.m[2].p.w = s1.p.w; - mesh.m[3].p.x = X_TO_REAL(s2.p.x-l2*R.x); mesh.m[3].p.y = Y_TO_REAL(s2.p.y-l2*R.y); mesh.m[3].p.z = s2.p.z; mesh.m[3].p.w = s2.p.w; -// mesh.m[1].p.x = X_TO_REAL(s2.p.x); mesh.m[1].p.y = Y_TO_REAL(s2.p.y); mesh.m[1].p.z = s2.p.z; mesh.m[1].p.w = s2.p.w; -// mesh.m[1].tu = 0.5f; mesh.m[1].tv = 0.f; - - mesh.setcolor (RGBA_MAKE(iFloor(color.r),iFloor(color.g),iFloor(color.b),iFloor(color.a))); - - EDevice.DP (D3DPT_TRIANGLESTRIP, FVF::F_TL, &mesh, 4); -*/ -/* Fvector2 dir; - dir.x = p1.x-p0.x; - dir.y = p1.y-p0.y; - dir.norm_safe (); - - Fvector P0,P1; - P0.direct (pos,); - - FVF::TL P; - P.transform (pos,EDevice.m_FullTransform); - float sz = UI->GetRenderWidth()*radius/P.p.w; - float sz0 = radius/P.p.w;//(radius/p0.w)/2; - float sz1 = radius/P.p.w;//radius/p1.w; - Fvector2 D,R; - D.x = (dir.x-dir.y)*0.7071f; - D.y = (dir.x+dir.y)*0.7071f; - R.cross (D); - - float cx = X_TO_REAL(P.p.x); - float cy = Y_TO_REAL(P.p.y); - - mesh.m[0].p.x = X_TO_REAL(p0.x+sz0*R.x); mesh.m[0].p.y = Y_TO_REAL(p0.y+sz0*R.y); - mesh.m[1].p.x = X_TO_REAL(p1.x+sz1*R.x); mesh.m[1].p.y = Y_TO_REAL(p1.y+sz1*R.y); - mesh.m[2].p.x = X_TO_REAL(p0.x-sz0*R.x); mesh.m[2].p.y = Y_TO_REAL(p0.y-sz0*R.y); - mesh.m[3].p.x = X_TO_REAL(p1.x-sz1*R.x); mesh.m[3].p.y = Y_TO_REAL(p1.y-sz1*R.y); - - mesh.setdepth (P.p.z, P.p.w); - mesh.setcolor (RGBA_MAKE(iFloor(color.r),iFloor(color.g),iFloor(color.b),iFloor(color.a))); - - EDevice.DP (D3DPT_TRIANGLESTRIP, FVF::F_TL, &mesh, 4); -*/ + Fvector2 dir, R; + dir.set(s2.p.x-s1.p.x, s2.p.y-s1.p.y); + dir.norm(); + R.cross(dir); + + mesh.m[0].p.x = EDevice._x2real(s1.p.x+l1*R.x); + mesh.m[0].p.y = EDevice._y2real(s1.p.y+l1*R.y); + mesh.m[0].p.z = s2.p.z; + mesh.m[0].p.w = s2.p.w; + mesh.m[1].p.x = EDevice._x2real(s2.p.x+l2*R.x); + mesh.m[1].p.y = EDevice._y2real(s2.p.y+l2*R.y); + mesh.m[1].p.z = s2.p.z; + mesh.m[1].p.w = s2.p.w; + mesh.m[2].p.x = EDevice._x2real(s1.p.x-l1*R.x); + mesh.m[2].p.y = EDevice._y2real(s1.p.y-l1*R.y); + mesh.m[2].p.z = s2.p.z; + mesh.m[2].p.w = s2.p.w; + mesh.m[3].p.x = EDevice._x2real(s2.p.x-l2*R.x); + mesh.m[3].p.y = EDevice._y2real(s2.p.y-l2*R.y); + mesh.m[3].p.z = s2.p.z; + mesh.m[3].p.w = s2.p.w; + + mesh.setcolor(color); + + DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP, 2, (FVF::TL*)&mesh, 4, false, false); + /* + float radius = size*0.5f; + + Fvector P1,P2; + P1.direct (pos,D,radius); + P2.direct (pos,D,-radius); + + FVF::TL s1,s2; + s1.transform (P1,EDevice.m_FullTransform); + s2.transform (P2,EDevice.m_FullTransform); + + if ((s1.p.w<=0)||(s2.p.w<=0)) return; + + float l1 = radius/s1.p.w*1.4142f; + float l2 = radius/s2.p.w*1.4142f; + + Fvector2 dir,R; + dir.set (s2.p.x-s1.p.x,s2.p.y-s1.p.y); + dir.norm (); + R.cross (dir); + + mesh.m[0].p.x = X_TO_REAL(s1.p.x+l1*R.x); mesh.m[0].p.y = Y_TO_REAL(s1.p.y+l1*R.y); mesh.m[0].p.z = s1.p.z; mesh.m[0].p.w = s1.p.w; + mesh.m[1].p.x = X_TO_REAL(s2.p.x+l2*R.x); mesh.m[1].p.y = Y_TO_REAL(s2.p.y+l2*R.y); mesh.m[1].p.z = s2.p.z; mesh.m[1].p.w = s2.p.w; + mesh.m[2].p.x = X_TO_REAL(s1.p.x-l1*R.x); mesh.m[2].p.y = Y_TO_REAL(s1.p.y-l1*R.y); mesh.m[2].p.z = s1.p.z; mesh.m[2].p.w = s1.p.w; + mesh.m[3].p.x = X_TO_REAL(s2.p.x-l2*R.x); mesh.m[3].p.y = Y_TO_REAL(s2.p.y-l2*R.y); mesh.m[3].p.z = s2.p.z; mesh.m[3].p.w = s2.p.w; + // mesh.m[1].p.x = X_TO_REAL(s2.p.x); mesh.m[1].p.y = Y_TO_REAL(s2.p.y); mesh.m[1].p.z = s2.p.z; mesh.m[1].p.w = s2.p.w; + // mesh.m[1].tu = 0.5f; mesh.m[1].tv = 0.f; + + mesh.setcolor (RGBA_MAKE(iFloor(color.r),iFloor(color.g),iFloor(color.b),iFloor(color.a))); + + EDevice.DP (D3DPT_TRIANGLESTRIP, FVF::F_TL, &mesh, 4); + */ + /* Fvector2 dir; + dir.x = p1.x-p0.x; + dir.y = p1.y-p0.y; + dir.norm_safe (); + + Fvector P0,P1; + P0.direct (pos,); + + FVF::TL P; + P.transform (pos,EDevice.m_FullTransform); + float sz = UI->GetRenderWidth()*radius/P.p.w; + float sz0 = radius/P.p.w;//(radius/p0.w)/2; + float sz1 = radius/P.p.w;//radius/p1.w; + Fvector2 D,R; + D.x = (dir.x-dir.y)*0.7071f; + D.y = (dir.x+dir.y)*0.7071f; + R.cross (D); + + float cx = X_TO_REAL(P.p.x); + float cy = Y_TO_REAL(P.p.y); + + mesh.m[0].p.x = X_TO_REAL(p0.x+sz0*R.x); mesh.m[0].p.y = Y_TO_REAL(p0.y+sz0*R.y); + mesh.m[1].p.x = X_TO_REAL(p1.x+sz1*R.x); mesh.m[1].p.y = Y_TO_REAL(p1.y+sz1*R.y); + mesh.m[2].p.x = X_TO_REAL(p0.x-sz0*R.x); mesh.m[2].p.y = Y_TO_REAL(p0.y-sz0*R.y); + mesh.m[3].p.x = X_TO_REAL(p1.x-sz1*R.x); mesh.m[3].p.y = Y_TO_REAL(p1.y-sz1*R.y); + + mesh.setdepth (P.p.z, P.p.w); + mesh.setcolor (RGBA_MAKE(iFloor(color.r),iFloor(color.g),iFloor(color.b),iFloor(color.a))); + + EDevice.DP (D3DPT_TRIANGLESTRIP, FVF::F_TL, &mesh, 4); + */ } /* @@ -165,13 +189,13 @@ void CTLSprite::UpdateTC(){ float tu,tv; int frame; - float fSPF = fPlayTime/float(iCount); - fLocalTime +=EDevice.fTimeDelta; - if (fLocalTime>=fPlayTime) fLocalTime-=fPlayTime; - frame = iFloor( fLocalTime/fSPF ); + float fSPF = fPlayTime/float(iCount); + fLocalTime +=EDevice.fTimeDelta; + if (fLocalTime>=fPlayTime) fLocalTime-=fPlayTime; + frame = iFloor( fLocalTime/fSPF ); - tu =(frame%iFrameDim)*fTexSize; - tv =(frame/iFrameDim)*fTexSize; + tu =(frame%iFrameDim)*fTexSize; + tv =(frame/iFrameDim)*fTexSize; mesh.m[0].tu=tu+fTexSize; mesh.m[0].tv=tv+fTexSize; mesh.m[1].tu=tu; mesh.m[1].tv=tv+fTexSize; @@ -181,32 +205,33 @@ void CTLSprite::UpdateTC(){ void CTLSprite::Render( Fvector &pos, float alpha, float size, float scale ) { - FTLvertex P; - FPcolor cur; - float s_da, s_da2, c_da, c_da2; - uchar cc; + FTLvertex P; + FPcolor cur; + float s_da, s_da2, c_da, c_da2; + uchar cc; - P.s_transform ( pos, UI->m_FullTransform ); - float cx = X_TO_REAL(P.sx); - float cy = Y_TO_REAL(P.sy); + P.s_transform ( pos, UI->m_FullTransform ); + float cx = X_TO_REAL(P.sx); + float cy = Y_TO_REAL(P.sy); - float dx = size/P.rhw * scale * UI->GetRenderWidth() / 2; - float dy = size/P.rhw / scale * UI->GetRenderWidth() / 2; + float dx = size/P.rhw * scale * UI->GetRenderWidth() / 2; + float dy = size/P.rhw / scale * UI->GetRenderWidth() / 2; - cc = uchar(255.f*alpha); - cur.set (cc,cc,cc,255); + cc = uchar(255.f*alpha); + cur.set (cc,cc,cc,255); - c_da = dy*0.707106f; - s_da = -dx*0.707106f; + c_da = dy*0.707106f; + s_da = -dx*0.707106f; - mesh.m[0].sx = cx + s_da; mesh.m[0].sy = cy + c_da; - mesh.m[1].sx = cx + s_da; mesh.m[1].sy = cy - c_da; - mesh.m[3].sx = cx - s_da; mesh.m[3].sy = cy - c_da; - mesh.m[2].sx = cx - s_da; mesh.m[2].sy = cy + c_da; + mesh.m[0].sx = cx + s_da; mesh.m[0].sy = cy + c_da; + mesh.m[1].sx = cx + s_da; mesh.m[1].sy = cy - c_da; + mesh.m[3].sx = cx - s_da; mesh.m[3].sy = cy - c_da; + mesh.m[2].sx = cx - s_da; mesh.m[2].sy = cy + c_da; - mesh.setdepth ( P.sz, P.rhw ); - mesh.setcolor ( cur ); + mesh.setdepth ( P.sz, P.rhw ); + mesh.setcolor ( cur ); CDX( UI->d3d()->DrawPrimitive( D3DPT_TRIANGLESTRIP, FTLVERTEX, &mesh, 4, 0 )); UI->stat->lRenderPolyCount += 2; }*/ + diff --git a/src/editors/ECore/Editor/TLSPRITE.h b/src/editors/ECore/Editor/TLSPRITE.h index 0057f4d38b3..c360da08e27 100644 --- a/src/editors/ECore/Editor/TLSPRITE.h +++ b/src/editors/ECore/Editor/TLSPRITE.h @@ -3,77 +3,202 @@ #define TO_REAL(_X_, _S_) ((_X_)+1.f)*float(_S_/2) -typedef struct _TLpolygon { +typedef struct _TLpolygon +{ public: - union{ - struct{ - FVF::TL lb, lt, rb, rt; - }; - FVF::TL m[4]; - }; - - IC void* d3d (void) { return this; } - IC void setpos (Frect &r) { lb.p.x=r.x1; lb.p.y=r.y2;lt.p.x=r.x1;lt.p.y=r.y1;rb.p.x=r.x2;rb.p.y=r.y2;rt.p.x=r.x2;rt.p.y=r.y1;} - IC void setpos (float x1, float y1, float x2, float y2){ lb.p.x=x1; lb.p.y=y2; lt.p.x=x1; lt.p.y=y1; rb.p.x=x2; rb.p.y=y2; rt.p.x=x2; rt.p.y=y1;} - IC void setdepth(float z = 0.f, float rhw = 1.f) { lb.p.z=z; rb.p.z= z; lt.p.z = z; rt.p.z = z; lb.p.w = rhw; rb.p.w = rhw; lt.p.w = rhw; rt.p.w = rhw;}; - IC void setcolor(u32 c) { lb.color=c; rb.color=c; lt.color=c; rt.color=c; }; - IC void settex (Frect &r) { lb.uv.x = r.x1; lb.uv.y = r.y2; lt.uv.x = r.x1; lt.uv.y = r.y1; rb.uv.x = r.x2; rb.uv.y = r.y2; rt.uv.x = r.x2; rt.uv.y = r.y1; } - IC void settex (float x1, float y1, float x2, float y2){ lb.uv.x=x1; lb.uv.y=y2; lt.uv.x=x1; lt.uv.y=y1; rb.uv.x=x2; rb.uv.y=y2; rt.uv.x=x2; rt.uv.y=y1;} - - IC void to_real (int w, int h) - { - lt.p.x=lb.p.x=TO_REAL(lb.p.x, w); rb.p.x=rt.p.x=TO_REAL(rb.p.x, w); - lt.p.y=rt.p.y=TO_REAL(lt.p.y, h); lb.p.y=rb.p.y=TO_REAL(lb.p.y, h); - } - - IC void to_real (Frect &r, int w, int h) - { - lt.p.x=lb.p.x=TO_REAL(r.x1, w); lt.p.y=rt.p.y=TO_REAL(r.y1, h); - rb.p.x=rt.p.x=TO_REAL(r.x2, w); lb.p.y=rb.p.y=TO_REAL(r.y2, h); - } - - IC void add (float dx, float dy) - { - lb.p.x+=dx; lb.p.y+=dy; lt.p.x+=dx; lt.p.y+=dy; - rb.p.x+=dx; rb.p.y+=dy; rt.p.x+=dx; rt.p.y+=dy; - } - - IC void add (Frect &r, float dx, float dy) - { - lb.p.x=r.x1+dx; lb.p.y=r.y2+dy; lt.p.x=r.x1+dx; lt.p.y=r.y1+dy; - rb.p.x=r.x2+dx; rb.p.y=r.y2+dy; rt.p.x=r.x2+dx; rt.p.y=r.y1+dy; - } - - IC void sub (float dx, float dy) - { - lb.p.x-=dx; lb.p.y-=dy; lt.p.x-=dx; lt.p.y-=dy; - rb.p.x-=dx; rb.p.y-=dy; rt.p.x-=dx; rt.p.y-=dy; - } - - IC void sub (Frect &r, float dx, float dy) - { - lb.p.x=r.x1-dx; lb.p.y=r.y2-dy; lt.p.x=r.x1-dx; lt.p.y=r.y1-dy; - rb.p.x=r.x2-dx; rb.p.y=r.y2-dy; rt.p.x=r.x2-dx; rt.p.y=r.y1-dy; - } + union + { + struct + { + FVF::TL lb, lt, rb, rt; + }; + + FVF::TL m[4]; + }; + + IC + + void *d3d(void) + { + return this; + } + + IC + + void setpos(Frect &r) + { + lb.p.x = r.x1; + lb.p.y = r.y2; + lt.p.x = r.x1; + lt.p.y = r.y1; + rb.p.x = r.x2; + rb.p.y = r.y2; + rt.p.x = r.x2; + rt.p.y = r.y1; + } + + IC + + void setpos(float x1, float y1, float x2, float y2) + { + lb.p.x = x1; + lb.p.y = y2; + lt.p.x = x1; + lt.p.y = y1; + rb.p.x = x2; + rb.p.y = y2; + rt.p.x = x2; + rt.p.y = y1; + } + + IC + + void setdepth(float z = 0.f, float rhw = 1.f) + { + lb.p.z = z; + rb.p.z = z; + lt.p.z = z; + rt.p.z = z; + lb.p.w = rhw; + rb.p.w = rhw; + lt.p.w = rhw; + rt.p.w = rhw; + }; + + IC + + void setcolor(u32 c) + { + lb.color = c; + rb.color = c; + lt.color = c; + rt.color = c; + }; + + IC + + void settex(Frect &r) + { + lb.uv.x = r.x1; + lb.uv.y = r.y2; + lt.uv.x = r.x1; + lt.uv.y = r.y1; + rb.uv.x = r.x2; + rb.uv.y = r.y2; + rt.uv.x = r.x2; + rt.uv.y = r.y1; + } + + IC + + void settex(float x1, float y1, float x2, float y2) + { + lb.uv.x = x1; + lb.uv.y = y2; + lt.uv.x = x1; + lt.uv.y = y1; + rb.uv.x = x2; + rb.uv.y = y2; + rt.uv.x = x2; + rt.uv.y = y1; + } + + IC + + void to_real(int w, int h) + { + lt.p.x = lb.p.x = TO_REAL(lb.p.x, w); + rb.p.x = rt.p.x = TO_REAL(rb.p.x, w); + lt.p.y = rt.p.y = TO_REAL(lt.p.y, h); + lb.p.y = rb.p.y = TO_REAL(lb.p.y, h); + } + + IC + + void to_real(Frect &r, int w, int h) + { + lt.p.x = lb.p.x = TO_REAL(r.x1, w); + lt.p.y = rt.p.y = TO_REAL(r.y1, h); + rb.p.x = rt.p.x = TO_REAL(r.x2, w); + lb.p.y = rb.p.y = TO_REAL(r.y2, h); + } + + IC + + void add(float dx, float dy) + { + lb.p.x += dx; + lb.p.y += dy; + lt.p.x += dx; + lt.p.y += dy; + rb.p.x += dx; + rb.p.y += dy; + rt.p.x += dx; + rt.p.y += dy; + } + + IC + + void add(Frect &r, float dx, float dy) + { + lb.p.x = r.x1+dx; + lb.p.y = r.y2+dy; + lt.p.x = r.x1+dx; + lt.p.y = r.y1+dy; + rb.p.x = r.x2+dx; + rb.p.y = r.y2+dy; + rt.p.x = r.x2+dx; + rt.p.y = r.y1+dy; + } + + IC + + void sub(float dx, float dy) + { + lb.p.x -= dx; + lb.p.y -= dy; + lt.p.x -= dx; + lt.p.y -= dy; + rb.p.x -= dx; + rb.p.y -= dy; + rt.p.x -= dx; + rt.p.y -= dy; + } + + IC + + void sub(Frect &r, float dx, float dy) + { + lb.p.x = r.x1-dx; + lb.p.y = r.y2-dy; + lt.p.x = r.x1-dx; + lt.p.y = r.y1-dy; + rb.p.x = r.x2-dx; + rb.p.y = r.y2-dy; + rt.p.x = r.x2-dx; + rt.p.y = r.y1-dy; + } } FTLpolygon; -class ECORE_API CTLSprite +class ECORE_API CTLSprite { - FTLpolygon mesh; -public: - CTLSprite ( ); - virtual ~CTLSprite ( ); - void Render ( Fvector &pos, u32 color, float radius, float angle ); - IC void Render ( Fvector &pos, u32 color, float radius, float angle, const Fvector2& lt, const Fvector2& rb ){ - mesh.settex (lt.x,lt.y,rb.x,rb.y); - Render (pos,color,radius,angle); + FTLpolygon mesh; + public: + CTLSprite(); + virtual ~CTLSprite(); + void Render(Fvector&pos, u32 color, float radius, float angle); + IC void Render(Fvector&pos, u32 color, float radius, float angle, const Fvector2<, const Fvector2&rb){ + mesh.settex(lt.x, lt.y, rb.x, rb.y); + Render(pos, color, radius, angle); } - void Render ( Fvector &pos, u32 color, float radius, const Fvector& D ); - IC void Render ( Fvector &pos, u32 color, float radius, const Fvector& D, const Fvector2& lt, const Fvector2& rb){ - mesh.settex (lt.x,lt.y,rb.x,rb.y); - Render (pos,color,radius,D); + void Render(Fvector&pos, u32 color, float radius, const Fvector&D); + IC void Render(Fvector&pos, u32 color, float radius, const Fvector&D, const Fvector2<, const Fvector2&rb){ + mesh.settex(lt.x, lt.y, rb.x, rb.y); + Render(pos, color, radius, D); } - void Render ( Fvector &pos, float radius, bool bFixedSize, u32 clr=0xffffffff ); + void Render(Fvector&pos, float radius, bool bFixedSize, u32 clr = 0xffffffff); }; #endif //__TLSPRITE_H__ + + diff --git a/src/editors/ECore/Editor/UI_Camera.cpp b/src/editors/ECore/Editor/UI_Camera.cpp index 699059a0b01..bfe6726c8f3 100644 --- a/src/editors/ECore/Editor/UI_Camera.cpp +++ b/src/editors/ECore/Editor/UI_Camera.cpp @@ -3,104 +3,133 @@ #include "UI_Camera.h" #include "ui_main.h" -#include "ui_toolscustom.h" +#include "UI_ToolsCustom.h" CUI_Camera::CUI_Camera() { - m_Style = csPlaneMove; + m_Style = csPlaneMove; - m_Znear = 0.2f; - m_Zfar = 1500.f; - m_HPB.set(0,0,0); - m_Position.set(0,0,0); - m_Target.set(0,0,0); + m_Znear = 0.2f; + m_Zfar = 1500.f; + m_HPB.set(0, 0, 0); + m_Position.set(0, 0, 0); + m_Target.set(0, 0, 0); m_CamMat.identity(); - m_FlySpeed = 5.f; + m_FlySpeed = 5.f; m_FlyAltitude = 1.8f; - m_bMoving=false; + m_bMoving = false; } -CUI_Camera::~CUI_Camera() -{ -} +CUI_Camera::~CUI_Camera() {} void CUI_Camera::SetStyle(ECameraStyle new_style) { - if (new_style==cs3DArcBall){ - Fvector dir; - dir.sub (m_Target,m_Position); + if (new_style==cs3DArcBall) + { + Fvector dir; + dir.sub(m_Target, m_Position); // parse heading - Fvector DYaw; DYaw.set(dir.x,0.f,dir.z); DYaw.normalize_safe(); - if (DYaw.x<0) m_HPB.x = acosf(DYaw.z); - else m_HPB.x = 2*PI-acosf(DYaw.z); + Fvector DYaw; + DYaw.set(dir.x, 0.f, dir.z); + DYaw.normalize_safe(); + if (DYaw.x<0) + m_HPB.x = acosf(DYaw.z); + else + m_HPB.x = 2*PI-acosf(DYaw.z); // parse pitch - dir.normalize_safe (); - m_HPB.y = asinf(dir.y); + dir.normalize_safe(); + m_HPB.y = asinf(dir.y); - BuildCamera (); + BuildCamera(); } - m_Style = new_style; + m_Style = new_style; UI->RedrawScene(); } void CUI_Camera::Reset() { - m_HPB.set(0,0,0); - m_Position.set(0,3,-10); - SetStyle(m_Style); + m_HPB.set(0, 0, 0); + m_Position.set(0, 3, -10); + SetStyle(m_Style); BuildCamera(); } void CUI_Camera::Set(float h, float p, float b, float x, float y, float z) { - m_HPB.set(h,p,b); - m_Position.set(x,y,z); + m_HPB.set(h, p, b); + m_Position.set(x, y, z); BuildCamera(); } -void CUI_Camera::Set(const Fvector& hpb, const Fvector& pos) +void CUI_Camera::Set(const Fvector &hpb, const Fvector &pos) { - m_HPB.set(hpb); + m_HPB.set(hpb); m_Position.set(pos); BuildCamera(); } void CUI_Camera::BuildCamera() { - if (m_HPB.x>PI_MUL_2) m_HPB.x-=PI_MUL_2; if (m_HPB.x<-PI_MUL_2) m_HPB.x+=PI_MUL_2; - if (m_HPB.y>PI_MUL_2) m_HPB.y-=PI_MUL_2; if (m_HPB.y<-PI_MUL_2) m_HPB.y+=PI_MUL_2; - if (m_HPB.z>PI_MUL_2) m_HPB.z-=PI_MUL_2; if (m_HPB.z<-PI_MUL_2) m_HPB.z+=PI_MUL_2; - - if (m_Style==cs3DArcBall){ - Fvector D; - D.setHP (m_HPB.x,m_HPB.y); - float dist = m_Position.distance_to(m_Target); - m_Position.mul (D,-dist); - m_Position.add (m_Target); + if (m_HPB.x>PI_MUL_2) + m_HPB.x -= PI_MUL_2; + if (m_HPB.x<-PI_MUL_2) + m_HPB.x += PI_MUL_2; + if (m_HPB.y>PI_MUL_2) + m_HPB.y -= PI_MUL_2; + if (m_HPB.y<-PI_MUL_2) + m_HPB.y += PI_MUL_2; + if (m_HPB.z>PI_MUL_2) + m_HPB.z -= PI_MUL_2; + if (m_HPB.z<-PI_MUL_2) + m_HPB.z += PI_MUL_2; + + if (m_Style==cs3DArcBall) + { + Fvector D; + D.setHP(m_HPB.x, m_HPB.y); + float dist = m_Position.distance_to(m_Target); + m_Position.mul(D, -dist); + m_Position.add(m_Target); } - m_CamMat.setHPB(m_HPB.x,m_HPB.y,m_HPB.z); + m_CamMat.setHPB(m_HPB.x, m_HPB.y, m_HPB.z); m_CamMat.translate_over(m_Position); UI->OutCameraPos(); - - EDevice.vCameraPosition.set (m_CamMat.c); - EDevice.vCameraDirection.set (m_CamMat.k); - EDevice.vCameraTop.set (m_CamMat.j); - EDevice.vCameraRight.set (m_CamMat.i); + + EDevice.vCameraPosition.set(m_CamMat.c); + EDevice.vCameraDirection.set(m_CamMat.k); + EDevice.vCameraTop.set(m_CamMat.j); + EDevice.vCameraRight.set(m_CamMat.i); } void CUI_Camera::SetDepth(float _far, bool bForcedUpdate) { - if (m_Zfar!=_far) {m_Zfar=_far; UI->Resize(bForcedUpdate);} + if (m_Zfar!=_far) + { + m_Zfar = _far; + UI->Resize(bForcedUpdate); + } } void CUI_Camera::SetViewport(float _near, float _far, float _fov) { - if (m_Znear!=_near) {m_Znear=_near; UI->Resize();} - if (m_Zfar!=_far) {m_Zfar=_far; UI->Resize();} - if (EDevice.fFOV!=_fov) {EDevice.fFOV=_fov; UI->Resize();} + if (m_Znear!=_near) + { + m_Znear = _near; + UI->Resize(); + } + if (m_Zfar!=_far) + { + m_Zfar = _far; + UI->Resize(); + } + if (EDevice.fFOV!=_fov) + { + EDevice.fFOV = _fov; + UI->Resize(); + } } void CUI_Camera::SetSensitivity(float sm, float sr) @@ -109,31 +138,35 @@ void CUI_Camera::SetSensitivity(float sm, float sr) m_SR = 0.02f*(sr*sr); } -static const Fvector down_dir={0.f,-1.f,0.f}; +static const Fvector down_dir = {0.f,-1.f,0.f}; void CUI_Camera::Update(float dt) { - if (m_bMoving){ - BOOL bLeftDn = m_Shift.Contains(ssLeft); - BOOL bRightDn = m_Shift.Contains(ssRight); - if ((m_Style==csFreeFly)&&(bLeftDn||bRightDn)&&!(bLeftDn&&bRightDn)){ - Fvector vmove; - vmove.set( m_CamMat.k ); - vmove.mul( m_FlySpeed*dt ); - if (bLeftDn) m_Position.add( vmove ); - else if (bRightDn) m_Position.sub( vmove ); - - if (m_Shift.Contains(ssCtrl)){ + if (m_bMoving) + { + BOOL bLeftDn = m_Shift.Contains(ssLeft); + BOOL bRightDn = m_Shift.Contains(ssRight); + if ((m_Style==csFreeFly)&&(bLeftDn||bRightDn)&&!(bLeftDn&&bRightDn)) + { + Fvector vmove; + vmove.set(m_CamMat.k); + vmove.mul(m_FlySpeed*dt); + if (bLeftDn) + m_Position.add(vmove); + else if (bRightDn) + m_Position.sub(vmove); + + if (m_Shift.Contains(ssCtrl)) + { float dist = UI->ZFar(); - if (Tools->RayPick(m_Position,down_dir,dist))//UI->R PickGround(pos,m_Position,dir,-1)) - m_Position.y = m_Position.y+down_dir.y*dist+m_FlyAltitude; + if (Tools->RayPick(m_Position, down_dir, dist))//UI->R PickGround(pos,m_Position,dir,-1)) + m_Position.y = m_Position.y+down_dir.y*dist+m_FlyAltitude; else - m_Position.y = m_FlyAltitude; - + m_Position.y = m_FlyAltitude; } - UI->RedrawScene(); - } + UI->RedrawScene(); + } BuildCamera(); } } @@ -141,15 +174,17 @@ void CUI_Camera::Update(float dt) void CUI_Camera::Pan(float dx, float dz) { Fvector vmove; - vmove.set( m_CamMat.k ); vmove.y = 0; + vmove.set(m_CamMat.k); + vmove.y = 0; vmove.normalize_safe(); - vmove.mul( dz*-m_SM ); - m_Position.add( vmove ); + vmove.mul(dz*-m_SM); + m_Position.add(vmove); - vmove.set( m_CamMat.i ); vmove.y = 0; + vmove.set(m_CamMat.i); + vmove.y = 0; vmove.normalize_safe(); - vmove.mul( dx*m_SM ); - m_Position.add( vmove ); + vmove.mul(dx*m_SM); + m_Position.add(vmove); BuildCamera(); } @@ -157,43 +192,46 @@ void CUI_Camera::Pan(float dx, float dz) void CUI_Camera::Scale(float dy) { Fvector vmove; - vmove.set( 0.f, dy, 0.f ); + vmove.set(0.f, dy, 0.f); vmove.y *= -m_SM; - m_Position.add( vmove ); + m_Position.add(vmove); BuildCamera(); } void CUI_Camera::Rotate(float dx, float dy) { - m_HPB.x-=m_SR*dx; - m_HPB.y-=m_SR*dy*EDevice.fASPECT; + m_HPB.x -= m_SR*dx; + m_HPB.y -= m_SR*dy*EDevice.fASPECT; BuildCamera(); } bool CUI_Camera::MoveStart(TShiftState Shift) { - if (Shift.Contains(ssShift)){ - if (!m_bMoving){ - ShowCursor (FALSE); - UI->IR_GetMousePosScreen(m_StartPos); - m_bMoving = true; + if (Shift.Contains(ssShift)) + { + if (!m_bMoving) + { + ShowCursor(FALSE); + UI->IR_GetMousePosScreen(m_StartPos); + m_bMoving = true; } - m_Shift = Shift; + m_Shift = Shift; return true; } - m_Shift = Shift; + m_Shift = Shift; return false; } bool CUI_Camera::MoveEnd(TShiftState Shift) { - m_Shift = Shift; - if (!Shift.Contains(ssLeft)||!Shift.Contains(ssShift)){ - SetCursorPos(m_StartPos.x, m_StartPos.y); - ShowCursor (TRUE); - m_bMoving = false; + m_Shift = Shift; + if (!Shift.Contains(ssLeft)||!Shift.Contains(ssShift)) + { + SetCursorPos(m_StartPos.x, m_StartPos.y); + ShowCursor(TRUE); + m_bMoving = false; return true; } return false; @@ -201,143 +239,169 @@ bool CUI_Camera::MoveEnd(TShiftState Shift) bool CUI_Camera::Process(TShiftState Shift, int dx, int dy) { - if (m_bMoving){ + if (m_bMoving) + { m_Shift = Shift; -// camera move - if( dx || dy ){ - SetCursorPos(m_StartPos.x,m_StartPos.y); - switch (m_Style){ - case csPlaneMove: - if (m_Shift.Contains(ssLeft) && m_Shift.Contains(ssRight)) Rotate (dx,dy); - else if (m_Shift.Contains(ssLeft)) Pan (dx,dy); - else if(m_Shift.Contains(ssRight)) Scale (dy); - break; - case csFreeFly: - if (m_Shift.Contains(ssLeft)||m_Shift.Contains(ssRight)) Rotate (dx,dy); -// if (Shift.Contains(ssLeft)) Rotate (d.x,d.y); -// else if (Shift.Contains(ssRight)) Scale(d.y); - break; - case cs3DArcBall: - ArcBall(m_Shift,dx,dy); - break; + // camera move + if (dx||dy) + { + SetCursorPos(m_StartPos.x, m_StartPos.y); + switch (m_Style) + { + case csPlaneMove: + if (m_Shift.Contains(ssLeft)&&m_Shift.Contains(ssRight)) + Rotate(dx, dy); + else if (m_Shift.Contains(ssLeft)) + Pan(dx, dy); + else if (m_Shift.Contains(ssRight)) + Scale(dy); + break; + case csFreeFly: + if (m_Shift.Contains(ssLeft)||m_Shift.Contains(ssRight)) + Rotate(dx, dy); + // if (Shift.Contains(ssLeft)) Rotate (d.x,d.y); + // else if (Shift.Contains(ssRight)) Scale(d.y); + break; + case cs3DArcBall: + ArcBall(m_Shift, dx, dy); + break; } - UI->RedrawScene(); + UI->RedrawScene(); } return true; - } + } return false; } bool CUI_Camera::KeyDown(WORD Key, TShiftState Shift) { - if (m_bMoving){ - switch (Key){ - case VK_CONTROL: m_Shift<>ssShift; MoveEnd(m_Shift); break; - case VK_CONTROL: m_Shift>>ssCtrl; break; - default: return false; + if (m_bMoving) + { + switch (Key) + { + case VK_SHIFT: m_Shift>>ssShift; + MoveEnd(m_Shift); + break; + case VK_CONTROL: m_Shift>>ssCtrl; + break; + default: return false; } - return true; + return true; } - return false; + return false; } -void CUI_Camera::MouseRayFromPoint( Fvector& start, Fvector& direction, const Ivector2& point ) +void CUI_Camera::MouseRayFromPoint(Fvector &start, Fvector &direction, const Ivector2 &point) { - int halfwidth = UI->GetRealWidth()*0.5f; - int halfheight = UI->GetRealHeight()*0.5f; + int halfwidth = UI->GetRealWidth()*0.5f; + int halfheight = UI->GetRealHeight()*0.5f; - if (!halfwidth||!halfheight) return; + if (!halfwidth||!halfheight) + return; Ivector2 point2; point2.set(point.x-halfwidth, halfheight-point.y); - start.set( m_Position ); + start.set(m_Position); - float size_y = m_Znear * tan( deg2rad(EDevice.fFOV) * 0.5f ); - float size_x = size_y / EDevice.fASPECT; + float size_y = m_Znear*tan(deg2rad(EDevice.fFOV)*0.5f); + float size_x = size_y/EDevice.fASPECT; - float r_pt = float(point2.x) * size_x / (float) halfwidth; - float u_pt = float(point2.y) * size_y / (float) halfheight; + float r_pt = float(point2.x)*size_x/(float) halfwidth; + float u_pt = float(point2.y)*size_y/(float) halfheight; - direction.mul( m_CamMat.k, m_Znear ); - direction.mad( direction, m_CamMat.j, u_pt ); - direction.mad( direction, m_CamMat.i, r_pt ); - direction.normalize(); + direction.mul(m_CamMat.k, m_Znear); + direction.mad(direction, m_CamMat.j, u_pt); + direction.mad(direction, m_CamMat.i, r_pt); + direction.normalize(); } -void CUI_Camera::ZoomExtents(const Fbox& bb) +void CUI_Camera::ZoomExtents(const Fbox &bb) { - Fvector C,D; - float R,H1,H2; - bb.getsphere(C,R); - D.mul(m_CamMat.k,-1); + Fvector C, D; + float R, H1, H2; + bb.getsphere(C, R); + D.mul(m_CamMat.k, -1); H1 = R/sinf(deg2rad(EDevice.fFOV)*0.5f); H2 = R/sinf(deg2rad(EDevice.fFOV)*0.5f/EDevice.fASPECT); - m_Position.mad(C,D,_max(H1,H2)); - m_Target.set(C); - - BuildCamera(); -/* - eye_k - фокусное расстояние, eye_k=eye_width/2 - camera.alfa:=0; - camera.beta:=-30*pi/180; - camera.gama:=0; - s:=(maxx-minx)*eye_k/eye_width*0.5*0.5; - camera.posx:=(maxx+minx)/2; - camera.posy:=maxy+s*tan(30*pi/180); - camera.posz:=minz-s; -*/ + m_Position.mad(C, D, _max(H1, H2)); + m_Target.set(C); + + BuildCamera(); + /* + eye_k - фокусное расстояние, eye_k=eye_width/2 + camera.alfa:=0; + camera.beta:=-30*pi/180; + camera.gama:=0; + s:=(maxx-minx)*eye_k/eye_width*0.5*0.5; + camera.posx:=(maxx+minx)/2; + camera.posy:=maxy+s*tan(30*pi/180); + camera.posz:=minz-s; + */ } void CUI_Camera::ArcBall(TShiftState Shift, float dx, float dy) { - float dist = m_Position.distance_to(m_Target); - if (Shift.Contains(ssAlt)){ - if (Shift.Contains(ssLeft)){ + float dist = m_Position.distance_to(m_Target); + if (Shift.Contains(ssAlt)) + { + if (Shift.Contains(ssLeft)) + { Fvector vmove; - vmove.set( m_CamMat.k ); vmove.y = 0; + vmove.set(m_CamMat.k); + vmove.y = 0; vmove.normalize_safe(); - vmove.mul( dy*-m_SM ); - m_Target.add( vmove ); + vmove.mul(dy*-m_SM); + m_Target.add(vmove); - vmove.set( m_CamMat.i ); vmove.y = 0; + vmove.set(m_CamMat.i); + vmove.y = 0; vmove.normalize_safe(); - vmove.mul( dx*m_SM ); - m_Target.add( vmove ); - }else if(Shift.Contains(ssRight)){ + vmove.mul(dx*m_SM); + m_Target.add(vmove); + } + else if (Shift.Contains(ssRight)) + { Fvector vmove; - vmove.set( 0.f, dy, 0.f ); + vmove.set(0.f, dy, 0.f); vmove.y *= -m_SM; - m_Target.add( vmove ); + m_Target.add(vmove); + } + } + else + { + if (Shift.Contains(ssRight)) + { + dist -= dx*m_SM; + } + else if (Shift.Contains(ssLeft)) + { + m_HPB.x -= m_SR*dx; + m_HPB.y -= m_SR*dy*EDevice.fASPECT; } - }else{ - if (Shift.Contains(ssRight)){ - dist -= dx*m_SM; - }else if (Shift.Contains(ssLeft)){ - m_HPB.x-=m_SR*dx; - m_HPB.y-=m_SR*dy*EDevice.fASPECT; - } } Fvector D; - D.setHP (m_HPB.x,m_HPB.y); + D.setHP(m_HPB.x, m_HPB.y); - m_Position.mul (D,-dist); - m_Position.add (m_Target); + m_Position.mul(D, -dist); + m_Position.add(m_Target); - BuildCamera (); + BuildCamera(); } - diff --git a/src/editors/ECore/Editor/UI_Camera.h b/src/editors/ECore/Editor/UI_Camera.h index cf005042cb1..1ee4d587c0d 100644 --- a/src/editors/ECore/Editor/UI_Camera.h +++ b/src/editors/ECore/Editor/UI_Camera.h @@ -2,80 +2,82 @@ #ifndef UI_CameraH #define UI_CameraH -enum ECameraStyle{ - csPlaneMove=0, - cs3DArcBall, +enum ECameraStyle +{ + csPlaneMove=0, + cs3DArcBall, csFreeFly }; class ECORE_API CUI_Camera{ - ECameraStyle m_Style; - bool m_bMoving; - TShiftState m_Shift; - Ivector2 m_StartPos; - float m_FlySpeed; - float m_FlyAltitude; + ECameraStyle m_Style; + bool m_bMoving; + TShiftState m_Shift; + Ivector2 m_StartPos; + float m_FlySpeed; + float m_FlyAltitude; - Fmatrix m_CamMat; - Fvector m_HPB; - Fvector m_Position; - Fvector m_Target; -protected: - friend class CEditorRenderDevice; - friend class TUI; + Fmatrix m_CamMat; + Fvector m_HPB; + Fvector m_Position; + Fvector m_Target; + protected: + friendclass CEditorRenderDevice; + friendclass TUI; - float m_Znear; - float m_Zfar; - float m_SR, m_SM; + float m_Znear; + float m_Zfar; + float m_SR, m_SM; - void Pan (float X, float Z); - void Scale (float Y); - void Rotate (float X, float Y); - void ArcBall (TShiftState Shift, float X, float Y); -public: - CUI_Camera (); - virtual ~CUI_Camera (); + void Pan(float X, float Z); + void Scale(float Y); + void Rotate(float X, float Y); + void ArcBall(TShiftState Shift, float X, float Y); + public: + CUI_Camera(); + virtual ~CUI_Camera(); - IC float _Znear (){return m_Znear;} - IC float _Zfar (){return m_Zfar;} + IC float _Znear(){return m_Znear;} + IC float _Zfar(){return m_Zfar;} - void BuildCamera (); - void Reset (); - void Update (float dt); - void SetStyle (ECameraStyle style); - ECameraStyle GetStyle (){return m_Style;} + void BuildCamera(); + void Reset(); + void Update(float dt); + void SetStyle(ECameraStyle style); + ECameraStyle GetStyle(){return m_Style;} - bool MoveStart (TShiftState Shift); - bool MoveEnd (TShiftState Shift); - bool IsMoving (){return m_bMoving;} - bool Process (TShiftState Shift, int dx, int dy); - bool KeyDown (WORD Key, TShiftState Shift); - bool KeyUp (WORD Key, TShiftState Shift); + bool MoveStart(TShiftState Shift); + bool MoveEnd(TShiftState Shift); + bool IsMoving(){return m_bMoving;} + bool Process(TShiftState Shift, int dx, int dy); + bool KeyDown(WORD Key, TShiftState Shift); + bool KeyUp(WORD Key, TShiftState Shift); - void ViewFront (){m_HPB.set(0.f,0.f,0.f); BuildCamera();} - void ViewBack (){m_HPB.set(M_PI,0.f,0.f); BuildCamera();} - void ViewLeft (){m_HPB.set(-PI_DIV_2,0.f,0.f); BuildCamera();} - void ViewRight (){m_HPB.set(PI_DIV_2,0.f,0.f); BuildCamera();} - void ViewTop (){m_HPB.set(0.f,-PI_DIV_2,0.f); BuildCamera();} - void ViewBottom (){m_HPB.set(0.f,PI_DIV_2,0.f); BuildCamera();} - void ViewReset (){m_HPB.set(0.f,0,0.f); m_Position.set(0,0,0); m_Target.set(0,0,0); BuildCamera();} + void ViewFront(){m_HPB.set(0.f, 0.f, 0.f); BuildCamera();} + void ViewBack(){m_HPB.set(M_PI, 0.f, 0.f); BuildCamera();} + void ViewLeft(){m_HPB.set(-PI_DIV_2, 0.f, 0.f); BuildCamera();} + void ViewRight(){m_HPB.set(PI_DIV_2, 0.f, 0.f); BuildCamera();} + void ViewTop(){m_HPB.set(0.f, -PI_DIV_2, 0.f); BuildCamera();} + void ViewBottom(){m_HPB.set(0.f, PI_DIV_2, 0.f); BuildCamera();} + void ViewReset(){m_HPB.set(0.f, 0, 0.f); m_Position.set(0, 0, 0); m_Target.set(0, 0, 0); BuildCamera();} - const Fmatrix& GetTransform() const {return m_CamMat;} - const Fmatrix& GetView (Fmatrix& V) const {return V.invert(m_CamMat);} - const Fvector& GetHPB () const {return m_HPB;} - const Fvector& GetPosition () const {return m_Position;} - const Fvector& GetRight () const {return m_CamMat.i;} - const Fvector& GetNormal () const {return m_CamMat.j;} - const Fvector& GetDirection() const {return m_CamMat.k;} - void Set (float h, float p, float b, float x, float y, float z); - void Set (const Fvector& hpb, const Fvector& pos); - void SetSensitivity(float sm, float sr); - void SetViewport (float _near, float _far, float _fov); - void SetDepth (float _far, bool bForcedUpdate); - void SetFlyParams(float speed, float fAltitude){ m_FlySpeed=speed; m_FlyAltitude=fAltitude; } + const Fmatrix&GetTransform() const{return m_CamMat;} + const Fmatrix&GetView(Fmatrix&V) const{return V.invert(m_CamMat);} + const Fvector&GetHPB() const{return m_HPB;} + const Fvector&GetPosition() const{return m_Position;} + const Fvector&GetRight() const{return m_CamMat.i;} + const Fvector&GetNormal() const{return m_CamMat.j;} + const Fvector&GetDirection() const{return m_CamMat.k;} + void Set(float h, float p, float b, float x, float y, float z); + void Set(const Fvector&hpb, const Fvector&pos); + void SetSensitivity(float sm, float sr); + void SetViewport(float _near, float _far, float _fov); + void SetDepth(float _far, bool bForcedUpdate); + void SetFlyParams(float speed, float fAltitude){m_FlySpeed = speed; m_FlyAltitude = fAltitude;} - void ZoomExtents (const Fbox& bb); + void ZoomExtents(const Fbox&bb); - void MouseRayFromPoint(Fvector& start, Fvector& direction, const Ivector2& point); + void MouseRayFromPoint(Fvector&start, Fvector&direction, const Ivector2&point); }; #endif + diff --git a/src/editors/ECore/Editor/UI_MainCommand.cpp b/src/editors/ECore/Editor/UI_MainCommand.cpp index 3ff83c0c548..69807abb6c2 100644 --- a/src/editors/ECore/Editor/UI_MainCommand.cpp +++ b/src/editors/ECore/Editor/UI_MainCommand.cpp @@ -9,228 +9,289 @@ #include "ImageEditor.h" #include "MinimapEditor.h" #include "SoundEditor.h" -#include "d3dutils.h" +#include "D3DUtils.h" -#include "PSLibrary.h" +#include "Layers/xrRender/PSLibrary.h" #include "Library.h" -#include "LightAnimLibrary.h" +#include "xrEngine/LightAnimLibrary.h" #include "ImageManager.h" #include "SoundManager.h" -#include "ResourceManager.h" -#include "igame_persistent.h" -#include "NumericVector.h" +#include "Layers/xrRender/ResourceManager.h" +#include "xrEngine/IGame_Persistent.h" +#include "editors/xrEProps/NumericVector.h" -#include "TextForm.h" +#include "editors/xrEProps/TextForm.h" -ECommandVec ECommands; -BOOL bAllowReceiveCommand = FALSE; -BOOL bAllowLogCommands = FALSE; -TfrmText* frmEditCommandList = 0; -AnsiString sCommandListText; +ECommandVec ECommands; +BOOL bAllowReceiveCommand = FALSE; +BOOL bAllowLogCommands = FALSE; +TfrmText *frmEditCommandList = 0; +AnsiString sCommandListText; BOOL AllowLogCommands() { - return bAllowLogCommands; + return bAllowLogCommands; } -ECommandVec& GetEditorCommands() +ECommandVec &GetEditorCommands() { - return ECommands; + return ECommands; } -void EnableReceiveCommands() + +void EnableReceiveCommands() { - bAllowReceiveCommand = TRUE; + bAllowReceiveCommand = TRUE; } -SESubCommand* FindCommandByShortcut(const xr_shortcut& val) + +SESubCommand *FindCommandByShortcut(const xr_shortcut &val) { - ECommandVec& cmds = GetEditorCommands(); - for (u32 cmd_idx=0; cmd_idxeditable){ - VERIFY(!CMD->sub_commands.empty()); - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; - if (SUB_CMD->shortcut.similar(val)) return SUB_CMD; + ECommandVec&cmds = GetEditorCommands(); + for (u32 cmd_idx = 0; cmd_idxeditable) + { + VERIFY(!CMD->sub_commands.empty()); + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*& SUB_CMD = CMD->sub_commands[sub_cmd_idx]; + if (SUB_CMD->shortcut.similar(val)) + return SUB_CMD; } } } return 0; } -SECommand* FindCommandByName(LPCSTR nm) + +SECommand *FindCommandByName(LPCSTR nm) { - ECommandVec& cmds = GetEditorCommands(); - for (u32 cmd_idx=0; cmd_idxname,nm))) return CMD; + ECommandVec&cmds = GetEditorCommands(); + for (u32 cmd_idx = 0; cmd_idxname, nm))) + return CMD; } return 0; } -SESubCommand* FindSubCommandByName(SECommand* CMD, LPCSTR nm) + +SESubCommand *FindSubCommandByName(SECommand *CMD, LPCSTR nm) { - VERIFY(CMD && !CMD->sub_commands.empty()); - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand* SUB_CMD = CMD->sub_commands[sub_cmd_idx]; - if (0==stricmp(SUB_CMD->desc.c_str(),nm)) return SUB_CMD; + VERIFY(CMD&&!CMD->sub_commands.empty()); + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*SUB_CMD = CMD->sub_commands[sub_cmd_idx]; + if (0==stricmp(SUB_CMD->desc.c_str(), nm)) + return SUB_CMD; } return 0; } -void ParseParam(xr_string sp, CCommandVar& res) + +void ParseParam(xr_string sp, CCommandVar &res) { - if (!sp.empty()){ - u32 rs=0,ip=0; - if (0==strstr(sp.c_str(),"\"")) - rs = sscanf(sp.c_str(),"%d",&ip); - if (1!=rs){ - _GetItem(sp.c_str(),1,sp,'\"'); - if (!sp.empty()) res = sp; - }else res = ip; + if (!sp.empty()) + { + u32 rs = 0, ip = 0; + if (0==strstr(sp.c_str(), "\"")) + rs = sscanf(sp.c_str(), "%d", &ip); + if (1!=rs) + { + _GetItem(sp.c_str(), 1, sp, '\"'); + if (!sp.empty()) + res = sp; + } + else + res = ip; } } -CCommandVar ExecCommand (const xr_shortcut& val) + +CCommandVar ExecCommand(const xr_shortcut &val) { - SESubCommand* SUB = FindCommandByShortcut(val); - CCommandVar res = CCommandVar(u32(0)); + SESubCommand*SUB = FindCommandByShortcut(val); + CCommandVar res = CCommandVar(u32(0)); if (SUB) - res = ExecCommand(SUB->parent->idx,SUB->p0,SUB->p1); + res = ExecCommand(SUB->parent->idx, SUB->p0, SUB->p1); return res; } -CCommandVar ExecCommand (u32 cmd, CCommandVar p1, CCommandVar p2) -{ - if (!bAllowReceiveCommand) return 0; - - VERIFY (cmdcommand.empty()); - static int exec_level= 0; - if (bAllowLogCommands){ - string128 level;strcpy(level,exec_level==0?"":";"); - for(int k=0; kName(),sp1.c_str(),sp2.c_str()); - else if (p1.IsInteger()&&p2.IsInteger())Msg("%s%s (%d,%d)", level,CMD->Name(),u32(p1),u32(p2)); - else if (p1.IsInteger()&&p2.IsString()) Msg("%s%s (%d,\"%s\")", level,CMD->Name(),u32(p1),sp2.c_str()); - else if (p1.IsString()&&p2.IsInteger()) Msg("%s%s (\"%s\",%d)", level,CMD->Name(),sp1.c_str(),u32(p2)); + +CCommandVar ExecCommand(u32 cmd, CCommandVar p1, CCommandVar p2) +{ + if (!bAllowReceiveCommand) + return 0; + + VERIFY(cmdcommand.empty()); + static int exec_level = 0; + if (bAllowLogCommands) + { + string128 level; + strcpy(level, exec_level==0 ? "" : ";"); + for (int k = 0; kName(), sp1.c_str(), sp2.c_str()); + else if (p1.IsInteger()&&p2.IsInteger()) + Msg("%s%s (%d,%d)", level, CMD->Name(), u32(p1), u32(p2)); + else if (p1.IsInteger()&&p2.IsString()) + Msg("%s%s (%d,\"%s\")", level, CMD->Name(), u32(p1), sp2.c_str()); + else if (p1.IsString()&&p2.IsInteger()) + Msg("%s%s (\"%s\",%d)", level, CMD->Name(), sp1.c_str(), u32(p2)); } exec_level++; - res = CMD->command(p1,p2); - exec_level--; VERIFY(exec_level>=0); + res = CMD->command(p1, p2); + exec_level--; + VERIFY(exec_level>=0); return res; } -void RegisterCommand (u32 cmd, SECommand* cmd_impl) + +void RegisterCommand(u32 cmd, SECommand *cmd_impl) { - if (cmd>=ECommands.size()) - ECommands.resize(cmd+1,0); - SECommand*& CMD = ECommands[cmd]; - if (CMD){ - Msg ("RegisterCommand: command '%s' overridden by command '%s'.",*CMD->desc,*cmd_impl->desc); - xr_delete (CMD); + if (cmd>=ECommands.size()) + ECommands.resize(cmd+1, 0); + SECommand*& CMD = ECommands[cmd]; + if (CMD) + { + Msg("RegisterCommand: command '%s' overridden by command '%s'.", *CMD->desc, *cmd_impl->desc); + xr_delete(CMD); } - CMD = cmd_impl; -} -void RegisterSubCommand(SECommand* cmd_impl, LPCSTR desc, CCommandVar p0, CCommandVar p1) -{ - VERIFY (cmd_impl); - cmd_impl->AppendSubCommand(desc,p0,p1); -} -BOOL LoadShortcuts(CInifile* ini) -{ - for (u32 cmd_idx=0; cmd_idxeditable){ - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand*& SUB = CMD->sub_commands[sub_cmd_idx]; - string256 nm,tmp; - if (SUB->desc.size()) sprintf(nm,"%s.\"%s\"",CMD->Name(),SUB->desc.c_str()); - else sprintf(nm,"%s",CMD->Name()); - if (ini->line_exist("shortcuts",nm)){ - LPCSTR val = ini->r_string("shortcuts",nm); - int res = sscanf(val,"%d,%s",&SUB->shortcut.hotkey,tmp); - if (2==res){ - xr_string sp; - _GetItem (tmp,0,sp); - ParseParam (sp,SUB->p0); - _GetItem (tmp,1,sp); - ParseParam (sp,SUB->p1); + CMD = cmd_impl; +} + +void RegisterSubCommand(SECommand *cmd_impl, LPCSTR desc, CCommandVar p0, CCommandVar p1) +{ + VERIFY(cmd_impl); + cmd_impl->AppendSubCommand(desc, p0, p1); +} + +BOOL LoadShortcuts(CInifile *ini) +{ + for (u32 cmd_idx = 0; cmd_idxeditable) + { + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*& SUB = CMD->sub_commands[sub_cmd_idx]; + string256 nm, tmp; + if (SUB->desc.size()) + sprintf(nm, "%s.\"%s\"", CMD->Name(), SUB->desc.c_str()); + else + sprintf(nm, "%s", CMD->Name()); + if (ini->line_exist("shortcuts", nm)) + { + LPCSTR val = ini->r_string("shortcuts", nm); + int res = sscanf(val, "%d,%s", &SUB->shortcut.hotkey, tmp); + if (2==res) + { + xr_string sp; + _GetItem(tmp, 0, sp); + ParseParam(sp, SUB->p0); + _GetItem(tmp, 1, sp); + ParseParam(sp, SUB->p1); } } } } } - return TRUE; -} -BOOL SaveShortcuts(CInifile* ini) -{ - for (u32 cmd_idx=0; cmd_idxeditable){ - for (u32 sub_cmd_idx=0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++){ - SESubCommand*& SUB = CMD->sub_commands[sub_cmd_idx]; - string256 nm,tmp; - if (SUB->desc.size()) sprintf(nm,"%s.\"%s\"",CMD->Name(),SUB->desc.c_str()); - else sprintf(nm,"%s",CMD->Name()); - if (SUB->p0.IsString()&&SUB->p1.IsString()) sprintf(tmp,"%d, \"%s\",\"%s\"",SUB->shortcut.hotkey,xr_string(SUB->p0).c_str(),xr_string(SUB->p1).c_str()); - else if (SUB->p0.IsInteger()&&SUB->p1.IsInteger()) sprintf(tmp,"%d, %d,%d", SUB->shortcut.hotkey,u32(SUB->p0),u32(SUB->p1)); - else if (SUB->p0.IsInteger()&&SUB->p1.IsString()) sprintf(tmp,"%d, %d,\"%s\"", SUB->shortcut.hotkey,u32(SUB->p0),xr_string(SUB->p1).c_str()); - else if (SUB->p0.IsString()&&SUB->p1.IsInteger()) sprintf(tmp,"%d, \"%s\",%d", SUB->shortcut.hotkey,xr_string(SUB->p0).c_str(),u32(SUB->p1)); - ini->w_string ("shortcuts",nm,tmp); + return TRUE; +} + +BOOL SaveShortcuts(CInifile *ini) +{ + for (u32 cmd_idx = 0; cmd_idxeditable) + { + for (u32 sub_cmd_idx = 0; sub_cmd_idxsub_commands.size(); sub_cmd_idx++) + { + SESubCommand*& SUB = CMD->sub_commands[sub_cmd_idx]; + string256 nm, tmp; + if (SUB->desc.size()) + sprintf(nm, "%s.\"%s\"", CMD->Name(), SUB->desc.c_str()); + else + sprintf(nm, "%s", CMD->Name()); + if (SUB->p0.IsString()&&SUB->p1.IsString()) + sprintf(tmp, "%d, \"%s\",\"%s\"", SUB->shortcut.hotkey, xr_string(SUB->p0).c_str(), xr_string(SUB->p1).c_str()); + else if (SUB->p0.IsInteger()&&SUB->p1.IsInteger()) + sprintf(tmp, "%d, %d,%d", SUB->shortcut.hotkey, u32(SUB->p0), u32(SUB->p1)); + else if (SUB->p0.IsInteger()&&SUB->p1.IsString()) + sprintf(tmp, "%d, %d,\"%s\"", SUB->shortcut.hotkey, u32(SUB->p0), xr_string(SUB->p1).c_str()); + else if (SUB->p0.IsString()&&SUB->p1.IsInteger()) + sprintf(tmp, "%d, \"%s\",%d", SUB->shortcut.hotkey, xr_string(SUB->p0).c_str(), u32(SUB->p1)); + ini->w_string("shortcuts", nm, tmp); } } } - return TRUE; + return TRUE; } -void ClearCommands() + +void ClearCommands() { - for (ECommandVecIt it=ECommands.begin(); it!=ECommands.end(); it++) - xr_delete (*it); - ECommands.clear (); + for (ECommandVecIt it = ECommands.begin(); it!=ECommands.end(); it++) + xr_delete(*it); + ECommands.clear(); } -void TUI::ClearCommands () +void TUI::ClearCommands() { - ::ClearCommands (); + ::ClearCommands(); } //------------------------------------------------------------------------------ // UI Commands //------------------------------------------------------------------------------ -CCommandVar TUI::CommandRenderFocus(CCommandVar p1, CCommandVar p2) +CCommandVar TUI::CommandRenderFocus(CCommandVar p1, CCommandVar p2) { if (((TForm*)m_D3DWindow->Owner)->Visible&&m_bReady) m_D3DWindow->SetFocus(); return 1; } -CCommandVar TUI::CommandBreakLastOperation(CCommandVar p1, CCommandVar p2) + +CCommandVar TUI::CommandBreakLastOperation(CCommandVar p1, CCommandVar p2) { - if (mrYes==ELog.DlgMsg(mtConfirmation,TMsgDlgButtons() << mbYes << mbNo,"Are you sure to break current action?")){ - NeedBreak (); - ELog.Msg (mtInformation,"Execution canceled."); + if (mrYes==ELog.DlgMsg(mtConfirmation, TMsgDlgButtons()<Width,h=m_D3DPanel->Height,w_2=w/2,h_2=h/2; + if (psDeviceFlags.is(rsDrawSafeRect)) + { + int w = m_D3DPanel->Width, h = m_D3DPanel->Height, w_2 = w/2, h_2 = h/2; Irect rect; - if ((0.75f*float(w))>float(h)) rect.set(w_2-1.33f*float(h_2),0,1.33f*h,h); - else rect.set(0,h_2-0.75f*float(w_2),w,0.75f*w); - m_D3DWindow->Left = rect.x1; - m_D3DWindow->Top = rect.y1; - m_D3DWindow->Width = rect.x2; - m_D3DWindow->Height = rect.y2; - }else{ - m_D3DWindow->Left = 0; - m_D3DWindow->Top = 0; - m_D3DWindow->Width = m_D3DPanel->Width; - m_D3DWindow->Height = m_D3DPanel->Height; + if ((0.75f*float(w))>float(h)) + rect.set(w_2-1.33f*float(h_2), 0, 1.33f*h, h); + else + rect.set(0, h_2-0.75f*float(w_2), w, 0.75f*w); + m_D3DWindow->Left = rect.x1; + m_D3DWindow->Top = rect.y1; + m_D3DWindow->Width = rect.x2; + m_D3DWindow->Height = rect.y2; + } + else + { + m_D3DWindow->Left = 0; + m_D3DWindow->Top = 0; + m_D3DWindow->Width = m_D3DPanel->Width; + m_D3DWindow->Height = m_D3DPanel->Height; } - UI->RedrawScene (); + UI->RedrawScene(); return 1; } @@ -239,504 +300,581 @@ CCommandVar TUI::CommandRenderResize(CCommandVar p1, CCommandVar p2) //------------------------------------------------------------------------------ CCommandVar CommandInitialize(CCommandVar p1, CCommandVar p2) { - CCommandVar res = TRUE; - Engine.Initialize (); + CCommandVar res = TRUE; + Engine.Initialize(); // make interface //---------------- - EPrefs->OnCreate (); - if (UI->OnCreate((TD3DWindow*)(u32)p1,(TPanel*)(u32)p2)) + EPrefs->OnCreate(); + if (UI->OnCreate((TD3DWindow*)(u32)p1, (TPanel*)(u32)p2)) { - ExecCommand (COMMAND_CREATE_SOUND_LIB); R_ASSERT(SndLib); + ExecCommand(COMMAND_CREATE_SOUND_LIB); + R_ASSERT(SndLib); SndLib->OnCreate(); - LALib.OnCreate (); - Lib.OnCreate (); + LALib.OnCreate(); + Lib.OnCreate(); BOOL bWeather = psDeviceFlags.is(rsEnvironment); psDeviceFlags.set(rsEnvironment, FALSE); - g_pGamePersistent= xr_new(); + g_pGamePersistent = xr_new(); if (Tools->OnCreate()) { - EPrefs->Load(); + EPrefs->Load(); EDevice.seqAppStart.Process(rp_AppStart); - ExecCommand (COMMAND_RESTORE_UI_BAR); - ExecCommand (COMMAND_REFRESH_UI_BAR); - ExecCommand (COMMAND_CLEAR); - ExecCommand (COMMAND_RENDER_FOCUS); - ExecCommand (COMMAND_CHANGE_ACTION, etaSelect); - ExecCommand (COMMAND_RENDER_RESIZE); -/* - if(bWeather && EPrefs->sWeather.size() ) - { - psDeviceFlags.set(rsEnvironment, TRUE); - g_pGamePersistent->Environment().SetWeather(EPrefs->sWeather, true); - - } -*/ - }else{ - res = FALSE; + ExecCommand(COMMAND_RESTORE_UI_BAR); + ExecCommand(COMMAND_REFRESH_UI_BAR); + ExecCommand(COMMAND_CLEAR); + ExecCommand(COMMAND_RENDER_FOCUS); + ExecCommand(COMMAND_CHANGE_ACTION, etaSelect); + ExecCommand(COMMAND_RENDER_RESIZE); + /* + if(bWeather && EPrefs->sWeather.size() ) + { + psDeviceFlags.set(rsEnvironment, TRUE); + g_pGamePersistent->Environment().SetWeather(EPrefs->sWeather, true); + + } + */ } - }else{ - res = FALSE; + else + { + res = FALSE; + } + } + else + { + res = FALSE; } return res; -} -CCommandVar CommandDestroy(CCommandVar p1, CCommandVar p2) +} + +CCommandVar CommandDestroy(CCommandVar p1, CCommandVar p2) { - ExecCommand (COMMAND_SAVE_UI_BAR); - EPrefs->OnDestroy (); - ExecCommand (COMMAND_CLEAR); + ExecCommand(COMMAND_SAVE_UI_BAR); + EPrefs->OnDestroy(); + ExecCommand(COMMAND_CLEAR); EDevice.seqAppEnd.Process(rp_AppEnd); - xr_delete (g_pGamePersistent); - LALib.OnDestroy (); - Tools->OnDestroy (); - SndLib->OnDestroy (); - xr_delete (SndLib); - Lib.OnDestroy (); - UI->OnDestroy (); - Engine.Destroy (); - return TRUE; -} -CCommandVar CommandQuit(CCommandVar p1, CCommandVar p2) + xr_delete(g_pGamePersistent); + LALib.OnDestroy(); + Tools->OnDestroy(); + SndLib->OnDestroy(); + xr_delete(SndLib); + Lib.OnDestroy(); + UI->OnDestroy(); + Engine.Destroy(); + return TRUE; +} + +CCommandVar CommandQuit(CCommandVar p1, CCommandVar p2) { - UI->Quit (); - return TRUE; -} -CCommandVar CommandEditorPrefs(CCommandVar p1, CCommandVar p2) + UI->Quit(); + return TRUE; +} + +CCommandVar CommandEditorPrefs(CCommandVar p1, CCommandVar p2) { - EPrefs->Edit (); - return TRUE; -} -CCommandVar CommandChangeAction(CCommandVar p1, CCommandVar p2) + EPrefs->Edit(); + return TRUE; +} + +CCommandVar CommandChangeAction(CCommandVar p1, CCommandVar p2) { - Tools->SetAction (ETAction(u32(p1))); - return TRUE; -} -CCommandVar CommandChangeAxis(CCommandVar p1, CCommandVar p2) + Tools->SetAction(ETAction(u32(p1))); + return TRUE; +} + +CCommandVar CommandChangeAxis(CCommandVar p1, CCommandVar p2) { - Tools->SetAxis (ETAxis(u32(p1))); - return TRUE; + Tools->SetAxis(ETAxis(u32(p1))); + return TRUE; } -CCommandVar CommandSimulate(CCommandVar p1, CCommandVar p2) +CCommandVar CommandSimulate(CCommandVar p1, CCommandVar p2) { + Tools->Simulate(); - Tools->Simulate(); - - return TRUE; + return TRUE; } -CCommandVar CommandUseSimulatePositions(CCommandVar p1, CCommandVar p2) +CCommandVar CommandUseSimulatePositions(CCommandVar p1, CCommandVar p2) { + Tools->UseSimulatePositions(); - Tools->UseSimulatePositions(); - - return TRUE; + return TRUE; } - -CCommandVar CommandSetSettings(CCommandVar p1, CCommandVar p2) +CCommandVar CommandSetSettings(CCommandVar p1, CCommandVar p2) { - Tools->SetSettings(p1,p2); - return TRUE; -} -CCommandVar CommandSoundEditor(CCommandVar p1, CCommandVar p2) + Tools->SetSettings(p1, p2); + return TRUE; +} + +CCommandVar CommandSoundEditor(CCommandVar p1, CCommandVar p2) { TfrmSoundLib::EditLib(AnsiString("Sound Editor")); - return TRUE; + return TRUE; } -CCommandVar CommandSyncSounds(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandSyncSounds(CCommandVar p1, CCommandVar p2) { - if (ELog.DlgMsg(mtConfirmation,TMsgDlgButtons() << mbYes << mbNo,"Are you sure to synchronize sounds?")==mrYes) + if (ELog.DlgMsg(mtConfirmation, TMsgDlgButtons()<RefreshSounds(true); - return TRUE; + return TRUE; } -CCommandVar CommandImageEditor(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandImageEditor(CCommandVar p1, CCommandVar p2) { TfrmImageLib::EditLib(AnsiString("Image Editor")); - return TRUE; + return TRUE; } -CCommandVar CommandMinimapEditor(CCommandVar p1, CCommandVar p2) +CCommandVar CommandMinimapEditor(CCommandVar p1, CCommandVar p2) { - TTMinimapEditor::Show (); - return TRUE; + TTMinimapEditor::Show(); + return TRUE; } -CCommandVar CommandCheckTextures(CCommandVar p1, CCommandVar p2) +CCommandVar CommandCheckTextures(CCommandVar p1, CCommandVar p2) { TfrmImageLib::ImportTextures(); - return TRUE; + return TRUE; } -CCommandVar CommandRefreshTextures(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandRefreshTextures(CCommandVar p1, CCommandVar p2) { - if (ELog.DlgMsg(mtConfirmation,TMsgDlgButtons() << mbYes << mbNo,"Are you sure to synchronize textures?")==mrYes) + if (ELog.DlgMsg(mtConfirmation, TMsgDlgButtons()<RedrawScene (); - return TRUE; + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandChangeSnap(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandChangeSnap(CCommandVar p1, CCommandVar p2) { ((TExtBtn*)(u32)p1)->Down = !((TExtBtn*)(u32)p1)->Down; - return TRUE; + return TRUE; } -CCommandVar CommandUnloadTextures(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandUnloadTextures(CCommandVar p1, CCommandVar p2) { EDevice.UnloadTextures(); - return TRUE; + return TRUE; } -CCommandVar CommandEvictObjects(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandEvictObjects(CCommandVar p1, CCommandVar p2) { - Lib.EvictObjects (); - return TRUE; + Lib.EvictObjects(); + return TRUE; } -CCommandVar CommandEvictTextures(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandEvictTextures(CCommandVar p1, CCommandVar p2) { EDevice.Resources->Evict(); - return TRUE; + return TRUE; } -CCommandVar CommandCheckModified(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandCheckModified(CCommandVar p1, CCommandVar p2) { - return Tools->IsModified(); + return Tools->IsModified(); } -CCommandVar CommandExit(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandExit(CCommandVar p1, CCommandVar p2) { - return Tools->IfModified(); + return Tools->IfModified(); } -CCommandVar CommandShowProperties(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandShowProperties(CCommandVar p1, CCommandVar p2) { - if(p1.IsString()) + if (p1.IsString()) { - xr_string SSS = p1; - Tools->ShowProperties(SSS.c_str()); - }else - Tools->ShowProperties(NULL); - return TRUE; + xr_string SSS = p1; + Tools->ShowProperties(SSS.c_str()); + } + else + Tools->ShowProperties(NULL); + return TRUE; } -CCommandVar CommandUpdateProperties(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandUpdateProperties(CCommandVar p1, CCommandVar p2) { Tools->UpdateProperties(p1); - return TRUE; + return TRUE; } -CCommandVar CommandRefreshProperties(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandRefreshProperties(CCommandVar p1, CCommandVar p2) { Tools->RefreshProperties(); - return TRUE; + return TRUE; } -CCommandVar CommandZoomExtents(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandZoomExtents(CCommandVar p1, CCommandVar p2) { - Tools->ZoomObject (p1); - UI->RedrawScene (); - return TRUE; + Tools->ZoomObject(p1); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandToggleRenderWire(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandToggleRenderWire(CCommandVar p1, CCommandVar p2) { - if (EDevice.dwFillMode!=D3DFILL_WIREFRAME) EDevice.dwFillMode = D3DFILL_WIREFRAME; - else EDevice.dwFillMode = D3DFILL_SOLID; - UI->RedrawScene (); - return TRUE; + if (EDevice.dwFillMode!=D3DFILL_WIREFRAME) + EDevice.dwFillMode = D3DFILL_WIREFRAME; + else + EDevice.dwFillMode = D3DFILL_SOLID; + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandToggleSafeRect(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandToggleSafeRect(CCommandVar p1, CCommandVar p2) { - psDeviceFlags.set (rsDrawSafeRect,!psDeviceFlags.is(rsDrawSafeRect)); - ExecCommand (COMMAND_RENDER_RESIZE); - UI->RedrawScene (); - return TRUE; + psDeviceFlags.set(rsDrawSafeRect, !psDeviceFlags.is(rsDrawSafeRect)); + ExecCommand(COMMAND_RENDER_RESIZE); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandToggleGrid(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandToggleGrid(CCommandVar p1, CCommandVar p2) { - psDeviceFlags.set(rsDrawGrid,!psDeviceFlags.is(rsDrawGrid)); - UI->RedrawScene (); - return TRUE; + psDeviceFlags.set(rsDrawGrid, !psDeviceFlags.is(rsDrawGrid)); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandUpdateGrid(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandUpdateGrid(CCommandVar p1, CCommandVar p2) { - DU_impl.UpdateGrid (EPrefs->grid_cell_count,EPrefs->grid_cell_size); - UI->OutGridSize (); - UI->RedrawScene (); - return TRUE; + DU_impl.UpdateGrid(EPrefs->grid_cell_count, EPrefs->grid_cell_size); + UI->OutGridSize(); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandGridNumberOfSlots(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandGridNumberOfSlots(CCommandVar p1, CCommandVar p2) { - if (p1) EPrefs->grid_cell_count += 2; - else EPrefs->grid_cell_count -= 2; - ExecCommand (COMMAND_UPDATE_GRID); - UI->RedrawScene (); - return TRUE; + if (p1) + EPrefs->grid_cell_count += 2; + else + EPrefs->grid_cell_count -= 2; + ExecCommand(COMMAND_UPDATE_GRID); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandGridSlotSize(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandGridSlotSize(CCommandVar p1, CCommandVar p2) { float step = 1.f; float val = EPrefs->grid_cell_size; - if (p1){ - if (val<1) step/=10.f; + if (p1) + { + if (val<1) + step /= 10.f; EPrefs->grid_cell_size += step; - }else{ - if (fsimilar(val,1.f)||(val<1)) step/=10.f; + } + else + { + if (fsimilar(val, 1.f)||(val<1)) + step /= 10.f; EPrefs->grid_cell_size -= step; } - ExecCommand (COMMAND_UPDATE_GRID); - UI->RedrawScene (); - return TRUE; + ExecCommand(COMMAND_UPDATE_GRID); + UI->RedrawScene(); + return TRUE; } -CCommandVar CommandCreateSoundLib(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandCreateSoundLib(CCommandVar p1, CCommandVar p2) { - SndLib = xr_new(); - return TRUE; + SndLib = xr_new(); + return TRUE; } -CCommandVar CommandMuteSound(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandMuteSound(CCommandVar p1, CCommandVar p2) { - SndLib->MuteSounds (p1); - return TRUE; + SndLib->MuteSounds(p1); + return TRUE; } + CCommandVar CommandMoveCameraTo(CCommandVar p1, CCommandVar p2) { - Fvector pos = EDevice.m_Camera.GetPosition(); - if (NumericVectorRun ("Move to",&pos,3)) - EDevice.m_Camera.Set (EDevice.m_Camera.GetHPB(),pos); - return TRUE; -} - -CCommandVar ExecuteCommandList(LPCSTR text) -{ - CCommandVar res = TRUE; - IReader F ((void*)text,xr_strlen(text)); - while (!F.eof()){ - xr_string line, cmd, params, sp1, sp2; - F.r_string (line); - line = _Trim(line); - if (!line.empty()){ - if (line[0]==';' || (line[0]=='/'&&line[1]=='/')) continue; - _GetItem (line.c_str(),0,cmd,'('); - _GetItem (line.c_str(),1,params,'('); - _GetItem (params.c_str(),0,params,')'); - _GetItem (params.c_str(),0,sp1,','); - _GetItem (params.c_str(),1,sp2,','); + Fvector pos = EDevice.m_Camera.GetPosition(); + if (NumericVectorRun("Move to", &pos, 3)) + EDevice.m_Camera.Set(EDevice.m_Camera.GetHPB(), pos); + return TRUE; +} + +CCommandVar ExecuteCommandList(LPCSTR text) +{ + CCommandVar res = TRUE; + IReader F((void*)text, xr_strlen(text)); + while (!F.eof()) + { + xr_string line, cmd, params, sp1, sp2; + F.r_string(line); + line = _Trim(line); + if (!line.empty()) + { + if (line[0]==';'||(line[0]=='/'&&line[1]=='/')) + continue; + _GetItem(line.c_str(), 0, cmd, '('); + _GetItem(line.c_str(), 1, params, '('); + _GetItem(params.c_str(), 0, params, ')'); + _GetItem(params.c_str(), 0, sp1, ','); + _GetItem(params.c_str(), 1, sp2, ','); // parse cmd - xr_string cmd_name, sub_cmd_name; - _GetItem (cmd.c_str(),0,cmd_name,'.'); - _GetItem (cmd.c_str(),1,sub_cmd_name,'.'); - - SECommand* CMD = FindCommandByName(cmd_name.c_str()); - if (CMD){ - SESubCommand* SUB= FindSubCommandByName(CMD,sub_cmd_name.c_str()); - if (!sub_cmd_name.empty()&&!SUB){ - ELog.DlgMsg (mtError,"Can't find sub-command: '%s'",sub_cmd_name.c_str()); - res = FALSE; + xr_string cmd_name, sub_cmd_name; + _GetItem(cmd.c_str(), 0, cmd_name, '.'); + _GetItem(cmd.c_str(), 1, sub_cmd_name, '.'); + + SECommand*CMD = FindCommandByName(cmd_name.c_str()); + if (CMD) + { + SESubCommand*SUB = FindSubCommandByName(CMD, sub_cmd_name.c_str()); + if (!sub_cmd_name.empty()&&!SUB) + { + ELog.DlgMsg(mtError, "Can't find sub-command: '%s'", sub_cmd_name.c_str()); + res = FALSE; break; } // parse params - CCommandVar p1,p2; - if (SUB){ - p1 = SUB->p0; - p2 = SUB->p1; + CCommandVar p1, p2; + if (SUB) + { + p1 = SUB->p0; + p2 = SUB->p1; } - ParseParam (sp1,p1); - ParseParam (sp2,p2); + ParseParam(sp1, p1); + ParseParam(sp2, p2); // execute command - if (FALSE==ExecCommand(CMD->idx,p1,p2)){ - ELog.DlgMsg (mtError,"Can't execute command: '%s'",cmd.c_str()); - res = FALSE; + if (FALSE==ExecCommand(CMD->idx, p1, p2)) + { + ELog.DlgMsg(mtError, "Can't execute command: '%s'", cmd.c_str()); + res = FALSE; break; } - }else{ - ELog.DlgMsg (mtError,"Can't find command: '%s'",cmd.c_str()); - res = FALSE; + } + else + { + ELog.DlgMsg(mtError, "Can't find command: '%s'", cmd.c_str()); + res = FALSE; break; } } } - return res; + return res; } -bool OnRunExecuteListClick(LPCSTR txt) +bool OnRunExecuteListClick(LPCSTR txt) { - ExecuteCommandList (txt); + ExecuteCommandList(txt); return true; } -CCommandVar CommandExecuteCommandList(CCommandVar _p1, CCommandVar _p2) +CCommandVar CommandExecuteCommandList(CCommandVar _p1, CCommandVar _p2) { - xr_string cmds_text = _p1; - return ExecuteCommandList (cmds_text.c_str()); + xr_string cmds_text = _p1; + return ExecuteCommandList(cmds_text.c_str()); } bool __stdcall OnCloseCommandListEditor() { - frmEditCommandList = 0; - return true; + frmEditCommandList = 0; + return true; } -CCommandVar CommandEditCommandList(CCommandVar _p1, CCommandVar _p2) +CCommandVar CommandEditCommandList(CCommandVar _p1, CCommandVar _p2) { - if (NULL==frmEditCommandList){ - frmEditCommandList = TfrmText::CreateForm(sCommandListText,"Execute command list",0,0,"Run",OnRunExecuteListClick,OnCloseCommandListEditor); + if (NULL==frmEditCommandList) + { + frmEditCommandList = TfrmText::CreateForm(sCommandListText, "Execute command list", 0, 0, "Run", OnRunExecuteListClick, OnCloseCommandListEditor); return TRUE; } return FALSE; } -CCommandVar CommandLogCommands(CCommandVar _p1, CCommandVar _p2) +CCommandVar CommandLogCommands(CCommandVar _p1, CCommandVar _p2) { - bAllowLogCommands = _p1; - return TRUE; + bAllowLogCommands = _p1; + return TRUE; } -CCommandVar CommandRunMacro(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandRunMacro(CCommandVar p1, CCommandVar p2) { - xr_string fn; - if (p1.IsString()){ - fn = xr_string(p1); - IReader* F = FS.r_open(fn.c_str()); - if (NULL==F) F = FS.r_open(_import_,fn.c_str()); - if (F){ - ExecCommand (COMMAND_EXECUTE_COMMAND_LIST,xr_string((LPCSTR)F->pointer())); - FS.r_close (F); - return TRUE; + xr_string fn; + if (p1.IsString()) + { + fn = xr_string(p1); + IReader *F = FS.r_open(fn.c_str()); + if (NULL==F) + F = FS.r_open(_import_, fn.c_str()); + if (F) + { + ExecCommand(COMMAND_EXECUTE_COMMAND_LIST, xr_string((LPCSTR)F->pointer())); + FS.r_close(F); + return TRUE; } - }else{ - SECommand* CMD = GetEditorCommands()[COMMAND_RUN_MACRO]; VERIFY(CMD); - u32 num = p1; VERIFY(numsub_commands.size()); - SESubCommand* SUB=CMD->sub_commands[num]; - fn = xr_string(SUB->p0); - return ExecCommand(COMMAND_RUN_MACRO,fn,p2); } - return FALSE; + else + { + SECommand*CMD = GetEditorCommands()[COMMAND_RUN_MACRO]; + VERIFY(CMD); + u32 num = p1; + VERIFY(numsub_commands.size()); + SESubCommand*SUB = CMD->sub_commands[num]; + fn = xr_string(SUB->p0); + return ExecCommand(COMMAND_RUN_MACRO, fn, p2); + } + return FALSE; } -CCommandVar CommandAssignMacro(CCommandVar p1, CCommandVar p2) + +CCommandVar CommandAssignMacro(CCommandVar p1, CCommandVar p2) { - xr_string fn = p2.IsString()?xr_string(p2):xr_string(""); - if (p2.IsString()){ + xr_string fn = p2.IsString() ? xr_string(p2) : xr_string(""); + if (p2.IsString()) + { if (0==fn.find(FS.get_path(_import_)->m_Path)) - fn = xr_string(fn.c_str()+xr_strlen(FS.get_path(_import_)->m_Path)); - ECommands[COMMAND_RUN_MACRO]->sub_commands[p1]->p0 = fn; - return TRUE; - }else{ - if (EFS.GetOpenName(_import_,fn,false,NULL,2)) - return ExecCommand (COMMAND_ASSIGN_MACRO,p1,fn); + fn = xr_string(fn.c_str()+xr_strlen(FS.get_path(_import_)->m_Path)); + ECommands[COMMAND_RUN_MACRO]->sub_commands[p1]->p0 = fn; + return TRUE; + } + else + { + if (EFS.GetOpenName(_import_, fn, false, NULL, 2)) + return ExecCommand(COMMAND_ASSIGN_MACRO, p1, fn); } return FALSE; } void TUI::RegisterCommands() { - REGISTER_CMD_S (COMMAND_INITIALIZE, CommandInitialize); - REGISTER_CMD_S (COMMAND_DESTROY, CommandDestroy); - REGISTER_CMD_SE (COMMAND_EXIT, "Exit", CommandExit, true); - REGISTER_CMD_S (COMMAND_QUIT, CommandQuit); - REGISTER_CMD_SE (COMMAND_EDITOR_PREF, "Editor Preference", CommandEditorPrefs, false); - - - REGISTER_CMD_SE (COMMAND_SIMULATE, "Simulate", CommandSimulate, true); - REGISTER_CMD_SE (COMMAND_USE_SIMULATE_POSITIONS,"Use Simulate Positions",CommandUseSimulatePositions, true); - - REGISTER_SUB_CMD_SE (COMMAND_CHANGE_ACTION, "Change Action", CommandChangeAction,false); - APPEND_SUB_CMD ("Select", etaSelect, 0); - APPEND_SUB_CMD ("Add", etaAdd, 0); - APPEND_SUB_CMD ("Move", etaMove, 0); - APPEND_SUB_CMD ("Rotate", etaRotate, 0); - APPEND_SUB_CMD ("Scale", etaScale, 0); - REGISTER_SUB_CMD_END; - REGISTER_SUB_CMD_SE (COMMAND_CHANGE_AXIS, "Change Axis", CommandChangeAxis, false); - APPEND_SUB_CMD ("X", etAxisX, 0); - APPEND_SUB_CMD ("Y", etAxisY, 0); - APPEND_SUB_CMD ("Z", etAxisZ, 0); - APPEND_SUB_CMD ("ZX", etAxisZX, 0); - REGISTER_SUB_CMD_END; - REGISTER_CMD_S (COMMAND_SET_SETTINGS, CommandSetSettings); - REGISTER_CMD_S (COMMAND_SOUND_EDITOR, CommandSoundEditor); - REGISTER_CMD_S (COMMAND_SYNC_SOUNDS, CommandSyncSounds); - REGISTER_CMD_S (COMMAND_IMAGE_EDITOR, CommandImageEditor); REGISTER_CMD_S (COMMAND_MINIMAP_EDITOR, CommandMinimapEditor); - REGISTER_CMD_S (COMMAND_CHECK_TEXTURES, CommandCheckTextures); - REGISTER_CMD_S (COMMAND_REFRESH_TEXTURES, CommandRefreshTextures); - REGISTER_CMD_S (COMMAND_RELOAD_TEXTURES, CommandReloadTextures); - REGISTER_CMD_S (COMMAND_CHANGE_SNAP, CommandChangeSnap); - REGISTER_CMD_S (COMMAND_UNLOAD_TEXTURES, CommandUnloadTextures); - REGISTER_CMD_S (COMMAND_EVICT_OBJECTS, CommandEvictObjects); - REGISTER_CMD_S (COMMAND_EVICT_TEXTURES, CommandEvictTextures); - REGISTER_CMD_S (COMMAND_CHECK_MODIFIED, CommandCheckModified); - REGISTER_CMD_SE (COMMAND_SHOW_PROPERTIES, "Show Properties", CommandShowProperties, false); - REGISTER_CMD_S (COMMAND_UPDATE_PROPERTIES, CommandUpdateProperties); - REGISTER_CMD_S (COMMAND_REFRESH_PROPERTIES, CommandRefreshProperties); - REGISTER_SUB_CMD_SE (COMMAND_ZOOM_EXTENTS, "Zoom", CommandZoomExtents,false); - APPEND_SUB_CMD ("Extent", 0,0); - APPEND_SUB_CMD ("Selected", 1,0); - REGISTER_SUB_CMD_END; - REGISTER_CMD_SE (COMMAND_MOVE_CAMERA_TO, "Scene\\Move Camera To",CommandMoveCameraTo,false); - REGISTER_CMD_SE (COMMAND_TOGGLE_RENDER_WIRE, "Toggle Wireframe", CommandToggleRenderWire, false); - REGISTER_CMD_C (COMMAND_RENDER_FOCUS, this,TUI::CommandRenderFocus); - REGISTER_CMD_CE (COMMAND_BREAK_LAST_OPERATION, "Break Last Operation", this,TUI::CommandBreakLastOperation,false); - REGISTER_CMD_SE (COMMAND_TOGGLE_SAFE_RECT, "Toggle Safe Rect", CommandToggleSafeRect,false); - REGISTER_CMD_C (COMMAND_RENDER_RESIZE, this,TUI::CommandRenderResize); - REGISTER_CMD_SE (COMMAND_TOGGLE_GRID, "Toggle Grid", CommandToggleGrid,false); - REGISTER_CMD_S (COMMAND_UPDATE_GRID, CommandUpdateGrid); - REGISTER_CMD_S (COMMAND_GRID_NUMBER_OF_SLOTS, CommandGridNumberOfSlots); - REGISTER_SUB_CMD_SE (COMMAND_GRID_SLOT_SIZE, "Change Grid Size", CommandGridSlotSize,false); - APPEND_SUB_CMD ("Decrease", 0,0); - APPEND_SUB_CMD ("Increase", 1,0); - REGISTER_SUB_CMD_END; - REGISTER_CMD_S (COMMAND_CREATE_SOUND_LIB, CommandCreateSoundLib); - REGISTER_CMD_S (COMMAND_MUTE_SOUND, CommandMuteSound); - REGISTER_CMD_S (COMMAND_EDIT_COMMAND_LIST, CommandEditCommandList); - REGISTER_CMD_S (COMMAND_EXECUTE_COMMAND_LIST, CommandExecuteCommandList); - REGISTER_CMD_S (COMMAND_LOG_COMMANDS, CommandLogCommands); - REGISTER_SUB_CMD_SE (COMMAND_RUN_MACRO, "Run Macro", CommandRunMacro,false); - APPEND_SUB_CMD ("Slot #1", xr_string(""),0); - APPEND_SUB_CMD ("Slot #2", xr_string(""),0); - APPEND_SUB_CMD ("Slot #3", xr_string(""),0); - APPEND_SUB_CMD ("Slot #4", xr_string(""),0); - APPEND_SUB_CMD ("Slot #5", xr_string(""),0); - APPEND_SUB_CMD ("Slot #6", xr_string(""),0); - APPEND_SUB_CMD ("Slot #7", xr_string(""),0); - APPEND_SUB_CMD ("Slot #8", xr_string(""),0); - REGISTER_SUB_CMD_END; - REGISTER_CMD_S (COMMAND_ASSIGN_MACRO, CommandAssignMacro); -} + REGISTER_CMD_S (COMMAND_INITIALIZE, CommandInitialize); + REGISTER_CMD_S (COMMAND_DESTROY, CommandDestroy); + REGISTER_CMD_SE (COMMAND_EXIT, "Exit", CommandExit, true); + REGISTER_CMD_S (COMMAND_QUIT, CommandQuit); + REGISTER_CMD_SE (COMMAND_EDITOR_PREF, "Editor Preference", CommandEditorPrefs, false); + + + REGISTER_CMD_SE (COMMAND_SIMULATE, "Simulate", CommandSimulate, true); + REGISTER_CMD_SE (COMMAND_USE_SIMULATE_POSITIONS,"Use Simulate Positions",CommandUseSimulatePositions, true); + + REGISTER_SUB_CMD_SE (COMMAND_CHANGE_ACTION, "Change Action", CommandChangeAction,false); + APPEND_SUB_CMD ("Select", etaSelect, 0); + APPEND_SUB_CMD ("Add", etaAdd, 0); + APPEND_SUB_CMD ("Move", etaMove, 0); + APPEND_SUB_CMD ("Rotate", etaRotate, 0); + APPEND_SUB_CMD ("Scale", etaScale, 0); + REGISTER_SUB_CMD_END; + REGISTER_SUB_CMD_SE (COMMAND_CHANGE_AXIS, "Change Axis", CommandChangeAxis, false); + APPEND_SUB_CMD ("X", etAxisX, 0); + APPEND_SUB_CMD ("Y", etAxisY, 0); + APPEND_SUB_CMD ("Z", etAxisZ, 0); + APPEND_SUB_CMD ("ZX", etAxisZX, 0); + REGISTER_SUB_CMD_END; + REGISTER_CMD_S (COMMAND_SET_SETTINGS, CommandSetSettings); + REGISTER_CMD_S (COMMAND_SOUND_EDITOR, CommandSoundEditor); + REGISTER_CMD_S (COMMAND_SYNC_SOUNDS, CommandSyncSounds); + REGISTER_CMD_S (COMMAND_IMAGE_EDITOR, CommandImageEditor); + REGISTER_CMD_S (COMMAND_MINIMAP_EDITOR, CommandMinimapEditor); + REGISTER_CMD_S (COMMAND_CHECK_TEXTURES, CommandCheckTextures); + REGISTER_CMD_S (COMMAND_REFRESH_TEXTURES, CommandRefreshTextures); + REGISTER_CMD_S (COMMAND_RELOAD_TEXTURES, CommandReloadTextures); + REGISTER_CMD_S (COMMAND_CHANGE_SNAP, CommandChangeSnap); + REGISTER_CMD_S (COMMAND_UNLOAD_TEXTURES, CommandUnloadTextures); + REGISTER_CMD_S (COMMAND_EVICT_OBJECTS, CommandEvictObjects); + REGISTER_CMD_S (COMMAND_EVICT_TEXTURES, CommandEvictTextures); + REGISTER_CMD_S (COMMAND_CHECK_MODIFIED, CommandCheckModified); + REGISTER_CMD_SE (COMMAND_SHOW_PROPERTIES, "Show Properties", CommandShowProperties, false); + REGISTER_CMD_S (COMMAND_UPDATE_PROPERTIES, CommandUpdateProperties); + REGISTER_CMD_S (COMMAND_REFRESH_PROPERTIES, CommandRefreshProperties); + REGISTER_SUB_CMD_SE (COMMAND_ZOOM_EXTENTS, "Zoom", CommandZoomExtents,false); + APPEND_SUB_CMD ("Extent", 0,0); + APPEND_SUB_CMD ("Selected", 1,0); + REGISTER_SUB_CMD_END; + REGISTER_CMD_SE (COMMAND_MOVE_CAMERA_TO, "Scene\\Move Camera To",CommandMoveCameraTo,false); + REGISTER_CMD_SE (COMMAND_TOGGLE_RENDER_WIRE, "Toggle Wireframe", CommandToggleRenderWire, false); + REGISTER_CMD_C (COMMAND_RENDER_FOCUS, this,TUI::CommandRenderFocus); + REGISTER_CMD_CE (COMMAND_BREAK_LAST_OPERATION, "Break Last Operation", this,TUI::CommandBreakLastOperation,false); + REGISTER_CMD_SE (COMMAND_TOGGLE_SAFE_RECT, "Toggle Safe Rect", CommandToggleSafeRect,false); + REGISTER_CMD_C (COMMAND_RENDER_RESIZE, this,TUI::CommandRenderResize); + REGISTER_CMD_SE (COMMAND_TOGGLE_GRID, "Toggle Grid", CommandToggleGrid,false); + REGISTER_CMD_S (COMMAND_UPDATE_GRID, CommandUpdateGrid); + REGISTER_CMD_S (COMMAND_GRID_NUMBER_OF_SLOTS, CommandGridNumberOfSlots); + REGISTER_SUB_CMD_SE (COMMAND_GRID_SLOT_SIZE, "Change Grid Size", CommandGridSlotSize,false); + APPEND_SUB_CMD ("Decrease", 0,0); + APPEND_SUB_CMD ("Increase", 1,0); + REGISTER_SUB_CMD_END; + REGISTER_CMD_S (COMMAND_CREATE_SOUND_LIB, CommandCreateSoundLib); + REGISTER_CMD_S (COMMAND_MUTE_SOUND, CommandMuteSound); + REGISTER_CMD_S (COMMAND_EDIT_COMMAND_LIST, CommandEditCommandList); + REGISTER_CMD_S (COMMAND_EXECUTE_COMMAND_LIST, CommandExecuteCommandList); + REGISTER_CMD_S (COMMAND_LOG_COMMANDS, CommandLogCommands); + REGISTER_SUB_CMD_SE (COMMAND_RUN_MACRO, "Run Macro", CommandRunMacro,false); + APPEND_SUB_CMD ("Slot #1", xr_string(""),0); + APPEND_SUB_CMD ("Slot #2", xr_string(""),0); + APPEND_SUB_CMD ("Slot #3", xr_string(""),0); + APPEND_SUB_CMD ("Slot #4", xr_string(""),0); + APPEND_SUB_CMD ("Slot #5", xr_string(""),0); + APPEND_SUB_CMD ("Slot #6", xr_string(""),0); + APPEND_SUB_CMD ("Slot #7", xr_string(""),0); + APPEND_SUB_CMD ("Slot #8", xr_string(""),0); + REGISTER_SUB_CMD_END; + REGISTER_CMD_S (COMMAND_ASSIGN_MACRO, CommandAssignMacro); +} //--------------------------------------------------------------------------- bool TUI::ApplyShortCut(WORD Key, TShiftState Shift) { - VERIFY(m_bReady); + VERIFY(m_bReady); - if (ApplyGlobalShortCut(Key,Shift)) return true; + if (ApplyGlobalShortCut(Key, Shift)) + return true; - if (Key==VK_ESCAPE){ ExecCommand (COMMAND_CHANGE_ACTION, etaSelect); return true;} + if (Key==VK_ESCAPE) + { + ExecCommand(COMMAND_CHANGE_ACTION, etaSelect); + return true; + } - xr_shortcut SC; - SC.key = Key; - SC.ext.assign (u8((Shift.Contains(ssShift)?xr_shortcut::flShift:0)| - (Shift.Contains(ssCtrl) ?xr_shortcut::flCtrl:0)| - (Shift.Contains(ssAlt) ?xr_shortcut::flAlt:0))); - SESubCommand* SUB = FindCommandByShortcut(SC); + xr_shortcut SC; + SC.key = Key; + SC.ext.assign(u8((Shift.Contains(ssShift) ? xr_shortcut::flShift : 0)| + (Shift.Contains(ssCtrl) ? xr_shortcut::flCtrl : 0)| + (Shift.Contains(ssAlt) ? xr_shortcut::flAlt : 0))); + SESubCommand*SUB = FindCommandByShortcut(SC); - if (!SUB||SUB->parent->global_shortcut) return false; + if (!SUB||SUB->parent->global_shortcut) + return false; - return ExecCommand(SC); + return ExecCommand(SC); } + //--------------------------------------------------------------------------- bool TUI::ApplyGlobalShortCut(WORD Key, TShiftState Shift) { - VERIFY(m_bReady); + VERIFY(m_bReady); - if (Key==VK_OEM_3){ ExecCommand (COMMAND_RENDER_FOCUS); return true;} + if (Key==VK_OEM_3) + { + ExecCommand(COMMAND_RENDER_FOCUS); + return true; + } - xr_shortcut SC; - SC.key = Key; - SC.ext.assign (u8((Shift.Contains(ssShift)?xr_shortcut::flShift:0)| - (Shift.Contains(ssCtrl) ?xr_shortcut::flCtrl:0)| - (Shift.Contains(ssAlt) ?xr_shortcut::flAlt:0))); - SESubCommand* SUB = FindCommandByShortcut(SC); + xr_shortcut SC; + SC.key = Key; + SC.ext.assign(u8((Shift.Contains(ssShift) ? xr_shortcut::flShift : 0)| + (Shift.Contains(ssCtrl) ? xr_shortcut::flCtrl : 0)| + (Shift.Contains(ssAlt) ? xr_shortcut::flAlt : 0))); + SESubCommand*SUB = FindCommandByShortcut(SC); - if (!SUB||!SUB->parent->global_shortcut) return false; + if (!SUB||!SUB->parent->global_shortcut) + return false; - return ExecCommand(SUB->parent->idx,SUB->p0,SUB->p1); + return ExecCommand(SUB->parent->idx, SUB->p0, SUB->p1); } + //--------------------------------------------------------------------------- diff --git a/src/editors/ECore/Editor/UI_MainCommand.h b/src/editors/ECore/Editor/UI_MainCommand.h index 520d7817c13..0b9e3e2e036 100644 --- a/src/editors/ECore/Editor/UI_MainCommand.h +++ b/src/editors/ECore/Editor/UI_MainCommand.h @@ -1,42 +1,43 @@ #ifndef UI_MainCommandH #define UI_MainCommandH -enum{ - COMMAND_INITIALIZE=0, // p1 - D3DWindow, p2 - TPanel - COMMAND_DESTROY, - COMMAND_QUIT, - COMMAND_EDITOR_PREF, - COMMAND_CHANGE_ACTION, +enum +{ + COMMAND_INITIALIZE=0, // p1 - D3DWindow, p2 - TPanel + COMMAND_DESTROY, + COMMAND_QUIT, + COMMAND_EDITOR_PREF, + COMMAND_CHANGE_ACTION, COMMAND_IMAGE_EDITOR, COMMAND_MINIMAP_EDITOR, - COMMAND_CHECK_TEXTURES, - COMMAND_REFRESH_TEXTURES, - COMMAND_RELOAD_TEXTURES, - COMMAND_CHANGE_AXIS, - COMMAND_CHANGE_SNAP, + COMMAND_CHECK_TEXTURES, + COMMAND_REFRESH_TEXTURES, + COMMAND_RELOAD_TEXTURES, + COMMAND_CHANGE_AXIS, + COMMAND_CHANGE_SNAP, COMMAND_SET_SETTINGS, COMMAND_UNLOAD_TEXTURES, COMMAND_EVICT_OBJECTS, COMMAND_EVICT_TEXTURES, COMMAND_CHECK_MODIFIED, - COMMAND_EXIT, - COMMAND_SHOW_PROPERTIES, - COMMAND_UPDATE_PROPERTIES, // p1 - forced update if needed + COMMAND_EXIT, + COMMAND_SHOW_PROPERTIES, + COMMAND_UPDATE_PROPERTIES, // p1 - forced update if needed COMMAND_REFRESH_PROPERTIES, COMMAND_MOVE_CAMERA_TO, - COMMAND_ZOOM_EXTENTS, + COMMAND_ZOOM_EXTENTS, COMMAND_RENDER_FOCUS, - COMMAND_RENDER_RESIZE, + COMMAND_RENDER_RESIZE, COMMAND_TOGGLE_RENDER_WIRE, COMMAND_UPDATE_CAPTION, - COMMAND_BREAK_LAST_OPERATION, - COMMAND_UPDATE_TOOLBAR, + COMMAND_BREAK_LAST_OPERATION, + COMMAND_UPDATE_TOOLBAR, COMMAND_TOGGLE_SAFE_RECT, COMMAND_TOGGLE_GRID, - COMMAND_UPDATE_GRID, + COMMAND_UPDATE_GRID, COMMAND_GRID_NUMBER_OF_SLOTS, COMMAND_GRID_SLOT_SIZE, - + COMMAND_REFRESH_UI_BAR, COMMAND_RESTORE_UI_BAR, COMMAND_SAVE_UI_BAR, @@ -50,93 +51,131 @@ enum{ COMMAND_SAVE_BACKUP, COMMAND_CREATE_SOUND_LIB, - COMMAND_TOGGLE_AIMAP_VISIBILITY, - + COMMAND_TOGGLE_AIMAP_VISIBILITY, + // sound - COMMAND_SOUND_EDITOR, - COMMAND_SYNC_SOUNDS, - - COMMAND_UNDO, - COMMAND_REDO, - + COMMAND_SOUND_EDITOR, + COMMAND_SYNC_SOUNDS, + + COMMAND_UNDO, + COMMAND_REDO, + COMMAND_EDIT_COMMAND_LIST, COMMAND_EXECUTE_COMMAND_LIST, COMMAND_LOG_COMMANDS, - COMMAND_RUN_MACRO, // p1 - file name - COMMAND_ASSIGN_MACRO, // p1 - slot, p2 - file_name + COMMAND_RUN_MACRO, // p1 - file name + COMMAND_ASSIGN_MACRO, // p1 - slot, p2 - file_name COMMAND_SIMULATE, COMMAND_USE_SIMULATE_POSITIONS, COMMAND_MAIN_LAST }; + //------------------------------------------------------------------------------ -class CCommandVar{ - enum EType{ +class CCommandVar +{ + enum EType + { tpStr, tpInt }; - u32 i; - xr_string s; - EType type; + + u32 i; + xr_string s; + EType type; public: - CCommandVar ():i(0),type(tpInt) {} - CCommandVar (xr_string str) :type(tpStr){s=str;} - CCommandVar (u32 val) :type(tpInt){i=val;} - IC operator u32 () {VERIFY(type==tpInt);return i;} - IC operator xr_string () {VERIFY(type==tpStr);return s;} - IC bool IsString () {return type==tpStr;} - IC bool IsInteger () {return type==tpInt;} -// IC operator LPCSTR () {VERIFY(type==tpStr);return s.c_str();} + CCommandVar(): i(0), type(tpInt) {} + + CCommandVar(xr_string str) : type(tpStr) + { + s = str; + } + + CCommandVar(u32 val) : type(tpInt) + { + i = val; + } + + IC operator u32() + { + VERIFY(type==tpInt); + return i; + } + + IC operator xr_string() + { + VERIFY(type==tpStr); + return s; + } + + IC + + bool IsString() + { + return type==tpStr; + } + + IC + + bool IsInteger() + { + return type==tpInt; + } + + // IC operator LPCSTR () {VERIFY(type==tpStr);return s.c_str();} }; -typedef fastdelegate::FastDelegate2 TECommandEvent; +typedef fastdelegate::FastDelegate2 TECommandEvent; class SECommand; struct ECORE_API SESubCommand{ - SECommand* parent; - xr_string desc; - CCommandVar p0; - CCommandVar p1; - xr_shortcut shortcut; -public: - SESubCommand (LPCSTR d, SECommand* p, CCommandVar _p0, CCommandVar _p1){desc=d;parent=p;p0=_p0;p1=_p1;} + SECommand*parent; + xr_string desc; + CCommandVar p0; + CCommandVar p1; + xr_shortcut shortcut; + public: + SESubCommand(LPCSTR d, SECommand*p, CCommandVar _p0, CCommandVar _p1){desc = d;parent = p;p0 = _p0;p1 = _p1;} }; -DEFINE_VECTOR (SESubCommand*,ESubCommandVec,ESubCommandVecIt); +DEFINE_VECTOR(SESubCommand *, ESubCommandVec, ESubCommandVecIt); struct ECORE_API SECommand{ - bool editable; - LPSTR name; - LPSTR desc; - ESubCommandVec sub_commands; - TECommandEvent command; - u32 idx; - bool global_shortcut; -public: - SECommand (LPCSTR n, LPCSTR d, bool edit, bool multi, TECommandEvent cmd, u32 i, bool _gs):editable(edit),command(cmd),idx(i),global_shortcut(_gs) - { - name = xr_strdup(n); - desc = xr_strdup(d); - if (!multi) AppendSubCommand("",u32(0),u32(0)); - } - ~SECommand (){xr_free(name);xr_free(desc); for (ESubCommandVecIt it=sub_commands.begin(); it!=sub_commands.end(); it++) xr_delete(*it);} - IC LPCSTR Name (){return name&&name[0]?name:"";} - IC LPCSTR Desc (){return desc&&desc[0]?desc:"";} - void AppendSubCommand(LPCSTR desc, CCommandVar p0, CCommandVar p1){sub_commands.push_back(xr_new(desc,this,p0,p1));} + bool editable; + LPSTR name; + LPSTR desc; + ESubCommandVec sub_commands; + TECommandEvent command; + u32 idx; + bool global_shortcut; + public: + SECommand(LPCSTR n, LPCSTR d, bool edit, bool multi, TECommandEvent cmd, u32 i, bool _gs):editable(edit),command(cmd),idx(i),global_shortcut(_gs) + { + name = xr_strdup(n); + desc = xr_strdup(d); + if (!multi) AppendSubCommand("", u32(0), u32(0)); + } + ~SECommand(){xr_free(name);xr_free(desc);for (ESubCommandVecIt it = sub_commands.begin(); it!=sub_commands.end(); it++) xr_delete(*it);} + IC LPCSTR Name(){return name&&name[0] ? name : "";} + IC LPCSTR Desc(){return desc&&desc[0] ? desc : "";} + void AppendSubCommand(LPCSTR desc, CCommandVar p0, CCommandVar p1){sub_commands.push_back(xr_new(desc,this,p0,p1));} }; -DEFINE_VECTOR(SECommand*,ECommandVec,ECommandVecIt); - -ECORE_API CCommandVar ExecCommand (u32 cmd, CCommandVar p1=u32(0), CCommandVar p2=u32(0)); -ECORE_API CCommandVar ExecCommand (const xr_shortcut& val); -ECORE_API void RegisterCommand (u32 cmd, SECommand* cmd_impl); -ECORE_API void RegisterSubCommand (SECommand* cmd_impl, LPCSTR desc, CCommandVar p0, CCommandVar p1); -ECORE_API void EnableReceiveCommands (); -ECORE_API ECommandVec& GetEditorCommands (); -ECORE_API SESubCommand* FindCommandByShortcut (const xr_shortcut& val); -ECORE_API BOOL LoadShortcuts (CInifile* ini); -ECORE_API BOOL SaveShortcuts (CInifile* ini); -ECORE_API BOOL AllowLogCommands (); +DEFINE_VECTOR(SECommand *, ECommandVec, ECommandVecIt); + +ECORE_API CCommandVar ExecCommand(u32 cmd, CCommandVar p1 = u32(0), CCommandVar p2 = u32(0)); +ECORE_API CCommandVar ExecCommand(const xr_shortcut &val); +ECORE_API +void RegisterCommand(u32 cmd, SECommand *cmd_impl); +ECORE_API +void RegisterSubCommand(SECommand *cmd_impl, LPCSTR desc, CCommandVar p0, CCommandVar p1); +ECORE_API +void EnableReceiveCommands(); +ECORE_API ECommandVec&GetEditorCommands(); +ECORE_API SESubCommand*FindCommandByShortcut(const xr_shortcut &val); +ECORE_API BOOL LoadShortcuts(CInifile*ini); +ECORE_API BOOL SaveShortcuts(CInifile*ini); +ECORE_API BOOL AllowLogCommands(); #define BIND_CMD_EVENT_S(a) fastdelegate::bind(a) #define BIND_CMD_EVENT_C(a,b) fastdelegate::bind(a,&b) @@ -153,4 +192,3 @@ ECORE_API BOOL AllowLogCommands (); #endif //UI_MainCommandH - diff --git a/src/editors/ECore/Editor/UI_MainMail.cpp b/src/editors/ECore/Editor/UI_MainMail.cpp index 48a34991b5e..69a9e8808e8 100644 --- a/src/editors/ECore/Editor/UI_MainMail.cpp +++ b/src/editors/ECore/Editor/UI_MainMail.cpp @@ -3,111 +3,134 @@ #pragma hdrstop #include "ui_main.h" + //--------------------------------------------------------------------------- bool TUI::CreateMailslot() { - AnsiString slot_name = AnsiString("\\\\.\\mailslot\\")+AnsiString(UI->EditorName()); + AnsiString slot_name = AnsiString("\\\\.\\mailslot\\")+AnsiString(UI->EditorName()); hMailSlot = ::CreateMailslot(slot_name.c_str(), - 0, // no maximum message size - MAILSLOT_WAIT_FOREVER, // no time-out for operations + 0, // no maximum message size + MAILSLOT_WAIT_FOREVER, // no time-out for operations (LPSECURITY_ATTRIBUTES) NULL); // no security attributes - return (hMailSlot != INVALID_HANDLE_VALUE); + return (hMailSlot!=INVALID_HANDLE_VALUE); } + //--------------------------------------------------------------------------- void TUI::CheckMailslot() { DWORD cbMessage, cMessage, cbRead; - BOOL fResult; - LPSTR lpszBuffer; + BOOL fResult; + LPSTR lpszBuffer; cbMessage = cMessage = cbRead = 0; - fResult = GetMailslotInfo(hMailSlot, // mailslot handle - (LPDWORD) NULL, // no maximum message size - &cbMessage, // size of next message - &cMessage, // number of messages - (LPDWORD) NULL); // no read time-out - R_ASSERT2(fResult,"Can't get mailslot info"); - if (cbMessage == MAILSLOT_NO_MESSAGE) return; - while (cMessage != 0) // retrieve all messages - { - // Allocate memory for the message. - lpszBuffer = (LPSTR) GlobalAlloc(GPTR, cbMessage); - lpszBuffer[0] = '\0'; - fResult = ReadFile(hMailSlot, lpszBuffer, cbMessage, &cbRead, (LPOVERLAPPED) NULL); - if (!fResult) { - GlobalFree((HGLOBAL) lpszBuffer); - throw Exception("Can't ReadFile"); - } - OnReceiveMail(lpszBuffer); - GlobalFree((HGLOBAL) lpszBuffer); - fResult = GetMailslotInfo(hMailSlot, // mailslot handle - (LPDWORD) NULL, // no maximum message size - &cbMessage, // size of next message - &cMessage, // number of messages - (LPDWORD) NULL); // no read time-out - R_ASSERT2(fResult,"Can't get mailslot info"); + fResult = GetMailslotInfo(hMailSlot, // mailslot handle + (LPDWORD) NULL, // no maximum message size + &cbMessage, // size of next message + &cMessage, // number of messages + (LPDWORD) NULL); // no read time-out + R_ASSERT2(fResult, "Can't get mailslot info"); + if (cbMessage==MAILSLOT_NO_MESSAGE) + return; + while (cMessage!=0) // retrieve all messages + { + // Allocate memory for the message. + lpszBuffer = (LPSTR) GlobalAlloc(GPTR, cbMessage); + lpszBuffer[0] = '\0'; + fResult = ReadFile(hMailSlot, lpszBuffer, cbMessage, &cbRead, (LPOVERLAPPED) NULL); + if (!fResult) + { + GlobalFree((HGLOBAL) lpszBuffer); + throw Exception("Can't ReadFile"); + } + OnReceiveMail(lpszBuffer); + GlobalFree((HGLOBAL) lpszBuffer); + fResult = GetMailslotInfo(hMailSlot, // mailslot handle + (LPDWORD) NULL, // no maximum message size + &cbMessage, // size of next message + &cMessage, // number of messages + (LPDWORD) NULL); // no read time-out + R_ASSERT2(fResult, "Can't get mailslot info"); } } + //--------------------------------------------------------------------------- void TUI::OnReceiveMail(LPCSTR msg) { - int cnt = _GetItemCount(msg,' '); - if (cnt){ - AnsiString M=AnsiString(msg).LowerCase(); + int cnt = _GetItemCount(msg, ' '); + if (cnt) + { + AnsiString M = AnsiString(msg).LowerCase(); AnsiString p[2]; - _GetItem(msg,0,p[0],' ',"",false); - if (cnt>1) _GetItems(msg,1,cnt,p[1],' '); - if (p[0]=="exit"){ - ELog.DlgMsg(mtInformation,"'%s EDITOR': Critical update!",AnsiString(UI->EditorName()).UpperCase().c_str()); - while (1){ - if (ExecCommand(COMMAND_EXIT)){ - ExecCommand(COMMAND_QUIT); + _GetItem(msg, 0, p[0], ' ', "", false); + if (cnt>1) + _GetItems(msg, 1, cnt, p[1], ' '); + if (p[0]=="exit") + { + ELog.DlgMsg(mtInformation, "'%s EDITOR': Critical update!", AnsiString(UI->EditorName()).UpperCase().c_str()); + while (1) + { + if (ExecCommand(COMMAND_EXIT)) + { + ExecCommand(COMMAND_QUIT); break; } } - }else if (p[0]=="quit"){ - ELog.Msg(mtInformation,"'%s EDITOR': Super critical update!",AnsiString(UI->EditorName()).UpperCase().c_str()); - ExecCommand(COMMAND_SAVE_BACKUP); - ExecCommand(COMMAND_QUIT); - }else if (p[0]=="info"){ - if (cnt>1) ELog.DlgMsg(mtInformation,"'%s EDITOR': %s",AnsiString(UI->EditorName()).UpperCase().c_str(),p[1].c_str()); - }else if (p[0]=="error"){ - if (cnt>1) ELog.DlgMsg(mtError,"'%s EDITOR': %s",AnsiString(UI->EditorName()).UpperCase().c_str(),p[1].c_str()); + } + else if (p[0]=="quit") + { + ELog.Msg(mtInformation, "'%s EDITOR': Super critical update!", AnsiString(UI->EditorName()).UpperCase().c_str()); + ExecCommand(COMMAND_SAVE_BACKUP); + ExecCommand(COMMAND_QUIT); + } + else if (p[0]=="info") + { + if (cnt>1) + ELog.DlgMsg(mtInformation, "'%s EDITOR': %s", AnsiString(UI->EditorName()).UpperCase().c_str(), p[1].c_str()); + } + else if (p[0]=="error") + { + if (cnt>1) + ELog.DlgMsg(mtError, "'%s EDITOR': %s", AnsiString(UI->EditorName()).UpperCase().c_str(), p[1].c_str()); } } } + //--------------------------------------------------------------------------- void TUI::SendMail(LPCSTR name, LPCSTR dest, LPCSTR msg) { - HANDLE hFile; - DWORD cbWritten; - BOOL fResult; - char cName[256]; + HANDLE hFile; + DWORD cbWritten; + BOOL fResult; + char cName[256]; - sprintf(cName,"\\\\%s\\mailslot\\%s",name,dest); - hFile = CreateFile( - cName, - GENERIC_WRITE, - FILE_SHARE_READ, // required to write to a mailslot - (LPSECURITY_ATTRIBUTES) NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - (HANDLE) NULL); - if (hFile == INVALID_HANDLE_VALUE) return; - fResult = WriteFile( - hFile, - msg, - (u32) lstrlen(msg) + 1, - &cbWritten, - (LPOVERLAPPED) NULL); - if (!fResult) return; - fResult = CloseHandle(hFile); - if (!fResult) return; + sprintf(cName, "\\\\%s\\mailslot\\%s", name, dest); + hFile = CreateFile( + cName, + GENERIC_WRITE, + FILE_SHARE_READ, // required to write to a mailslot + (LPSECURITY_ATTRIBUTES) NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + (HANDLE) NULL); + if (hFile==INVALID_HANDLE_VALUE) + return; + fResult = WriteFile( + hFile, + msg, + (u32) lstrlen(msg)+1, + &cbWritten, + (LPOVERLAPPED) NULL); + if (!fResult) + return; + fResult = CloseHandle(hFile); + if (!fResult) + return; } + //--------------------------------------------------------------------------- diff --git a/src/editors/ECore/Editor/UI_ToolsCustom.cpp b/src/editors/ECore/Editor/UI_ToolsCustom.cpp index 83b5119f499..17973cffc11 100644 --- a/src/editors/ECore/Editor/UI_ToolsCustom.cpp +++ b/src/editors/ECore/Editor/UI_ToolsCustom.cpp @@ -8,106 +8,108 @@ #include "EditMesh.h" #include "ChoseForm.h" #include "ui_main.h" -#include "PropertiesList.h" -#include "motion.h" -#include "bone.h" -#include "library.h" -#include "fmesh.h" -#include "folderlib.h" -#include "d3dutils.h" +#include "PropertiesList.h" +#include "xrCore/Animation/Motion.hpp" +#include "xrCore/Animation/Bone.hpp" +#include "Library.h" +#include "xrCore/FMesh.hpp" +#include "editors/xrEProps/FolderLib.h" +#include "D3DUtils.h" //------------------------------------------------------------------------------ -CToolCustom* Tools=0; +CToolCustom *Tools = 0; //------------------------------------------------------------------------------ #define CHECK_SNAP(R,A,C){ R+=A; if(fabsf(R)>=C){ A=snapto(R,C); R=0; }else{A=0;}} CToolCustom::CToolCustom() { - m_bReady = false; - m_Action = etaSelect; - m_Settings.assign (etfNormalAlign|etfGSnap|etfOSnap|etfMTSnap|etfVSnap|etfASnap|etfMSnap); - m_Axis = etAxisZX; - fFogness = 0.9f; - dwFogColor = 0xffffffff; - m_pAxisMoveObject = NULL; - m_axis_xform = Fidentity; + m_bReady = false; + m_Action = etaSelect; + m_Settings.assign(etfNormalAlign|etfGSnap|etfOSnap|etfMTSnap|etfVSnap|etfASnap|etfMSnap); + m_Axis = etAxisZX; + fFogness = 0.9f; + dwFogColor = 0xffffffff; + m_pAxisMoveObject = NULL; + m_axis_xform = Fidentity; } + //--------------------------------------------------------------------------- -CToolCustom::~CToolCustom() -{ -} +CToolCustom::~CToolCustom() {} + //--------------------------------------------------------------------------- bool CToolCustom::OnCreate() { - m_bReady = true; + m_bReady = true; - SetAction (etaSelect); + SetAction(etaSelect); return true; } void CToolCustom::OnDestroy() { - Lib.RemoveEditObject (m_pAxisMoveObject); - VERIFY (m_bReady); - m_bReady = false; + Lib.RemoveEditObject(m_pAxisMoveObject); + VERIFY(m_bReady); + m_bReady = false; } + //--------------------------------------------------------------------------- void CToolCustom::SetAction(ETAction action) { - switch(action) + switch (action) { - case etaSelect: - m_bHiddenMode = false; - break; - case etaAdd: - case etaMove: - case etaRotate: - case etaScale: - m_bHiddenMode = true; - break; + case etaSelect: + m_bHiddenMode = false; + break; + case etaAdd: + case etaMove: + case etaRotate: + case etaScale: + m_bHiddenMode = true; + break; } m_Action = action; - switch(m_Action) + switch (m_Action) { - case etaSelect: - UI->GetD3DWindow()->Cursor = crCross; - break; - case etaAdd: - UI->GetD3DWindow()->Cursor = crArrow; - break; - case etaMove: - if(!EPrefs->tools_show_move_axis) - UI->GetD3DWindow()->Cursor = crSizeAll; - else - UI->GetD3DWindow()->Cursor = crHandPoint; - - break; - case etaRotate: - UI->GetD3DWindow()->Cursor = crSizeWE; - break; - case etaScale: - UI->GetD3DWindow()->Cursor = crVSplit; - break; - default: - UI->GetD3DWindow()->Cursor = crHelp; + case etaSelect: + UI->GetD3DWindow()->Cursor = crCross; + break; + case etaAdd: + UI->GetD3DWindow()->Cursor = crArrow; + break; + case etaMove: + if (!EPrefs->tools_show_move_axis) + UI->GetD3DWindow()->Cursor = crSizeAll; + else + UI->GetD3DWindow()->Cursor = crHandPoint; + + break; + case etaRotate: + UI->GetD3DWindow()->Cursor = crSizeWE; + break; + case etaScale: + UI->GetD3DWindow()->Cursor = crVSplit; + break; + default: + UI->GetD3DWindow()->Cursor = crHelp; } - if(m_Action==etaMove) + if (m_Action==etaMove) { - if(!m_pAxisMoveObject && EPrefs->tools_show_move_axis) + if (!m_pAxisMoveObject&&EPrefs->tools_show_move_axis) { m_pAxisMoveObject = Lib.CreateEditObject("editor\\axis"); m_Axis = etAxisUndefined; - } - }else + } + } + else { - if(m_pAxisMoveObject) - Lib.RemoveEditObject (m_pAxisMoveObject); - } + if (m_pAxisMoveObject) + Lib.RemoveEditObject(m_pAxisMoveObject); + } UI->RedrawScene(); ExecCommand(COMMAND_REFRESH_UI_BAR); } @@ -115,14 +117,14 @@ void CToolCustom::SetAction(ETAction action) void CToolCustom::SetAxis(ETAxis axis) { - m_Axis=axis; + m_Axis = axis; UI->RedrawScene(); ExecCommand(COMMAND_REFRESH_UI_BAR); } void CToolCustom::SetSettings(u32 mask, BOOL val) { - m_Settings.set(mask,val); + m_Settings.set(mask, val); UI->RedrawScene(); ExecCommand(COMMAND_REFRESH_UI_BAR); } @@ -130,238 +132,263 @@ void CToolCustom::SetSettings(u32 mask, BOOL val) bool __fastcall CToolCustom::MouseStart(TShiftState Shift) { - switch(m_Action) + switch (m_Action) { - case etaSelect: break; - case etaAdd: break; - case etaMove: - if (etAxisY==m_Axis){ - m_MoveXVector.set(0,0,0); - m_MoveYVector.set(0,1,0); - }else{ - m_MoveXVector.set( EDevice.m_Camera.GetRight() ); - m_MoveXVector.y = 0; - m_MoveYVector.set( EDevice.m_Camera.GetDirection() ); - m_MoveYVector.y = 0; - m_MoveXVector.normalize_safe(); - m_MoveYVector.normalize_safe(); - } - m_MoveReminder.set(0,0,0); - m_MovedAmount.set(0,0,0); - break; - case etaRotate: - m_RotateCenter.set(0,0,0); - m_RotateVector.set(0,0,0); - if (etAxisX==m_Axis) m_RotateVector.set(1,0,0); - else if (etAxisY==m_Axis) m_RotateVector.set(0,1,0); - else if (etAxisZ==m_Axis) m_RotateVector.set(0,0,1); - m_fRotateSnapValue = 0; - m_RotateAmount = 0; - break; - case etaScale: - m_ScaleAmount.set (0,0,0); - break; + case etaSelect: break; + case etaAdd: break; + case etaMove: + if (etAxisY==m_Axis) + { + m_MoveXVector.set(0, 0, 0); + m_MoveYVector.set(0, 1, 0); + } + else + { + m_MoveXVector.set(EDevice.m_Camera.GetRight()); + m_MoveXVector.y = 0; + m_MoveYVector.set(EDevice.m_Camera.GetDirection()); + m_MoveYVector.y = 0; + m_MoveXVector.normalize_safe(); + m_MoveYVector.normalize_safe(); + } + m_MoveReminder.set(0, 0, 0); + m_MovedAmount.set(0, 0, 0); + break; + case etaRotate: + m_RotateCenter.set(0, 0, 0); + m_RotateVector.set(0, 0, 0); + if (etAxisX==m_Axis) + m_RotateVector.set(1, 0, 0); + else if (etAxisY==m_Axis) + m_RotateVector.set(0, 1, 0); + else if (etAxisZ==m_Axis) + m_RotateVector.set(0, 0, 1); + m_fRotateSnapValue = 0; + m_RotateAmount = 0; + break; + case etaScale: + m_ScaleAmount.set(0, 0, 0); + break; } - if(m_Action==etaMove && m_pAxisMoveObject) + if (m_Action==etaMove&&m_pAxisMoveObject) { - Fmatrix inv_parent; - inv_parent.invert (m_axis_xform); - Fvector start_point, start_dir; - float dist; - SRayPickInfo pinfo; - - start_point = UI->m_CurrentRStart; - start_dir = UI->m_CurrentRDir; - dist = 10000; - m_pAxisMoveObject->RayPick(dist, start_point, start_dir,inv_parent,&pinfo); - if(pinfo.e_mesh) + Fmatrix inv_parent; + inv_parent.invert(m_axis_xform); + Fvector start_point, start_dir; + float dist; + SRayPickInfo pinfo; + + start_point = UI->m_CurrentRStart; + start_dir = UI->m_CurrentRDir; + dist = 10000; + m_pAxisMoveObject->RayPick(dist, start_point, start_dir, inv_parent, &pinfo); + if (pinfo.e_mesh) { - LPCSTR mn = pinfo.e_mesh->Name().c_str(); - if(0==stricmp(mn,"axis_x")) - SetAxis(etAxisX); - else - if(0==stricmp(mn,"axis_y")) - SetAxis(etAxisY); - else - if(0==stricmp(mn,"axis_z")) - SetAxis(etAxisZ); + LPCSTR mn = pinfo.e_mesh->Name().c_str(); + if (0==stricmp(mn, "axis_x")) + SetAxis(etAxisX); + else if (0==stricmp(mn, "axis_y")) + SetAxis(etAxisY); + else if (0==stricmp(mn, "axis_z")) + SetAxis(etAxisZ); + else if (0==stricmp(mn, "center")) + SetAxis(etAxisZX); else - if(0==stricmp(mn,"center")) - SetAxis(etAxisZX); - else - R_ASSERT2(0, "fix axis name"); + R_ASSERT2(0, "fix axis name"); }; } - - return m_bHiddenMode; + + return m_bHiddenMode; } bool __fastcall CToolCustom::MouseEnd(TShiftState Shift) { - switch(m_Action){ - case etaSelect: break; - case etaAdd: break; - case etaMove: - if(EPrefs->tools_show_move_axis) - m_Axis = etAxisUndefined; - break; - case etaRotate: break; - case etaScale: break; + switch (m_Action) + { + case etaSelect: break; + case etaAdd: break; + case etaMove: + if (EPrefs->tools_show_move_axis) + m_Axis = etAxisUndefined; + break; + case etaRotate: break; + case etaScale: break; } - return true; + return true; } void __fastcall CToolCustom::MouseMove(TShiftState Shift) { - switch(m_Action){ - case etaSelect: break; - case etaAdd: break; - case etaMove: - { - m_MovedAmount.mul( m_MoveXVector, UI->m_MouseSM * UI->m_DeltaCpH.x ); - m_MovedAmount.mad( m_MoveYVector, -UI->m_MouseSM * UI->m_DeltaCpH.y ); - - if( m_Settings.is(etfMSnap) ){ - CHECK_SNAP(m_MoveReminder.x,m_MovedAmount.x,m_MoveSnap); - CHECK_SNAP(m_MoveReminder.y,m_MovedAmount.y,m_MoveSnap); - CHECK_SNAP(m_MoveReminder.z,m_MovedAmount.z,m_MoveSnap); + switch (m_Action) + { + case etaSelect: break; + case etaAdd: break; + case etaMove: + { + m_MovedAmount.mul(m_MoveXVector, UI->m_MouseSM*UI->m_DeltaCpH.x); + m_MovedAmount.mad(m_MoveYVector, -UI->m_MouseSM*UI->m_DeltaCpH.y); + + if (m_Settings.is(etfMSnap)) + { + CHECK_SNAP(m_MoveReminder.x,m_MovedAmount.x,m_MoveSnap); + CHECK_SNAP(m_MoveReminder.y,m_MovedAmount.y,m_MoveSnap); + CHECK_SNAP(m_MoveReminder.z,m_MovedAmount.z,m_MoveSnap); + } + + if (!(etAxisX==m_Axis)&&!(etAxisZX==m_Axis)) + m_MovedAmount.x = 0.f; + if (!(etAxisZ==m_Axis)&&!(etAxisZX==m_Axis)) + m_MovedAmount.z = 0.f; + if (!(etAxisY==m_Axis)) + m_MovedAmount.y = 0.f; + } + break; + case etaRotate: + { + m_RotateAmount = -UI->m_DeltaCpH.x*UI->m_MouseSR; + if (m_Settings.is(etfASnap)) + CHECK_SNAP(m_fRotateSnapValue,m_RotateAmount,m_RotateSnapAngle); } + break; + case etaScale: + { + float dy = UI->m_DeltaCpH.x*UI->m_MouseSS; + if (dy>1.f) + dy = 1.f; else if (dy<-1.f) + dy = -1.f; + + m_ScaleAmount.set(dy, dy, dy); - if (!(etAxisX==m_Axis)&&!(etAxisZX==m_Axis)) m_MovedAmount.x = 0.f; - if (!(etAxisZ==m_Axis)&&!(etAxisZX==m_Axis)) m_MovedAmount.z = 0.f; - if (!(etAxisY==m_Axis)) m_MovedAmount.y = 0.f; - - }break; - case etaRotate:{ - m_RotateAmount = -UI->m_DeltaCpH.x * UI->m_MouseSR; - if( m_Settings.is(etfASnap) ) CHECK_SNAP(m_fRotateSnapValue,m_RotateAmount,m_RotateSnapAngle); - }break; - case etaScale:{ - float dy = UI->m_DeltaCpH.x * UI->m_MouseSS; - if (dy>1.f) dy=1.f; else if (dy<-1.f) dy=-1.f; - - m_ScaleAmount.set( dy, dy, dy ); - - if (m_Settings.is(etfNUScale)){ - if (!(etAxisX==m_Axis)&&!(etAxisZX==m_Axis)) m_ScaleAmount.x = 0.f; - if (!(etAxisZ==m_Axis)&&!(etAxisZX==m_Axis)) m_ScaleAmount.z = 0.f; - if (!(etAxisY==m_Axis)) m_ScaleAmount.y = 0.f; + if (m_Settings.is(etfNUScale)) + { + if (!(etAxisX==m_Axis)&&!(etAxisZX==m_Axis)) + m_ScaleAmount.x = 0.f; + if (!(etAxisZ==m_Axis)&&!(etAxisZX==m_Axis)) + m_ScaleAmount.z = 0.f; + if (!(etAxisY==m_Axis)) + m_ScaleAmount.y = 0.f; + } } - }break; + break; } } -void CToolCustom::GetCurrentFog(u32& fog_color, float& s_fog, float& e_fog) +void CToolCustom::GetCurrentFog(u32 &fog_color, float &s_fog, float &e_fog) { - s_fog = psDeviceFlags.is(rsFog)?(1.0f - fFogness)* 0.85f * UI->ZFar():0.99f*UI->ZFar(); - e_fog = psDeviceFlags.is(rsFog)?0.91f * UI->ZFar():UI->ZFar(); - fog_color = dwFogColor; + s_fog = psDeviceFlags.is(rsFog) ? (1.0f-fFogness)*0.85f*UI->ZFar() : 0.99f*UI->ZFar(); + e_fog = psDeviceFlags.is(rsFog) ? 0.91f*UI->ZFar() : UI->ZFar(); + fog_color = dwFogColor; } -void CToolCustom::RenderEnvironment() -{ -} +void CToolCustom::RenderEnvironment() {} void CToolCustom::Clear() { - ClearDebugDraw (); + ClearDebugDraw(); } void CToolCustom::Render() { - // render errors - EDevice.SetShader (EDevice.m_SelectionShader); - RCache.set_xform_world (Fidentity); - EDevice.RenderNearer (0.0003f); - EDevice.SetRS (D3DRS_CULLMODE,D3DCULL_NONE); + // render errors + EDevice.SetShader(EDevice.m_SelectionShader); + RCache.set_xform_world(Fidentity); + EDevice.RenderNearer(0.0003f); + EDevice.SetRS(D3DRS_CULLMODE, D3DCULL_NONE); AnsiString temp; - int cnt=0; - for (SDebugDraw::PointIt vit=m_DebugDraw.m_Points.begin(); vit!=m_DebugDraw.m_Points.end(); ++vit) + int cnt = 0; + for (SDebugDraw::PointIt vit = m_DebugDraw.m_Points.begin(); vit!=m_DebugDraw.m_Points.end(); ++vit) { LPCSTR s = NULL; if (vit->i) { - temp.sprintf ("P: %d",cnt++); + temp.sprintf("P: %d", cnt++); s = temp.c_str(); } - if(vit->descr.size()) + if (vit->descr.size()) { s = vit->descr.c_str(); } - DU_impl.dbgDrawVert(vit->p[0], vit->c, s?s:""); + DU_impl.dbgDrawVert(vit->p[0], vit->c, s ? s : ""); } - EDevice.SetShader (EDevice.m_SelectionShader); - cnt=0; - for (SDebugDraw::LineIt eit=m_DebugDraw.m_Lines.begin(); eit!=m_DebugDraw.m_Lines.end(); eit++){ - if (eit->i) temp.sprintf ("L: %d",cnt++); - DU_impl.dbgDrawEdge (eit->p[0],eit->p[1], eit->c, eit->i?temp.c_str():""); + EDevice.SetShader(EDevice.m_SelectionShader); + cnt = 0; + for (SDebugDraw::LineIt eit = m_DebugDraw.m_Lines.begin(); eit!=m_DebugDraw.m_Lines.end(); eit++) + { + if (eit->i) + temp.sprintf("L: %d", cnt++); + DU_impl.dbgDrawEdge(eit->p[0], eit->p[1], eit->c, eit->i ? temp.c_str() : ""); } - EDevice.SetShader (EDevice.m_SelectionShader); - cnt=0; - for (SDebugDraw::FaceIt fwit=m_DebugDraw.m_WireFaces.begin(); fwit!=m_DebugDraw.m_WireFaces.end(); fwit++){ - if (fwit->i) temp.sprintf ("F: %d",cnt++); - DU_impl.dbgDrawFace (fwit->p[0],fwit->p[1],fwit->p[2],fwit->c, fwit->i?temp.c_str():""); + EDevice.SetShader(EDevice.m_SelectionShader); + cnt = 0; + for (SDebugDraw::FaceIt fwit = m_DebugDraw.m_WireFaces.begin(); fwit!=m_DebugDraw.m_WireFaces.end(); fwit++) + { + if (fwit->i) + temp.sprintf("F: %d", cnt++); + DU_impl.dbgDrawFace(fwit->p[0], fwit->p[1], fwit->p[2], fwit->c, fwit->i ? temp.c_str() : ""); } - cnt=0; - if (!m_DebugDraw.m_SolidFaces.empty()){ - EDevice.SetShader (EDevice.m_SelectionShader); - DU_impl.DD_DrawFace_begin (FALSE); - for (SDebugDraw::FaceIt fsit=m_DebugDraw.m_SolidFaces.begin(); fsit!=m_DebugDraw.m_SolidFaces.end(); fsit++) - DU_impl.DD_DrawFace_push (fsit->p[0],fsit->p[1],fsit->p[2], fsit->c); - DU_impl.DD_DrawFace_end (); + cnt = 0; + if (!m_DebugDraw.m_SolidFaces.empty()) + { + EDevice.SetShader(EDevice.m_SelectionShader); + DU_impl.DD_DrawFace_begin(FALSE); + for (SDebugDraw::FaceIt fsit = m_DebugDraw.m_SolidFaces.begin(); fsit!=m_DebugDraw.m_SolidFaces.end(); fsit++) + DU_impl.DD_DrawFace_push(fsit->p[0], fsit->p[1], fsit->p[2], fsit->c); + DU_impl.DD_DrawFace_end(); } - EDevice.SetShader (EDevice.m_SelectionShader); - cnt=0; - for (SDebugDraw::OBBVecIt oit=m_DebugDraw.m_OBB.begin(); oit!=m_DebugDraw.m_OBB.end(); oit++) + EDevice.SetShader(EDevice.m_SelectionShader); + cnt = 0; + for (SDebugDraw::OBBVecIt oit = m_DebugDraw.m_OBB.begin(); oit!=m_DebugDraw.m_OBB.end(); oit++) { - temp.sprintf ("OBB: %d",cnt++); - DU_impl.DrawOBB (Fidentity,*oit,0x2F00FF00,0xFF00FF00); - DU_impl.OutText (oit->m_translate,temp.c_str(),0xffff0000,0x0000000); + temp.sprintf("OBB: %d", cnt++); + DU_impl.DrawOBB(Fidentity, *oit, 0x2F00FF00, 0xFF00FF00); + DU_impl.OutText(oit->m_translate, temp.c_str(), 0xffff0000, 0x0000000); } - EDevice.SetRS (D3DRS_CULLMODE,D3DCULL_CCW); - EDevice.ResetNearer (); - - if(m_pAxisMoveObject && GetSelectionPosition(m_axis_xform) ) + EDevice.SetRS(D3DRS_CULLMODE, D3DCULL_CCW); + EDevice.ResetNearer(); + + if (m_pAxisMoveObject&&GetSelectionPosition(m_axis_xform)) { - for(SurfaceIt s_it = m_pAxisMoveObject->Surfaces().begin(); s_it != m_pAxisMoveObject->Surfaces().end(); ++s_it) + for (SurfaceIt s_it = m_pAxisMoveObject->Surfaces().begin(); s_it!=m_pAxisMoveObject->Surfaces().end(); ++s_it) { - EDevice.SetShader ((*s_it)->_Shader()); - RCache.set_xform_world (m_axis_xform); - - for(int idx=0; idx< m_pAxisMoveObject->Meshes().size(); ++idx) + EDevice.SetShader((*s_it)->_Shader()); + RCache.set_xform_world(m_axis_xform); + + for (int idx = 0; idxMeshes().size(); ++idx) { - CEditableMesh* M = m_pAxisMoveObject->Meshes()[idx]; - if( (m_Axis==idx) || - (idx==etAxisZX) || - (m_Axis==etAxisZX && (idx==etAxisX || idx==etAxisZ) ) || - (m_Axis==etAxisUndefined) - ) - M->Render (m_axis_xform, *s_it); - } + CEditableMesh*M = m_pAxisMoveObject->Meshes()[idx]; + if ((m_Axis==idx)|| + (idx==etAxisZX)|| + (m_Axis==etAxisZX&&(idx==etAxisX||idx==etAxisZ))|| + (m_Axis==etAxisUndefined) + ) + M->Render(m_axis_xform, *s_it); + } } - } - - if(m_pAxisMoveObject && GetSelectionPosition(m_axis_xform) ) + } + + if (m_pAxisMoveObject&&GetSelectionPosition(m_axis_xform)) { - for(SurfaceIt s_it = m_pAxisMoveObject->Surfaces().begin(); s_it != m_pAxisMoveObject->Surfaces().end(); ++s_it) + for (SurfaceIt s_it = m_pAxisMoveObject->Surfaces().begin(); s_it!=m_pAxisMoveObject->Surfaces().end(); ++s_it) { - EDevice.SetShader ((*s_it)->_Shader()); - RCache.set_xform_world (m_axis_xform); - - for(int idx=0; idx< m_pAxisMoveObject->Meshes().size(); ++idx) + EDevice.SetShader((*s_it)->_Shader()); + RCache.set_xform_world(m_axis_xform); + + for (int idx = 0; idxMeshes().size(); ++idx) { - CEditableMesh* M = m_pAxisMoveObject->Meshes()[idx]; - if( (m_Axis==idx) || - (idx==etAxisZX) || - (m_Axis==etAxisZX && (idx==etAxisX || idx==etAxisZ) ) || - (m_Axis==etAxisUndefined) - ) - M->Render (m_axis_xform, *s_it); - } + CEditableMesh*M = m_pAxisMoveObject->Meshes()[idx]; + if ((m_Axis==idx)|| + (idx==etAxisZX)|| + (m_Axis==etAxisZX&&(idx==etAxisX||idx==etAxisZ))|| + (m_Axis==etAxisUndefined) + ) + M->Render(m_axis_xform, *s_it); + } } - } + } } + //------------------------------------------------------------------------------ + diff --git a/src/editors/ECore/Editor/UI_ToolsCustom.h b/src/editors/ECore/Editor/UI_ToolsCustom.h index e85ddec0686..94de0fd2f32 100644 --- a/src/editors/ECore/Editor/UI_ToolsCustom.h +++ b/src/editors/ECore/Editor/UI_ToolsCustom.h @@ -4,7 +4,7 @@ #include "eltree.hpp" #include "mxplacemnt.hpp" -#include "../xrEProps/ItemListHelper.h" +#include "editors/xrEProps/ItemListHelper.h" #include "EditObject.h" // refs @@ -14,7 +14,8 @@ class PropValue; class TfrmKeyBar; class CBlend; -enum ETAction{ +enum ETAction +{ etaSelect=0, etaAdd, etaMove, @@ -23,211 +24,213 @@ enum ETAction{ etaMaxActions }; -enum ETAxis{ - etAxisY, +enum ETAxis +{ + etAxisY, etAxisX, etAxisZ, etAxisZX, - etAxisUndefined, + etAxisUndefined, }; -enum ETFlags{ - etfCSParent = (1<<0), - etfNUScale = (1<<1), - etfNormalAlign = (1<<2), - etfGSnap = (1<<3), - etfOSnap = (1<<4), - etfMTSnap = (1<<5), - etfVSnap = (1<<6), - etfASnap = (1<<7), - etfMSnap = (1<<8), +enum ETFlags +{ + etfCSParent = (1<<0), + etfNUScale = (1<<1), + etfNormalAlign = (1<<2), + etfGSnap = (1<<3), + etfOSnap = (1<<4), + etfMTSnap = (1<<5), + etfVSnap = (1<<6), + etfASnap = (1<<7), + etfMSnap = (1<<8), }; class ECORE_API CToolCustom { - friend class CCustomPreferences; -protected: - bool m_bReady; - - ETAction m_Action; - ETAxis m_Axis; - Flags32 m_Settings; - - bool m_bHiddenMode; - // move - Fvector m_MoveXVector; - Fvector m_MoveYVector; - Fvector m_MoveReminder; - Fvector m_MovedAmount; - // scale - Fvector m_ScaleCenter; - Fvector m_ScaleAmount; + friendclass CCustomPreferences; + protected: + bool m_bReady; + + ETAction m_Action; + ETAxis m_Axis; + Flags32 m_Settings; + + bool m_bHiddenMode; + // move + Fvector m_MoveXVector; + Fvector m_MoveYVector; + Fvector m_MoveReminder; + Fvector m_MovedAmount; + // scale + Fvector m_ScaleCenter; + Fvector m_ScaleAmount; // rotate - Fvector m_RotateCenter; - Fvector m_RotateVector; - float m_fRotateSnapValue; - float m_RotateAmount; -public: - float m_MoveSnap; - float m_MoveSnapTo; - float m_RotateSnapAngle; -public: - float fFogness; - u32 dwFogColor; -public: - AnsiString m_LastFileName; -public: + Fvector m_RotateCenter; + Fvector m_RotateVector; + float m_fRotateSnapValue; + float m_RotateAmount; + public: + float m_MoveSnap; + float m_MoveSnapTo; + float m_RotateSnapAngle; + public: + float fFogness; + u32 dwFogColor; + public: + AnsiString m_LastFileName; + public: struct SDebugDraw{ - struct Face{ - Fvector p[3]; - u32 c; - bool i; - bool m; - }; - struct Line{ - Fvector p[2]; - u32 c; - bool i; - bool m; - }; - struct Point{ - Fvector p[1]; - u32 c; - bool i; - bool m; - xr_string descr; - }; - DEFINE_VECTOR(Face,FaceVec,FaceIt); - DEFINE_VECTOR(Line,LineVec,LineIt); - DEFINE_VECTOR(Point,PointVec,PointIt); - DEFINE_VECTOR(Fobb,OBBVec,OBBVecIt); - FaceVec m_WireFaces; - FaceVec m_SolidFaces; - LineVec m_Lines; - PointVec m_Points; - OBBVec m_OBB; - void Clear() + struct Face{ + Fvector p[3]; + u32 c; + bool i; + bool m; + }; + struct Line{ + Fvector p[2]; + u32 c; + bool i; + bool m; + }; + struct Point{ + Fvector p[1]; + u32 c; + bool i; + bool m; + xr_string descr; + }; + DEFINE_VECTOR(Face, FaceVec, FaceIt); + DEFINE_VECTOR(Line, LineVec, LineIt); + DEFINE_VECTOR(Point, PointVec, PointIt); + DEFINE_VECTOR(Fobb, OBBVec, OBBVecIt); + FaceVec m_WireFaces; + FaceVec m_SolidFaces; + LineVec m_Lines; + PointVec m_Points; + OBBVec m_OBB; + void Clear() { - m_WireFaces.clear (); - m_SolidFaces.clear (); - m_Lines.clear (); - m_Points.clear (); - m_OBB.clear (); + m_WireFaces.clear(); + m_SolidFaces.clear(); + m_Lines.clear(); + m_Points.clear(); + m_OBB.clear(); } - void AppendPoint(const Fvector& p0, u32 c=0xff0000ff, bool i=true, bool m=true, LPCSTR descr = NULL) + void AppendPoint(const Fvector&p0, u32 c = 0xff0000ff, bool i = true, bool m = true, LPCSTR descr = NULL) { - m_Points.push_back(Point()); + m_Points.push_back(Point()); m_Points.back().p[0].set(p0); - m_Points.back().c = c; - m_Points.back().i = i; - m_Points.back().m = m; + m_Points.back().c = c; + m_Points.back().i = i; + m_Points.back().m = m; if(descr) - m_Points.back().descr = descr; + m_Points.back().descr = descr; } - void AppendLine (const Fvector& p0, const Fvector& p1, u32 c=0xff00ff00, bool i=true, bool m=true) + void AppendLine(const Fvector&p0, const Fvector&p1, u32 c = 0xff00ff00, bool i = true, bool m = true) { - m_Lines.push_back(Line()); - m_Lines.back().p[0].set(p0); - m_Lines.back().p[1].set(p1); - m_Lines.back().c = c; - m_Lines.back().i = i; - m_Lines.back().m = m; + m_Lines.push_back(Line()); + m_Lines.back().p[0].set(p0); + m_Lines.back().p[1].set(p1); + m_Lines.back().c = c; + m_Lines.back().i = i; + m_Lines.back().m = m; } - void AppendWireFace (const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 c=0xffff0000, bool i=true, bool m=true) + void AppendWireFace(const Fvector&p0, const Fvector&p1, const Fvector&p2, u32 c = 0xffff0000, bool i = true, bool m = true) { - m_WireFaces.push_back(Face()); - m_WireFaces.back().p[0].set(p0); - m_WireFaces.back().p[1].set(p1); - m_WireFaces.back().p[2].set(p2); - m_WireFaces.back().c = c; - m_WireFaces.back().i = i; - m_WireFaces.back().m = m; + m_WireFaces.push_back(Face()); + m_WireFaces.back().p[0].set(p0); + m_WireFaces.back().p[1].set(p1); + m_WireFaces.back().p[2].set(p2); + m_WireFaces.back().c = c; + m_WireFaces.back().i = i; + m_WireFaces.back().m = m; } - void AppendSolidFace(const Fvector& p0, const Fvector& p1, const Fvector& p2, u32 c=0xffff0000, bool i=true, bool m=true) + void AppendSolidFace(const Fvector&p0, const Fvector&p1, const Fvector&p2, u32 c = 0xffff0000, bool i = true, bool m = true) { - m_SolidFaces.push_back(Face()); - m_SolidFaces.back().p[0].set(p0); - m_SolidFaces.back().p[1].set(p1); - m_SolidFaces.back().p[2].set(p2); - m_SolidFaces.back().c = c; - m_SolidFaces.back().i = i; - m_SolidFaces.back().m = m; + m_SolidFaces.push_back(Face()); + m_SolidFaces.back().p[0].set(p0); + m_SolidFaces.back().p[1].set(p1); + m_SolidFaces.back().p[2].set(p2); + m_SolidFaces.back().c = c; + m_SolidFaces.back().i = i; + m_SolidFaces.back().m = m; } - void AppendOBB (const Fobb& obb) + void AppendOBB(const Fobb&obb) { - m_OBB.push_back(obb); + m_OBB.push_back(obb); } }; - SDebugDraw m_DebugDraw; -public: - void ClearDebugDraw (){m_DebugDraw.Clear();} -public: - CToolCustom (); - virtual ~CToolCustom (); - - ETAction GetAction () {return m_Action;} - ETAxis GetAxis () {return m_Axis;} - BOOL GetSettings (u32 mask) {return m_Settings.is(mask);} - virtual void SetAction (ETAction act); - virtual void SetAxis (ETAxis axis); - virtual void SetSettings (u32 mask, BOOL val); - - virtual void Simulate (){}; - virtual void UseSimulatePositions(){}; - - - virtual void SetFog (u32 fog_color, float fogness){dwFogColor=fog_color;fFogness=fogness;} - virtual void GetCurrentFog (u32& fog_color, float& s_fog, float& e_fog); - - virtual void Render ()=0; - virtual void RenderEnvironment ()=0; - virtual void OnFrame ()=0; - - virtual bool OnCreate ()=0; - virtual void OnDestroy ()=0; - - virtual bool IfModified ()=0; - virtual bool IsModified ()=0; - virtual void Modified ()=0; - - virtual LPCSTR GetInfo ()=0; - - virtual void ZoomObject (BOOL bSelOnly)=0; - - virtual bool Load (LPCSTR name)=0; - virtual bool Save (LPCSTR name, bool bInternal=false)=0; - virtual void Reload ()=0; - - virtual void OnDeviceCreate ()=0; - virtual void OnDeviceDestroy ()=0; - - virtual void Clear ()=0; - - virtual void OnShowHint (AStringVec& SS)=0; - - virtual bool __fastcall MouseStart (TShiftState Shift)=0; - virtual bool __fastcall MouseEnd (TShiftState Shift)=0; - virtual void __fastcall MouseMove (TShiftState Shift)=0; - virtual bool __fastcall HiddenMode (){return m_bHiddenMode;} - virtual bool __fastcall KeyDown (WORD Key, TShiftState Shift){return false;} - virtual bool __fastcall KeyUp (WORD Key, TShiftState Shift){return false;} - virtual bool __fastcall KeyPress (WORD Key, TShiftState Shift){return false;} - - virtual bool Pick (TShiftState Shift)=0; - virtual bool RayPick (const Fvector& start, const Fvector& dir, float& dist, Fvector* pt=0, Fvector* n=0)=0; - - virtual void ShowProperties (LPCSTR focused_item)=0; - virtual void UpdateProperties (BOOL bForced=FALSE)=0; - virtual void RefreshProperties ()=0; - - const AnsiString& GetEditFileName () { return m_LastFileName; } - - CEditableObject* m_pAxisMoveObject; - Fmatrix m_axis_xform; - - virtual bool GetSelectionPosition (Fmatrix& result) =0; + SDebugDraw m_DebugDraw; + public: + void ClearDebugDraw(){m_DebugDraw.Clear();} + public: + CToolCustom(); + virtual ~CToolCustom(); + + ETAction GetAction(){return m_Action;} + ETAxis GetAxis(){return m_Axis;} + BOOL GetSettings(u32 mask){return m_Settings.is(mask);} + virtual void SetAction(ETAction act); + virtual void SetAxis(ETAxis axis); + virtual void SetSettings(u32 mask, BOOL val); + + virtual void Simulate(){}; + virtual void UseSimulatePositions(){}; + + + virtual void SetFog(u32 fog_color, float fogness){dwFogColor = fog_color;fFogness = fogness;} + virtual void GetCurrentFog(u32&fog_color, float& s_fog, float& e_fog); + + virtual void Render() = 0; + virtual void RenderEnvironment() = 0; + virtual void OnFrame() = 0; + + virtual bool OnCreate() = 0; + virtual void OnDestroy() = 0; + + virtual bool IfModified() = 0; + virtual bool IsModified() = 0; + virtual void Modified() = 0; + + virtual LPCSTR GetInfo() = 0; + + virtual void ZoomObject(BOOL bSelOnly) = 0; + + virtual bool Load(LPCSTR name) = 0; + virtual bool Save(LPCSTR name, bool bInternal = false) = 0; + virtual void Reload() = 0; + + virtual void OnDeviceCreate() = 0; + virtual void OnDeviceDestroy() = 0; + + virtual void Clear() = 0; + + virtual void OnShowHint(AStringVec&SS) = 0; + + virtual bool__fastcall MouseStart(TShiftState Shift) = 0; + virtual bool__fastcall MouseEnd(TShiftState Shift) = 0; + virtual void__fastcall MouseMove(TShiftState Shift) = 0; + virtual bool__fastcall HiddenMode(){return m_bHiddenMode;} + virtual bool__fastcall KeyDown(WORD Key, TShiftState Shift){return false;} + virtual bool__fastcall KeyUp(WORD Key, TShiftState Shift){return false;} + virtual bool__fastcall KeyPress(WORD Key, TShiftState Shift){return false;} + + virtual bool Pick(TShiftState Shift) = 0; + virtual bool RayPick(const Fvector&start, const Fvector&dir, float& dist, Fvector*pt = 0, Fvector*n = 0) = 0; + + virtual void ShowProperties(LPCSTR focused_item) = 0; + virtual void UpdateProperties(BOOL bForced = FALSE) = 0; + virtual void RefreshProperties() = 0; + + const AnsiString&GetEditFileName(){return m_LastFileName;} + + CEditableObject*m_pAxisMoveObject; + Fmatrix m_axis_xform; + + virtual bool GetSelectionPosition(Fmatrix&result) = 0; }; -extern ECORE_API CToolCustom* Tools; +extern ECORE_API CToolCustom* Tools; #define SURFACES_PREFIX "Surfaces" #define BONES_PREFIX "Bones" @@ -235,3 +238,4 @@ extern ECORE_API CToolCustom* Tools; #define OBJECT_PREFIX "Object" //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/c_dinput.cpp b/src/editors/ECore/Editor/c_dinput.cpp index d348dca2180..abee3df1ec7 100644 --- a/src/editors/ECore/Editor/c_dinput.cpp +++ b/src/editors/ECore/Editor/c_dinput.cpp @@ -10,262 +10,262 @@ #pragma hdrstop static DIOBJECTDATAFORMAT rgodfDIKeyboard[] = { - { &GUID_Key, 0, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(0) | 0x80000000, 0 }, - { &GUID_Key, 1, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(1) | 0x80000000, 0 }, - { &GUID_Key, 2, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(2) | 0x80000000, 0 }, - { &GUID_Key, 3, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(3) | 0x80000000, 0 }, - { &GUID_Key, 4, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(4) | 0x80000000, 0 }, - { &GUID_Key, 5, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(5) | 0x80000000, 0 }, - { &GUID_Key, 6, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(6) | 0x80000000, 0 }, - { &GUID_Key, 7, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(7) | 0x80000000, 0 }, - { &GUID_Key, 8, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(8) | 0x80000000, 0 }, - { &GUID_Key, 9, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(9) | 0x80000000, 0 }, - { &GUID_Key, 10, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(10) | 0x80000000, 0 }, - { &GUID_Key, 11, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(11) | 0x80000000, 0 }, - { &GUID_Key, 12, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(12) | 0x80000000, 0 }, - { &GUID_Key, 13, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(13) | 0x80000000, 0 }, - { &GUID_Key, 14, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(14) | 0x80000000, 0 }, - { &GUID_Key, 15, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(15) | 0x80000000, 0 }, - { &GUID_Key, 16, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(16) | 0x80000000, 0 }, - { &GUID_Key, 17, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(17) | 0x80000000, 0 }, - { &GUID_Key, 18, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(18) | 0x80000000, 0 }, - { &GUID_Key, 19, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(19) | 0x80000000, 0 }, - { &GUID_Key, 20, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(20) | 0x80000000, 0 }, - { &GUID_Key, 21, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(21) | 0x80000000, 0 }, - { &GUID_Key, 22, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(22) | 0x80000000, 0 }, - { &GUID_Key, 23, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(23) | 0x80000000, 0 }, - { &GUID_Key, 24, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(24) | 0x80000000, 0 }, - { &GUID_Key, 25, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(25) | 0x80000000, 0 }, - { &GUID_Key, 26, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(26) | 0x80000000, 0 }, - { &GUID_Key, 27, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(27) | 0x80000000, 0 }, - { &GUID_Key, 28, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(28) | 0x80000000, 0 }, - { &GUID_Key, 29, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(29) | 0x80000000, 0 }, - { &GUID_Key, 30, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(30) | 0x80000000, 0 }, - { &GUID_Key, 31, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(31) | 0x80000000, 0 }, - { &GUID_Key, 32, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(32) | 0x80000000, 0 }, - { &GUID_Key, 33, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(33) | 0x80000000, 0 }, - { &GUID_Key, 34, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(34) | 0x80000000, 0 }, - { &GUID_Key, 35, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(35) | 0x80000000, 0 }, - { &GUID_Key, 36, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(36) | 0x80000000, 0 }, - { &GUID_Key, 37, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(37) | 0x80000000, 0 }, - { &GUID_Key, 38, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(38) | 0x80000000, 0 }, - { &GUID_Key, 39, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(39) | 0x80000000, 0 }, - { &GUID_Key, 40, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(40) | 0x80000000, 0 }, - { &GUID_Key, 41, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(41) | 0x80000000, 0 }, - { &GUID_Key, 42, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(42) | 0x80000000, 0 }, - { &GUID_Key, 43, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(43) | 0x80000000, 0 }, - { &GUID_Key, 44, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(44) | 0x80000000, 0 }, - { &GUID_Key, 45, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(45) | 0x80000000, 0 }, - { &GUID_Key, 46, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(46) | 0x80000000, 0 }, - { &GUID_Key, 47, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(47) | 0x80000000, 0 }, - { &GUID_Key, 48, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(48) | 0x80000000, 0 }, - { &GUID_Key, 49, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(49) | 0x80000000, 0 }, - { &GUID_Key, 50, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(50) | 0x80000000, 0 }, - { &GUID_Key, 51, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(51) | 0x80000000, 0 }, - { &GUID_Key, 52, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(52) | 0x80000000, 0 }, - { &GUID_Key, 53, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(53) | 0x80000000, 0 }, - { &GUID_Key, 54, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(54) | 0x80000000, 0 }, - { &GUID_Key, 55, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(55) | 0x80000000, 0 }, - { &GUID_Key, 56, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(56) | 0x80000000, 0 }, - { &GUID_Key, 57, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(57) | 0x80000000, 0 }, - { &GUID_Key, 58, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(58) | 0x80000000, 0 }, - { &GUID_Key, 59, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(59) | 0x80000000, 0 }, - { &GUID_Key, 60, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(60) | 0x80000000, 0 }, - { &GUID_Key, 61, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(61) | 0x80000000, 0 }, - { &GUID_Key, 62, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(62) | 0x80000000, 0 }, - { &GUID_Key, 63, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(63) | 0x80000000, 0 }, - { &GUID_Key, 64, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(64) | 0x80000000, 0 }, - { &GUID_Key, 65, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(65) | 0x80000000, 0 }, - { &GUID_Key, 66, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(66) | 0x80000000, 0 }, - { &GUID_Key, 67, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(67) | 0x80000000, 0 }, - { &GUID_Key, 68, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(68) | 0x80000000, 0 }, - { &GUID_Key, 69, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(69) | 0x80000000, 0 }, - { &GUID_Key, 70, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(70) | 0x80000000, 0 }, - { &GUID_Key, 71, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(71) | 0x80000000, 0 }, - { &GUID_Key, 72, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(72) | 0x80000000, 0 }, - { &GUID_Key, 73, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(73) | 0x80000000, 0 }, - { &GUID_Key, 74, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(74) | 0x80000000, 0 }, - { &GUID_Key, 75, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(75) | 0x80000000, 0 }, - { &GUID_Key, 76, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(76) | 0x80000000, 0 }, - { &GUID_Key, 77, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(77) | 0x80000000, 0 }, - { &GUID_Key, 78, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(78) | 0x80000000, 0 }, - { &GUID_Key, 79, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(79) | 0x80000000, 0 }, - { &GUID_Key, 80, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(80) | 0x80000000, 0 }, - { &GUID_Key, 81, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(81) | 0x80000000, 0 }, - { &GUID_Key, 82, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(82) | 0x80000000, 0 }, - { &GUID_Key, 83, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(83) | 0x80000000, 0 }, - { &GUID_Key, 84, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(84) | 0x80000000, 0 }, - { &GUID_Key, 85, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(85) | 0x80000000, 0 }, - { &GUID_Key, 86, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(86) | 0x80000000, 0 }, - { &GUID_Key, 87, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(87) | 0x80000000, 0 }, - { &GUID_Key, 88, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(88) | 0x80000000, 0 }, - { &GUID_Key, 89, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(89) | 0x80000000, 0 }, - { &GUID_Key, 90, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(90) | 0x80000000, 0 }, - { &GUID_Key, 91, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(91) | 0x80000000, 0 }, - { &GUID_Key, 92, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(92) | 0x80000000, 0 }, - { &GUID_Key, 93, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(93) | 0x80000000, 0 }, - { &GUID_Key, 94, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(94) | 0x80000000, 0 }, - { &GUID_Key, 95, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(95) | 0x80000000, 0 }, - { &GUID_Key, 96, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(96) | 0x80000000, 0 }, - { &GUID_Key, 97, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(97) | 0x80000000, 0 }, - { &GUID_Key, 98, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(98) | 0x80000000, 0 }, - { &GUID_Key, 99, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(99) | 0x80000000, 0 }, - { &GUID_Key, 100, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(100) | 0x80000000, 0 }, - { &GUID_Key, 101, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(101) | 0x80000000, 0 }, - { &GUID_Key, 102, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(102) | 0x80000000, 0 }, - { &GUID_Key, 103, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(103) | 0x80000000, 0 }, - { &GUID_Key, 104, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(104) | 0x80000000, 0 }, - { &GUID_Key, 105, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(105) | 0x80000000, 0 }, - { &GUID_Key, 106, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(106) | 0x80000000, 0 }, - { &GUID_Key, 107, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(107) | 0x80000000, 0 }, - { &GUID_Key, 108, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(108) | 0x80000000, 0 }, - { &GUID_Key, 109, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(109) | 0x80000000, 0 }, - { &GUID_Key, 110, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(110) | 0x80000000, 0 }, - { &GUID_Key, 111, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(111) | 0x80000000, 0 }, - { &GUID_Key, 112, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(112) | 0x80000000, 0 }, - { &GUID_Key, 113, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(113) | 0x80000000, 0 }, - { &GUID_Key, 114, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(114) | 0x80000000, 0 }, - { &GUID_Key, 115, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(115) | 0x80000000, 0 }, - { &GUID_Key, 116, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(116) | 0x80000000, 0 }, - { &GUID_Key, 117, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(117) | 0x80000000, 0 }, - { &GUID_Key, 118, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(118) | 0x80000000, 0 }, - { &GUID_Key, 119, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(119) | 0x80000000, 0 }, - { &GUID_Key, 120, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(120) | 0x80000000, 0 }, - { &GUID_Key, 121, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(121) | 0x80000000, 0 }, - { &GUID_Key, 122, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(122) | 0x80000000, 0 }, - { &GUID_Key, 123, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(123) | 0x80000000, 0 }, - { &GUID_Key, 124, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(124) | 0x80000000, 0 }, - { &GUID_Key, 125, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(125) | 0x80000000, 0 }, - { &GUID_Key, 126, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(126) | 0x80000000, 0 }, - { &GUID_Key, 127, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(127) | 0x80000000, 0 }, - { &GUID_Key, 128, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(128) | 0x80000000, 0 }, - { &GUID_Key, 129, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(129) | 0x80000000, 0 }, - { &GUID_Key, 130, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(130) | 0x80000000, 0 }, - { &GUID_Key, 131, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(131) | 0x80000000, 0 }, - { &GUID_Key, 132, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(132) | 0x80000000, 0 }, - { &GUID_Key, 133, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(133) | 0x80000000, 0 }, - { &GUID_Key, 134, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(134) | 0x80000000, 0 }, - { &GUID_Key, 135, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(135) | 0x80000000, 0 }, - { &GUID_Key, 136, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(136) | 0x80000000, 0 }, - { &GUID_Key, 137, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(137) | 0x80000000, 0 }, - { &GUID_Key, 138, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(138) | 0x80000000, 0 }, - { &GUID_Key, 139, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(139) | 0x80000000, 0 }, - { &GUID_Key, 140, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(140) | 0x80000000, 0 }, - { &GUID_Key, 141, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(141) | 0x80000000, 0 }, - { &GUID_Key, 142, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(142) | 0x80000000, 0 }, - { &GUID_Key, 143, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(143) | 0x80000000, 0 }, - { &GUID_Key, 144, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(144) | 0x80000000, 0 }, - { &GUID_Key, 145, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(145) | 0x80000000, 0 }, - { &GUID_Key, 146, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(146) | 0x80000000, 0 }, - { &GUID_Key, 147, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(147) | 0x80000000, 0 }, - { &GUID_Key, 148, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(148) | 0x80000000, 0 }, - { &GUID_Key, 149, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(149) | 0x80000000, 0 }, - { &GUID_Key, 150, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(150) | 0x80000000, 0 }, - { &GUID_Key, 151, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(151) | 0x80000000, 0 }, - { &GUID_Key, 152, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(152) | 0x80000000, 0 }, - { &GUID_Key, 153, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(153) | 0x80000000, 0 }, - { &GUID_Key, 154, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(154) | 0x80000000, 0 }, - { &GUID_Key, 155, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(155) | 0x80000000, 0 }, - { &GUID_Key, 156, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(156) | 0x80000000, 0 }, - { &GUID_Key, 157, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(157) | 0x80000000, 0 }, - { &GUID_Key, 158, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(158) | 0x80000000, 0 }, - { &GUID_Key, 159, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(159) | 0x80000000, 0 }, - { &GUID_Key, 160, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(160) | 0x80000000, 0 }, - { &GUID_Key, 161, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(161) | 0x80000000, 0 }, - { &GUID_Key, 162, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(162) | 0x80000000, 0 }, - { &GUID_Key, 163, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(163) | 0x80000000, 0 }, - { &GUID_Key, 164, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(164) | 0x80000000, 0 }, - { &GUID_Key, 165, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(165) | 0x80000000, 0 }, - { &GUID_Key, 166, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(166) | 0x80000000, 0 }, - { &GUID_Key, 167, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(167) | 0x80000000, 0 }, - { &GUID_Key, 168, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(168) | 0x80000000, 0 }, - { &GUID_Key, 169, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(169) | 0x80000000, 0 }, - { &GUID_Key, 170, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(170) | 0x80000000, 0 }, - { &GUID_Key, 171, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(171) | 0x80000000, 0 }, - { &GUID_Key, 172, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(172) | 0x80000000, 0 }, - { &GUID_Key, 173, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(173) | 0x80000000, 0 }, - { &GUID_Key, 174, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(174) | 0x80000000, 0 }, - { &GUID_Key, 175, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(175) | 0x80000000, 0 }, - { &GUID_Key, 176, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(176) | 0x80000000, 0 }, - { &GUID_Key, 177, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(177) | 0x80000000, 0 }, - { &GUID_Key, 178, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(178) | 0x80000000, 0 }, - { &GUID_Key, 179, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(179) | 0x80000000, 0 }, - { &GUID_Key, 180, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(180) | 0x80000000, 0 }, - { &GUID_Key, 181, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(181) | 0x80000000, 0 }, - { &GUID_Key, 182, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(182) | 0x80000000, 0 }, - { &GUID_Key, 183, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(183) | 0x80000000, 0 }, - { &GUID_Key, 184, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(184) | 0x80000000, 0 }, - { &GUID_Key, 185, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(185) | 0x80000000, 0 }, - { &GUID_Key, 186, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(186) | 0x80000000, 0 }, - { &GUID_Key, 187, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(187) | 0x80000000, 0 }, - { &GUID_Key, 188, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(188) | 0x80000000, 0 }, - { &GUID_Key, 189, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(189) | 0x80000000, 0 }, - { &GUID_Key, 190, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(190) | 0x80000000, 0 }, - { &GUID_Key, 191, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(191) | 0x80000000, 0 }, - { &GUID_Key, 192, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(192) | 0x80000000, 0 }, - { &GUID_Key, 193, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(193) | 0x80000000, 0 }, - { &GUID_Key, 194, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(194) | 0x80000000, 0 }, - { &GUID_Key, 195, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(195) | 0x80000000, 0 }, - { &GUID_Key, 196, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(196) | 0x80000000, 0 }, - { &GUID_Key, 197, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(197) | 0x80000000, 0 }, - { &GUID_Key, 198, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(198) | 0x80000000, 0 }, - { &GUID_Key, 199, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(199) | 0x80000000, 0 }, - { &GUID_Key, 200, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(200) | 0x80000000, 0 }, - { &GUID_Key, 201, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(201) | 0x80000000, 0 }, - { &GUID_Key, 202, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(202) | 0x80000000, 0 }, - { &GUID_Key, 203, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(203) | 0x80000000, 0 }, - { &GUID_Key, 204, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(204) | 0x80000000, 0 }, - { &GUID_Key, 205, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(205) | 0x80000000, 0 }, - { &GUID_Key, 206, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(206) | 0x80000000, 0 }, - { &GUID_Key, 207, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(207) | 0x80000000, 0 }, - { &GUID_Key, 208, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(208) | 0x80000000, 0 }, - { &GUID_Key, 209, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(209) | 0x80000000, 0 }, - { &GUID_Key, 210, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(210) | 0x80000000, 0 }, - { &GUID_Key, 211, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(211) | 0x80000000, 0 }, - { &GUID_Key, 212, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(212) | 0x80000000, 0 }, - { &GUID_Key, 213, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(213) | 0x80000000, 0 }, - { &GUID_Key, 214, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(214) | 0x80000000, 0 }, - { &GUID_Key, 215, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(215) | 0x80000000, 0 }, - { &GUID_Key, 216, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(216) | 0x80000000, 0 }, - { &GUID_Key, 217, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(217) | 0x80000000, 0 }, - { &GUID_Key, 218, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(218) | 0x80000000, 0 }, - { &GUID_Key, 219, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(219) | 0x80000000, 0 }, - { &GUID_Key, 220, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(220) | 0x80000000, 0 }, - { &GUID_Key, 221, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(221) | 0x80000000, 0 }, - { &GUID_Key, 222, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(222) | 0x80000000, 0 }, - { &GUID_Key, 223, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(223) | 0x80000000, 0 }, - { &GUID_Key, 224, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(224) | 0x80000000, 0 }, - { &GUID_Key, 225, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(225) | 0x80000000, 0 }, - { &GUID_Key, 226, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(226) | 0x80000000, 0 }, - { &GUID_Key, 227, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(227) | 0x80000000, 0 }, - { &GUID_Key, 228, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(228) | 0x80000000, 0 }, - { &GUID_Key, 229, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(229) | 0x80000000, 0 }, - { &GUID_Key, 230, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(230) | 0x80000000, 0 }, - { &GUID_Key, 231, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(231) | 0x80000000, 0 }, - { &GUID_Key, 232, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(232) | 0x80000000, 0 }, - { &GUID_Key, 233, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(233) | 0x80000000, 0 }, - { &GUID_Key, 234, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(234) | 0x80000000, 0 }, - { &GUID_Key, 235, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(235) | 0x80000000, 0 }, - { &GUID_Key, 236, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(236) | 0x80000000, 0 }, - { &GUID_Key, 237, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(237) | 0x80000000, 0 }, - { &GUID_Key, 238, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(238) | 0x80000000, 0 }, - { &GUID_Key, 239, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(239) | 0x80000000, 0 }, - { &GUID_Key, 240, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(240) | 0x80000000, 0 }, - { &GUID_Key, 241, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(241) | 0x80000000, 0 }, - { &GUID_Key, 242, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(242) | 0x80000000, 0 }, - { &GUID_Key, 243, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(243) | 0x80000000, 0 }, - { &GUID_Key, 244, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(244) | 0x80000000, 0 }, - { &GUID_Key, 245, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(245) | 0x80000000, 0 }, - { &GUID_Key, 246, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(246) | 0x80000000, 0 }, - { &GUID_Key, 247, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(247) | 0x80000000, 0 }, - { &GUID_Key, 248, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(248) | 0x80000000, 0 }, - { &GUID_Key, 249, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(249) | 0x80000000, 0 }, - { &GUID_Key, 250, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(250) | 0x80000000, 0 }, - { &GUID_Key, 251, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(251) | 0x80000000, 0 }, - { &GUID_Key, 252, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(252) | 0x80000000, 0 }, - { &GUID_Key, 253, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(253) | 0x80000000, 0 }, - { &GUID_Key, 254, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(254) | 0x80000000, 0 }, - { &GUID_Key, 255, DIDFT_BUTTON | DIDFT_MAKEINSTANCE(255) | 0x80000000, 0 } + {&GUID_Key, 0, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(0)|0x80000000, 0}, + {&GUID_Key, 1, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(1)|0x80000000, 0}, + {&GUID_Key, 2, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(2)|0x80000000, 0}, + {&GUID_Key, 3, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(3)|0x80000000, 0}, + {&GUID_Key, 4, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(4)|0x80000000, 0}, + {&GUID_Key, 5, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(5)|0x80000000, 0}, + {&GUID_Key, 6, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(6)|0x80000000, 0}, + {&GUID_Key, 7, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(7)|0x80000000, 0}, + {&GUID_Key, 8, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(8)|0x80000000, 0}, + {&GUID_Key, 9, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(9)|0x80000000, 0}, + {&GUID_Key, 10, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(10)|0x80000000, 0}, + {&GUID_Key, 11, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(11)|0x80000000, 0}, + {&GUID_Key, 12, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(12)|0x80000000, 0}, + {&GUID_Key, 13, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(13)|0x80000000, 0}, + {&GUID_Key, 14, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(14)|0x80000000, 0}, + {&GUID_Key, 15, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(15)|0x80000000, 0}, + {&GUID_Key, 16, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(16)|0x80000000, 0}, + {&GUID_Key, 17, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(17)|0x80000000, 0}, + {&GUID_Key, 18, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(18)|0x80000000, 0}, + {&GUID_Key, 19, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(19)|0x80000000, 0}, + {&GUID_Key, 20, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(20)|0x80000000, 0}, + {&GUID_Key, 21, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(21)|0x80000000, 0}, + {&GUID_Key, 22, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(22)|0x80000000, 0}, + {&GUID_Key, 23, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(23)|0x80000000, 0}, + {&GUID_Key, 24, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(24)|0x80000000, 0}, + {&GUID_Key, 25, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(25)|0x80000000, 0}, + {&GUID_Key, 26, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(26)|0x80000000, 0}, + {&GUID_Key, 27, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(27)|0x80000000, 0}, + {&GUID_Key, 28, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(28)|0x80000000, 0}, + {&GUID_Key, 29, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(29)|0x80000000, 0}, + {&GUID_Key, 30, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(30)|0x80000000, 0}, + {&GUID_Key, 31, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(31)|0x80000000, 0}, + {&GUID_Key, 32, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(32)|0x80000000, 0}, + {&GUID_Key, 33, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(33)|0x80000000, 0}, + {&GUID_Key, 34, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(34)|0x80000000, 0}, + {&GUID_Key, 35, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(35)|0x80000000, 0}, + {&GUID_Key, 36, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(36)|0x80000000, 0}, + {&GUID_Key, 37, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(37)|0x80000000, 0}, + {&GUID_Key, 38, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(38)|0x80000000, 0}, + {&GUID_Key, 39, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(39)|0x80000000, 0}, + {&GUID_Key, 40, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(40)|0x80000000, 0}, + {&GUID_Key, 41, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(41)|0x80000000, 0}, + {&GUID_Key, 42, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(42)|0x80000000, 0}, + {&GUID_Key, 43, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(43)|0x80000000, 0}, + {&GUID_Key, 44, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(44)|0x80000000, 0}, + {&GUID_Key, 45, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(45)|0x80000000, 0}, + {&GUID_Key, 46, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(46)|0x80000000, 0}, + {&GUID_Key, 47, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(47)|0x80000000, 0}, + {&GUID_Key, 48, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(48)|0x80000000, 0}, + {&GUID_Key, 49, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(49)|0x80000000, 0}, + {&GUID_Key, 50, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(50)|0x80000000, 0}, + {&GUID_Key, 51, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(51)|0x80000000, 0}, + {&GUID_Key, 52, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(52)|0x80000000, 0}, + {&GUID_Key, 53, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(53)|0x80000000, 0}, + {&GUID_Key, 54, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(54)|0x80000000, 0}, + {&GUID_Key, 55, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(55)|0x80000000, 0}, + {&GUID_Key, 56, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(56)|0x80000000, 0}, + {&GUID_Key, 57, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(57)|0x80000000, 0}, + {&GUID_Key, 58, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(58)|0x80000000, 0}, + {&GUID_Key, 59, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(59)|0x80000000, 0}, + {&GUID_Key, 60, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(60)|0x80000000, 0}, + {&GUID_Key, 61, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(61)|0x80000000, 0}, + {&GUID_Key, 62, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(62)|0x80000000, 0}, + {&GUID_Key, 63, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(63)|0x80000000, 0}, + {&GUID_Key, 64, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(64)|0x80000000, 0}, + {&GUID_Key, 65, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(65)|0x80000000, 0}, + {&GUID_Key, 66, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(66)|0x80000000, 0}, + {&GUID_Key, 67, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(67)|0x80000000, 0}, + {&GUID_Key, 68, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(68)|0x80000000, 0}, + {&GUID_Key, 69, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(69)|0x80000000, 0}, + {&GUID_Key, 70, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(70)|0x80000000, 0}, + {&GUID_Key, 71, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(71)|0x80000000, 0}, + {&GUID_Key, 72, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(72)|0x80000000, 0}, + {&GUID_Key, 73, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(73)|0x80000000, 0}, + {&GUID_Key, 74, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(74)|0x80000000, 0}, + {&GUID_Key, 75, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(75)|0x80000000, 0}, + {&GUID_Key, 76, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(76)|0x80000000, 0}, + {&GUID_Key, 77, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(77)|0x80000000, 0}, + {&GUID_Key, 78, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(78)|0x80000000, 0}, + {&GUID_Key, 79, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(79)|0x80000000, 0}, + {&GUID_Key, 80, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(80)|0x80000000, 0}, + {&GUID_Key, 81, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(81)|0x80000000, 0}, + {&GUID_Key, 82, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(82)|0x80000000, 0}, + {&GUID_Key, 83, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(83)|0x80000000, 0}, + {&GUID_Key, 84, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(84)|0x80000000, 0}, + {&GUID_Key, 85, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(85)|0x80000000, 0}, + {&GUID_Key, 86, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(86)|0x80000000, 0}, + {&GUID_Key, 87, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(87)|0x80000000, 0}, + {&GUID_Key, 88, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(88)|0x80000000, 0}, + {&GUID_Key, 89, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(89)|0x80000000, 0}, + {&GUID_Key, 90, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(90)|0x80000000, 0}, + {&GUID_Key, 91, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(91)|0x80000000, 0}, + {&GUID_Key, 92, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(92)|0x80000000, 0}, + {&GUID_Key, 93, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(93)|0x80000000, 0}, + {&GUID_Key, 94, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(94)|0x80000000, 0}, + {&GUID_Key, 95, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(95)|0x80000000, 0}, + {&GUID_Key, 96, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(96)|0x80000000, 0}, + {&GUID_Key, 97, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(97)|0x80000000, 0}, + {&GUID_Key, 98, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(98)|0x80000000, 0}, + {&GUID_Key, 99, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(99)|0x80000000, 0}, + {&GUID_Key, 100, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(100)|0x80000000, 0}, + {&GUID_Key, 101, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(101)|0x80000000, 0}, + {&GUID_Key, 102, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(102)|0x80000000, 0}, + {&GUID_Key, 103, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(103)|0x80000000, 0}, + {&GUID_Key, 104, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(104)|0x80000000, 0}, + {&GUID_Key, 105, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(105)|0x80000000, 0}, + {&GUID_Key, 106, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(106)|0x80000000, 0}, + {&GUID_Key, 107, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(107)|0x80000000, 0}, + {&GUID_Key, 108, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(108)|0x80000000, 0}, + {&GUID_Key, 109, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(109)|0x80000000, 0}, + {&GUID_Key, 110, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(110)|0x80000000, 0}, + {&GUID_Key, 111, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(111)|0x80000000, 0}, + {&GUID_Key, 112, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(112)|0x80000000, 0}, + {&GUID_Key, 113, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(113)|0x80000000, 0}, + {&GUID_Key, 114, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(114)|0x80000000, 0}, + {&GUID_Key, 115, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(115)|0x80000000, 0}, + {&GUID_Key, 116, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(116)|0x80000000, 0}, + {&GUID_Key, 117, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(117)|0x80000000, 0}, + {&GUID_Key, 118, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(118)|0x80000000, 0}, + {&GUID_Key, 119, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(119)|0x80000000, 0}, + {&GUID_Key, 120, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(120)|0x80000000, 0}, + {&GUID_Key, 121, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(121)|0x80000000, 0}, + {&GUID_Key, 122, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(122)|0x80000000, 0}, + {&GUID_Key, 123, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(123)|0x80000000, 0}, + {&GUID_Key, 124, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(124)|0x80000000, 0}, + {&GUID_Key, 125, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(125)|0x80000000, 0}, + {&GUID_Key, 126, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(126)|0x80000000, 0}, + {&GUID_Key, 127, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(127)|0x80000000, 0}, + {&GUID_Key, 128, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(128)|0x80000000, 0}, + {&GUID_Key, 129, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(129)|0x80000000, 0}, + {&GUID_Key, 130, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(130)|0x80000000, 0}, + {&GUID_Key, 131, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(131)|0x80000000, 0}, + {&GUID_Key, 132, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(132)|0x80000000, 0}, + {&GUID_Key, 133, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(133)|0x80000000, 0}, + {&GUID_Key, 134, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(134)|0x80000000, 0}, + {&GUID_Key, 135, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(135)|0x80000000, 0}, + {&GUID_Key, 136, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(136)|0x80000000, 0}, + {&GUID_Key, 137, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(137)|0x80000000, 0}, + {&GUID_Key, 138, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(138)|0x80000000, 0}, + {&GUID_Key, 139, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(139)|0x80000000, 0}, + {&GUID_Key, 140, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(140)|0x80000000, 0}, + {&GUID_Key, 141, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(141)|0x80000000, 0}, + {&GUID_Key, 142, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(142)|0x80000000, 0}, + {&GUID_Key, 143, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(143)|0x80000000, 0}, + {&GUID_Key, 144, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(144)|0x80000000, 0}, + {&GUID_Key, 145, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(145)|0x80000000, 0}, + {&GUID_Key, 146, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(146)|0x80000000, 0}, + {&GUID_Key, 147, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(147)|0x80000000, 0}, + {&GUID_Key, 148, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(148)|0x80000000, 0}, + {&GUID_Key, 149, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(149)|0x80000000, 0}, + {&GUID_Key, 150, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(150)|0x80000000, 0}, + {&GUID_Key, 151, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(151)|0x80000000, 0}, + {&GUID_Key, 152, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(152)|0x80000000, 0}, + {&GUID_Key, 153, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(153)|0x80000000, 0}, + {&GUID_Key, 154, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(154)|0x80000000, 0}, + {&GUID_Key, 155, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(155)|0x80000000, 0}, + {&GUID_Key, 156, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(156)|0x80000000, 0}, + {&GUID_Key, 157, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(157)|0x80000000, 0}, + {&GUID_Key, 158, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(158)|0x80000000, 0}, + {&GUID_Key, 159, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(159)|0x80000000, 0}, + {&GUID_Key, 160, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(160)|0x80000000, 0}, + {&GUID_Key, 161, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(161)|0x80000000, 0}, + {&GUID_Key, 162, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(162)|0x80000000, 0}, + {&GUID_Key, 163, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(163)|0x80000000, 0}, + {&GUID_Key, 164, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(164)|0x80000000, 0}, + {&GUID_Key, 165, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(165)|0x80000000, 0}, + {&GUID_Key, 166, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(166)|0x80000000, 0}, + {&GUID_Key, 167, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(167)|0x80000000, 0}, + {&GUID_Key, 168, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(168)|0x80000000, 0}, + {&GUID_Key, 169, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(169)|0x80000000, 0}, + {&GUID_Key, 170, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(170)|0x80000000, 0}, + {&GUID_Key, 171, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(171)|0x80000000, 0}, + {&GUID_Key, 172, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(172)|0x80000000, 0}, + {&GUID_Key, 173, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(173)|0x80000000, 0}, + {&GUID_Key, 174, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(174)|0x80000000, 0}, + {&GUID_Key, 175, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(175)|0x80000000, 0}, + {&GUID_Key, 176, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(176)|0x80000000, 0}, + {&GUID_Key, 177, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(177)|0x80000000, 0}, + {&GUID_Key, 178, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(178)|0x80000000, 0}, + {&GUID_Key, 179, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(179)|0x80000000, 0}, + {&GUID_Key, 180, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(180)|0x80000000, 0}, + {&GUID_Key, 181, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(181)|0x80000000, 0}, + {&GUID_Key, 182, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(182)|0x80000000, 0}, + {&GUID_Key, 183, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(183)|0x80000000, 0}, + {&GUID_Key, 184, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(184)|0x80000000, 0}, + {&GUID_Key, 185, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(185)|0x80000000, 0}, + {&GUID_Key, 186, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(186)|0x80000000, 0}, + {&GUID_Key, 187, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(187)|0x80000000, 0}, + {&GUID_Key, 188, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(188)|0x80000000, 0}, + {&GUID_Key, 189, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(189)|0x80000000, 0}, + {&GUID_Key, 190, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(190)|0x80000000, 0}, + {&GUID_Key, 191, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(191)|0x80000000, 0}, + {&GUID_Key, 192, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(192)|0x80000000, 0}, + {&GUID_Key, 193, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(193)|0x80000000, 0}, + {&GUID_Key, 194, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(194)|0x80000000, 0}, + {&GUID_Key, 195, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(195)|0x80000000, 0}, + {&GUID_Key, 196, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(196)|0x80000000, 0}, + {&GUID_Key, 197, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(197)|0x80000000, 0}, + {&GUID_Key, 198, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(198)|0x80000000, 0}, + {&GUID_Key, 199, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(199)|0x80000000, 0}, + {&GUID_Key, 200, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(200)|0x80000000, 0}, + {&GUID_Key, 201, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(201)|0x80000000, 0}, + {&GUID_Key, 202, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(202)|0x80000000, 0}, + {&GUID_Key, 203, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(203)|0x80000000, 0}, + {&GUID_Key, 204, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(204)|0x80000000, 0}, + {&GUID_Key, 205, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(205)|0x80000000, 0}, + {&GUID_Key, 206, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(206)|0x80000000, 0}, + {&GUID_Key, 207, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(207)|0x80000000, 0}, + {&GUID_Key, 208, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(208)|0x80000000, 0}, + {&GUID_Key, 209, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(209)|0x80000000, 0}, + {&GUID_Key, 210, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(210)|0x80000000, 0}, + {&GUID_Key, 211, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(211)|0x80000000, 0}, + {&GUID_Key, 212, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(212)|0x80000000, 0}, + {&GUID_Key, 213, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(213)|0x80000000, 0}, + {&GUID_Key, 214, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(214)|0x80000000, 0}, + {&GUID_Key, 215, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(215)|0x80000000, 0}, + {&GUID_Key, 216, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(216)|0x80000000, 0}, + {&GUID_Key, 217, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(217)|0x80000000, 0}, + {&GUID_Key, 218, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(218)|0x80000000, 0}, + {&GUID_Key, 219, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(219)|0x80000000, 0}, + {&GUID_Key, 220, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(220)|0x80000000, 0}, + {&GUID_Key, 221, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(221)|0x80000000, 0}, + {&GUID_Key, 222, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(222)|0x80000000, 0}, + {&GUID_Key, 223, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(223)|0x80000000, 0}, + {&GUID_Key, 224, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(224)|0x80000000, 0}, + {&GUID_Key, 225, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(225)|0x80000000, 0}, + {&GUID_Key, 226, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(226)|0x80000000, 0}, + {&GUID_Key, 227, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(227)|0x80000000, 0}, + {&GUID_Key, 228, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(228)|0x80000000, 0}, + {&GUID_Key, 229, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(229)|0x80000000, 0}, + {&GUID_Key, 230, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(230)|0x80000000, 0}, + {&GUID_Key, 231, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(231)|0x80000000, 0}, + {&GUID_Key, 232, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(232)|0x80000000, 0}, + {&GUID_Key, 233, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(233)|0x80000000, 0}, + {&GUID_Key, 234, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(234)|0x80000000, 0}, + {&GUID_Key, 235, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(235)|0x80000000, 0}, + {&GUID_Key, 236, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(236)|0x80000000, 0}, + {&GUID_Key, 237, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(237)|0x80000000, 0}, + {&GUID_Key, 238, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(238)|0x80000000, 0}, + {&GUID_Key, 239, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(239)|0x80000000, 0}, + {&GUID_Key, 240, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(240)|0x80000000, 0}, + {&GUID_Key, 241, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(241)|0x80000000, 0}, + {&GUID_Key, 242, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(242)|0x80000000, 0}, + {&GUID_Key, 243, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(243)|0x80000000, 0}, + {&GUID_Key, 244, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(244)|0x80000000, 0}, + {&GUID_Key, 245, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(245)|0x80000000, 0}, + {&GUID_Key, 246, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(246)|0x80000000, 0}, + {&GUID_Key, 247, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(247)|0x80000000, 0}, + {&GUID_Key, 248, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(248)|0x80000000, 0}, + {&GUID_Key, 249, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(249)|0x80000000, 0}, + {&GUID_Key, 250, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(250)|0x80000000, 0}, + {&GUID_Key, 251, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(251)|0x80000000, 0}, + {&GUID_Key, 252, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(252)|0x80000000, 0}, + {&GUID_Key, 253, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(253)|0x80000000, 0}, + {&GUID_Key, 254, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(254)|0x80000000, 0}, + {&GUID_Key, 255, DIDFT_BUTTON|DIDFT_MAKEINSTANCE(255)|0x80000000, 0} }; extern const DIDATAFORMAT c_dfDIKeyboard = { @@ -278,13 +278,13 @@ extern const DIDATAFORMAT c_dfDIKeyboard = { }; static DIOBJECTDATAFORMAT rgodfDIMouse[] = { - { &GUID_XAxis, 0, DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 }, - { &GUID_YAxis, 4, DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 }, - { &GUID_ZAxis, 8, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 12, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 }, - { NULL, 13, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 }, - { NULL, 14, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 15, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 } + {&GUID_XAxis, 0, DIDFT_AXIS|DIDFT_ANYINSTANCE, 0}, + {&GUID_YAxis, 4, DIDFT_AXIS|DIDFT_ANYINSTANCE, 0}, + {&GUID_ZAxis, 8, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 12, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0}, + {NULL, 13, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0}, + {NULL, 14, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 15, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0} }; extern const DIDATAFORMAT c_dfDIMouse = { @@ -297,17 +297,17 @@ extern const DIDATAFORMAT c_dfDIMouse = { }; static DIOBJECTDATAFORMAT rgodfDIMouse2[] = { - { &GUID_XAxis, 0, DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 }, - { &GUID_YAxis, 4, DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 }, - { &GUID_ZAxis, 8, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 12, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 }, - { NULL, 13, DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 }, - { NULL, 14, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 15, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 16, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 17, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 18, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 19, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 } + {&GUID_XAxis, 0, DIDFT_AXIS|DIDFT_ANYINSTANCE, 0}, + {&GUID_YAxis, 4, DIDFT_AXIS|DIDFT_ANYINSTANCE, 0}, + {&GUID_ZAxis, 8, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 12, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0}, + {NULL, 13, DIDFT_BUTTON|DIDFT_ANYINSTANCE, 0}, + {NULL, 14, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 15, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 16, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 17, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 18, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 19, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0} }; extern const DIDATAFORMAT c_dfDIMouse2 = { @@ -320,50 +320,50 @@ extern const DIDATAFORMAT c_dfDIMouse2 = { }; static DIOBJECTDATAFORMAT rgodfDIJoystick[] = { - { &GUID_XAxis, 0, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_YAxis, 4, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_ZAxis, 8, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RxAxis, 12, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RyAxis, 16, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RzAxis, 20, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_Slider, 24, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_Slider, 28, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_POV, 32, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 36, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 40, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 44, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 48, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 49, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 50, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 51, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 52, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 53, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 54, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 55, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 56, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 57, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 58, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 59, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 60, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 61, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 62, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 63, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 64, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 65, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 66, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 67, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 68, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 69, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 70, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 71, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 72, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 73, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 74, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 75, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 76, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 77, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 78, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 79, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 } + {&GUID_XAxis, 0, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_YAxis, 4, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_ZAxis, 8, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RxAxis, 12, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RyAxis, 16, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RzAxis, 20, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_Slider, 24, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_Slider, 28, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_POV, 32, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 36, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 40, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 44, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 48, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 49, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 50, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 51, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 52, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 53, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 54, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 55, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 56, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 57, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 58, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 59, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 60, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 61, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 62, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 63, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 64, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 65, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 66, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 67, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 68, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 69, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 70, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 71, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 72, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 73, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 74, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 75, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 76, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 77, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 78, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 79, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0} }; extern const DIDATAFORMAT c_dfDIJoystick = { @@ -376,170 +376,170 @@ extern const DIDATAFORMAT c_dfDIJoystick = { }; static DIOBJECTDATAFORMAT rgodfDIJoystick2[] = { - { &GUID_XAxis, 0, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_YAxis, 4, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_ZAxis, 8, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RxAxis, 12, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RyAxis, 16, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_RzAxis, 20, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_Slider, 24, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_Slider, 28, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTPOSITION }, - { &GUID_POV, 32, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 36, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 40, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_POV, 44, DIDFT_POV | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 48, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 49, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 50, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 51, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 52, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 53, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 54, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 55, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 56, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 57, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 58, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 59, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 60, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 61, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 62, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 63, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 64, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 65, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 66, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 67, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 68, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 69, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 70, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 71, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 72, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 73, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 74, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 75, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 76, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 77, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 78, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 79, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 80, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 81, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 82, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 83, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 84, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 85, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 86, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 87, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 88, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 89, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 90, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 91, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 92, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 93, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 94, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 95, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 96, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 97, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 98, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 99, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 100, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 101, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 102, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 103, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 104, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 105, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 106, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 107, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 108, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 109, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 110, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 111, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 112, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 113, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 114, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 115, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 116, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 117, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 118, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 119, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 120, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 121, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 122, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 123, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 124, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 125, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 126, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 127, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 128, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 129, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 130, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 131, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 132, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 133, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 134, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 135, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 136, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 137, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 138, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 139, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 140, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 141, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 142, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 143, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 144, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 145, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 146, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 147, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 148, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 149, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 150, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 151, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 152, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 153, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 154, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 155, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 156, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 157, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 158, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 159, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 160, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 161, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 162, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 163, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 164, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 165, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 166, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 167, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 168, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 169, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 170, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 171, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 172, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 173, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 174, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { NULL, 175, DIDFT_BUTTON | DIDFT_ANYINSTANCE | 0x80000000, 0 }, - { &GUID_XAxis, 176, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_YAxis, 180, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_ZAxis, 184, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_RxAxis, 188, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_RyAxis, 192, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_RzAxis, 196, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_Slider, 24, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_Slider, 28, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTVELOCITY }, - { &GUID_XAxis, 208, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_YAxis, 212, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_ZAxis, 216, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_RxAxis, 220, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_RyAxis, 224, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_RzAxis, 228, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_Slider, 24, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_Slider, 28, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTACCEL }, - { &GUID_XAxis, 240, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_YAxis, 244, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_ZAxis, 248, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_RxAxis, 252, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_RyAxis, 256, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_RzAxis, 260, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_Slider, 24, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE }, - { &GUID_Slider, 28, DIDFT_AXIS | DIDFT_ANYINSTANCE | 0x80000000, DIDOI_ASPECTFORCE } + {&GUID_XAxis, 0, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_YAxis, 4, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_ZAxis, 8, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RxAxis, 12, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RyAxis, 16, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_RzAxis, 20, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_Slider, 24, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_Slider, 28, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTPOSITION}, + {&GUID_POV, 32, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 36, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 40, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_POV, 44, DIDFT_POV|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 48, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 49, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 50, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 51, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 52, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 53, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 54, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 55, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 56, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 57, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 58, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 59, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 60, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 61, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 62, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 63, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 64, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 65, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 66, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 67, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 68, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 69, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 70, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 71, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 72, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 73, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 74, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 75, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 76, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 77, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 78, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 79, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 80, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 81, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 82, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 83, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 84, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 85, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 86, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 87, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 88, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 89, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 90, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 91, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 92, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 93, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 94, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 95, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 96, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 97, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 98, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 99, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 100, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 101, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 102, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 103, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 104, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 105, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 106, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 107, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 108, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 109, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 110, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 111, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 112, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 113, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 114, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 115, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 116, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 117, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 118, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 119, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 120, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 121, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 122, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 123, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 124, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 125, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 126, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 127, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 128, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 129, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 130, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 131, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 132, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 133, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 134, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 135, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 136, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 137, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 138, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 139, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 140, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 141, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 142, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 143, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 144, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 145, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 146, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 147, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 148, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 149, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 150, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 151, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 152, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 153, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 154, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 155, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 156, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 157, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 158, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 159, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 160, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 161, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 162, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 163, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 164, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 165, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 166, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 167, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 168, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 169, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 170, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 171, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 172, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 173, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 174, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {NULL, 175, DIDFT_BUTTON|DIDFT_ANYINSTANCE|0x80000000, 0}, + {&GUID_XAxis, 176, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_YAxis, 180, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_ZAxis, 184, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_RxAxis, 188, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_RyAxis, 192, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_RzAxis, 196, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_Slider, 24, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_Slider, 28, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTVELOCITY}, + {&GUID_XAxis, 208, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_YAxis, 212, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_ZAxis, 216, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_RxAxis, 220, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_RyAxis, 224, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_RzAxis, 228, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_Slider, 24, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_Slider, 28, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTACCEL}, + {&GUID_XAxis, 240, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_YAxis, 244, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_ZAxis, 248, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_RxAxis, 252, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_RyAxis, 256, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_RzAxis, 260, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_Slider, 24, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE}, + {&GUID_Slider, 28, DIDFT_AXIS|DIDFT_ANYINSTANCE|0x80000000, DIDOI_ASPECTFORCE} }; extern const DIDATAFORMAT c_dfDIJoystick2 = { diff --git a/src/editors/ECore/Editor/device.cpp b/src/editors/ECore/Editor/device.cpp index bcdf03d87fd..17215d7c387 100644 --- a/src/editors/ECore/Editor/device.cpp +++ b/src/editors/ECore/Editor/device.cpp @@ -1,429 +1,451 @@ //--------------------------------------------------------------------------- #include "stdafx.h" #pragma hdrstop -#include "gamefont.h" +#include "xrEngine/GameFont.h" #include #include "xrCore/Debug/dxerr.h" #include "ImageManager.h" #include "ui_main.h" #include "render.h" -#include "GameMtlLib.h" -#include "ResourceManager.h" +#include "xrEngine/GameMtlLib.h" +#include "Layers/xrRender/ResourceManager.h" #pragma package(smart_init) -CEditorRenderDevice EDevice; +CEditorRenderDevice EDevice; -extern int rsDVB_Size; -extern int rsDIB_Size; +extern int rsDVB_Size; +extern int rsDIB_Size; -ENGINE_API BOOL g_bRendering = FALSE; +ENGINE_API BOOL g_bRendering = FALSE; //--------------------------------------------------------------------------- CEditorRenderDevice::CEditorRenderDevice() { - psDeviceFlags.assign(rsStatistic|rsFilterLinear|rsFog|rsDrawGrid); -// dynamic buffer size - rsDVB_Size = 2048; - rsDIB_Size = 2048; -// default initialization + psDeviceFlags.assign(rsStatistic|rsFilterLinear|rsFog|rsDrawGrid); + // dynamic buffer size + rsDVB_Size = 2048; + rsDIB_Size = 2048; + // default initialization m_ScreenQuality = 1.f; - dwWidth = dwHeight = 256; - m_RealWidth = m_RealHeight = 256; - m_RenderWidth_2 = m_RenderHeight_2 = 128; - mProject.identity(); + dwWidth = dwHeight = 256; + m_RealWidth = m_RealHeight = 256; + m_RenderWidth_2 = m_RenderHeight_2 = 128; + mProject.identity(); mFullTransform.identity(); - mView.identity (); - m_WireShader = 0; - m_SelectionShader = 0; + mView.identity(); + m_WireShader = 0; + m_SelectionShader = 0; - b_is_Ready = FALSE; - b_is_Active = FALSE; + b_is_Ready = FALSE; + b_is_Active = FALSE; - // Engine flow-control - fTimeDelta = 0; - fTimeGlobal = 0; - dwTimeDelta = 0; - dwTimeGlobal = 0; + // Engine flow-control + fTimeDelta = 0; + fTimeGlobal = 0; + dwTimeDelta = 0; + dwTimeGlobal = 0; - dwFillMode = D3DFILL_SOLID; - dwShadeMode = D3DSHADE_GOURAUD; + dwFillMode = D3DFILL_SOLID; + dwShadeMode = D3DSHADE_GOURAUD; - m_CurrentShader = 0; - pSystemFont = 0; + m_CurrentShader = 0; + pSystemFont = 0; - fASPECT = 1.f; - fFOV = 60.f; + fASPECT = 1.f; + fFOV = 60.f; dwPrecacheFrame = 0; } -CEditorRenderDevice::~CEditorRenderDevice(){ - VERIFY(!b_is_Ready); +CEditorRenderDevice::~CEditorRenderDevice() +{ + VERIFY(!b_is_Ready); } extern void Surface_Init(); -#include "../../Include/xrAPI/xrAPI.h" +#include "Include/xrAPI/xrAPI.h" #include "../../Layers/xrRender/dxRenderFactory.h" + void CEditorRenderDevice::Initialize() { -// m_Camera.Reset(); + // m_Camera.Reset(); - m_DefaultMat.set(1,1,1); - Surface_Init(); + m_DefaultMat.set(1, 1, 1); + Surface_Init(); - // game materials - GMLib.Load (); + // game materials + GMLib.Load(); - // compiler shader + // compiler shader string_path fn; - FS.update_path(fn,_game_data_,"shaders_xrlc.xr"); - if (FS.exist(fn)){ - ShaderXRLC.Load(fn); - }else{ - ELog.DlgMsg(mtInformation,"Can't find file '%s'",fn); + FS.update_path(fn, _game_data_, "shaders_xrlc.xr"); + if (FS.exist(fn)) + { + ShaderXRLC.Load(fn); + } + else + { + ELog.DlgMsg(mtInformation, "Can't find file '%s'", fn); } - RenderFactory = &RenderFactoryImpl; + RenderFactory = &RenderFactoryImpl; - // Startup shaders - Create (); + // Startup shaders + Create(); ::Render->Initialize(); } void CEditorRenderDevice::ShutDown() { - ::Render->ShutDown (); + ::Render->ShutDown(); - ShaderXRLC.Unload (); - GMLib.Unload (); + ShaderXRLC.Unload(); + GMLib.Unload(); - // destroy context - Destroy (); - xr_delete (pSystemFont); + // destroy context + Destroy(); + xr_delete(pSystemFont); - // destroy shaders -// PSLib.xrShutDown (); + // destroy shaders + // PSLib.xrShutDown (); } -void CEditorRenderDevice::InitTimer(){ - Timer_MM_Delta = 0; - { - u32 time_mm = timeGetTime (); - while (timeGetTime()==time_mm); // wait for next tick - u32 time_system = timeGetTime (); - u32 time_local = TimerAsync (); - Timer_MM_Delta = time_system-time_local; - } +void CEditorRenderDevice::InitTimer() +{ + Timer_MM_Delta = 0; + { + u32 time_mm = timeGetTime(); + while (timeGetTime()==time_mm); // wait for next tick + u32 time_system = timeGetTime(); + u32 time_local = TimerAsync(); + Timer_MM_Delta = time_system-time_local; + } } + //--------------------------------------------------------------------------- -void CEditorRenderDevice::RenderNearer(float n){ - mProject._43=m_fNearer-n; +void CEditorRenderDevice::RenderNearer(float n) +{ + mProject._43 = m_fNearer-n; RCache.set_xform_project(mProject); } -void CEditorRenderDevice::ResetNearer(){ - mProject._43=m_fNearer; + +void CEditorRenderDevice::ResetNearer() +{ + mProject._43 = m_fNearer; RCache.set_xform_project(mProject); } + //--------------------------------------------------------------------------- bool CEditorRenderDevice::Create() { - if (b_is_Ready) return false; - Statistic = xr_new(); - ELog.Msg(mtInformation,"Starting RENDER device..."); + if (b_is_Ready) + return false; + Statistic = xr_new(); + ELog.Msg(mtInformation, "Starting RENDER device..."); - HW.CreateDevice (m_hRenderWnd, false); + HW.CreateDevice(m_hRenderWnd, false); - // after creation - dwFrame = 0; + // after creation + dwFrame = 0; - string_path sh; - FS.update_path (sh,_game_data_,"shaders.xr"); + string_path sh; + FS.update_path(sh, _game_data_, "shaders.xr"); - IReader* F = 0; - if (FS.exist(sh)) - F = FS.r_open(0,sh); - Resources = xr_new (); + IReader *F = 0; + if (FS.exist(sh)) + F = FS.r_open(0, sh); + Resources = xr_new(); // if build options - load textures immediately - if (strstr(Core.Params,"-build")||strstr(Core.Params,"-ebuild")) + if (strstr(Core.Params, "-build")||strstr(Core.Params, "-ebuild")) EDevice.Resources->DeferredLoad(FALSE); - _Create (F); - FS.r_close (F); + _Create(F); + FS.r_close(F); - ELog.Msg (mtInformation, "D3D: initialized"); + ELog.Msg(mtInformation, "D3D: initialized"); - return true; + return true; } //--------------------------------------------------------------------------- -void CEditorRenderDevice::Destroy(){ - if (!b_is_Ready) return; +void CEditorRenderDevice::Destroy() +{ + if (!b_is_Ready) + return; - ELog.Msg( mtInformation, "Destroying Direct3D..."); + ELog.Msg(mtInformation, "Destroying Direct3D..."); - HW.Validate (); + HW.Validate(); - // before destroy - _Destroy (FALSE); - xr_delete (Resources); + // before destroy + _Destroy(FALSE); + xr_delete(Resources); - // real destroy - HW.DestroyDevice (); + // real destroy + HW.DestroyDevice(); - ELog.Msg( mtInformation, "D3D: device cleared" ); - xr_delete (Statistic); + ELog.Msg(mtInformation, "D3D: device cleared"); + xr_delete(Statistic); } + //--------------------------------------------------------------------------- void CEditorRenderDevice::_SetupStates() { - HW.Caps.Update(); - for (u32 i=0; iSetSamplerState( i, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD) (&fBias)))); - } - EDevice.SetRS(D3DRS_DITHERENABLE, TRUE ); - EDevice.SetRS(D3DRS_COLORVERTEX, TRUE ); - EDevice.SetRS(D3DRS_STENCILENABLE, FALSE ); - EDevice.SetRS(D3DRS_ZENABLE, TRUE ); - EDevice.SetRS(D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); - EDevice.SetRS(D3DRS_CULLMODE, D3DCULL_CCW ); - EDevice.SetRS(D3DRS_ALPHAFUNC, D3DCMP_GREATER ); - EDevice.SetRS(D3DRS_LOCALVIEWER, TRUE ); - EDevice.SetRS(D3DRS_NORMALIZENORMALS,TRUE ); - - EDevice.SetRS(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - EDevice.SetRS(D3DRS_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL); - EDevice.SetRS(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); - EDevice.SetRS(D3DRS_EMISSIVEMATERIALSOURCE,D3DMCS_COLOR1 ); + HW.Caps.Update(); + for (u32 i = 0; iSetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD)(&fBias)))); + } + EDevice.SetRS(D3DRS_DITHERENABLE, TRUE); + EDevice.SetRS(D3DRS_COLORVERTEX, TRUE); + EDevice.SetRS(D3DRS_STENCILENABLE, FALSE); + EDevice.SetRS(D3DRS_ZENABLE, TRUE); + EDevice.SetRS(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); + EDevice.SetRS(D3DRS_CULLMODE, D3DCULL_CCW); + EDevice.SetRS(D3DRS_ALPHAFUNC, D3DCMP_GREATER); + EDevice.SetRS(D3DRS_LOCALVIEWER, TRUE); + EDevice.SetRS(D3DRS_NORMALIZENORMALS, TRUE); + + EDevice.SetRS(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); + EDevice.SetRS(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL); + EDevice.SetRS(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); + EDevice.SetRS(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); ResetMaterial(); } + //--------------------------------------------------------------------------- -void CEditorRenderDevice::_Create(IReader* F) +void CEditorRenderDevice::_Create(IReader *F) { - b_is_Ready = TRUE; + b_is_Ready = TRUE; - // General Render States - _SetupStates (); - - RCache.OnDeviceCreate (); - Resources->OnDeviceCreate (F); - ::Render->OnDeviceCreate (); + // General Render States + _SetupStates(); - m_WireShader.create ("editor\\wire"); - m_SelectionShader.create ("editor\\selection"); + RCache.OnDeviceCreate(); + Resources->OnDeviceCreate(F); + ::Render->OnDeviceCreate(); - // signal another objects - UI->OnDeviceCreate (); -//. seqDevCreate.Process (rp_DeviceCreate); + m_WireShader.create("editor\\wire"); + m_SelectionShader.create("editor\\selection"); - pSystemFont = xr_new("hud_font_small"); -// pSystemFont = xr_new("hud_font_medium"); + // signal another objects + UI->OnDeviceCreate(); + //. seqDevCreate.Process (rp_DeviceCreate); + + pSystemFont = xr_new("hud_font_small"); + // pSystemFont = xr_new("hud_font_medium"); } -void CEditorRenderDevice::_Destroy(BOOL bKeepTextures) +void CEditorRenderDevice::_Destroy(BOOL bKeepTextures) { - xr_delete (pSystemFont); + xr_delete(pSystemFont); - b_is_Ready = FALSE; - m_CurrentShader = 0; + b_is_Ready = FALSE; + m_CurrentShader = 0; - UI->OnDeviceDestroy (); + UI->OnDeviceDestroy(); - m_WireShader.destroy (); - m_SelectionShader.destroy (); + m_WireShader.destroy(); + m_SelectionShader.destroy(); -//. seqDevDestroy.Process (rp_DeviceDestroy); + //. seqDevDestroy.Process (rp_DeviceDestroy); - ::Render->Models->OnDeviceDestroy (); + ::Render->Models->OnDeviceDestroy(); - Resources->OnDeviceDestroy (bKeepTextures); + Resources->OnDeviceDestroy(bKeepTextures); - RCache.OnDeviceDestroy (); - ::Render->OnDeviceDestroy (); + RCache.OnDeviceDestroy(); + ::Render->OnDeviceDestroy(); } //--------------------------------------------------------------------------- void __fastcall CEditorRenderDevice::Resize(int w, int h) { - m_RealWidth = w; - m_RealHeight = h; - m_RenderArea = w*h; + m_RealWidth = w; + m_RealHeight = h; + m_RenderArea = w*h; - dwWidth = m_RealWidth * m_ScreenQuality; - dwHeight = m_RealHeight * m_ScreenQuality; - m_RenderWidth_2 = dwWidth * 0.5f; - m_RenderHeight_2= dwHeight * 0.5f; + dwWidth = m_RealWidth*m_ScreenQuality; + dwHeight = m_RealHeight*m_ScreenQuality; + m_RenderWidth_2 = dwWidth*0.5f; + m_RenderHeight_2 = dwHeight*0.5f; - fASPECT = (float)dwHeight / (float)dwWidth; - mProject.build_projection( deg2rad(fFOV), fASPECT, m_Camera.m_Znear, m_Camera.m_Zfar ); - m_fNearer = mProject._43; + fASPECT = (float)dwHeight/(float)dwWidth; + mProject.build_projection(deg2rad(fFOV), fASPECT, m_Camera.m_Znear, m_Camera.m_Zfar); + m_fNearer = mProject._43; - Reset (); + Reset(); RCache.set_xform_project(mProject); - RCache.set_xform_world (Fidentity); + RCache.set_xform_world(Fidentity); - UI->RedrawScene (); + UI->RedrawScene(); } -void CEditorRenderDevice::Reset () +void CEditorRenderDevice::Reset() { - u32 tm_start = TimerAsync(); - Resources->reset_begin (); - Memory.mem_compact (); - HW.DevPP.BackBufferWidth= dwWidth; - HW.DevPP.BackBufferHeight= dwHeight; - HW.Reset (m_hRenderWnd); - dwWidth = HW.DevPP.BackBufferWidth; - dwHeight = HW.DevPP.BackBufferHeight; - m_RenderWidth_2 = dwWidth * 0.5f; - m_RenderHeight_2 = dwHeight * 0.5f; -// fWidth_2 = float(dwWidth/2); -// fHeight_2 = float(dwHeight/2); - Resources->reset_end (); - _SetupStates (); - u32 tm_end = TimerAsync(); - Msg ("*** RESET [%d ms]",tm_end-tm_start); + u32 tm_start = TimerAsync(); + Resources->reset_begin(); + Memory.mem_compact(); + HW.DevPP.BackBufferWidth = dwWidth; + HW.DevPP.BackBufferHeight = dwHeight; + HW.Reset(m_hRenderWnd); + dwWidth = HW.DevPP.BackBufferWidth; + dwHeight = HW.DevPP.BackBufferHeight; + m_RenderWidth_2 = dwWidth*0.5f; + m_RenderHeight_2 = dwHeight*0.5f; + // fWidth_2 = float(dwWidth/2); + // fHeight_2 = float(dwHeight/2); + Resources->reset_end(); + _SetupStates(); + u32 tm_end = TimerAsync(); + Msg("*** RESET [%d ms]", tm_end-tm_start); } -BOOL CEditorRenderDevice::Begin () +BOOL CEditorRenderDevice::Begin() { - VERIFY(b_is_Ready); - HW.Validate (); - HRESULT _hr = HW.pDevice->TestCooperativeLevel(); + VERIFY(b_is_Ready); + HW.Validate(); + HRESULT _hr = HW.pDevice->TestCooperativeLevel(); if (FAILED(_hr)) - { - // If the device was lost, do not render until we get it back - if (D3DERR_DEVICELOST==_hr) { - Sleep (33); - return FALSE; - } - - // Check if the device is ready to be reset - if (D3DERR_DEVICENOTRESET==_hr) - { - Reset (); - } - } - - VERIFY (FALSE==g_bRendering); - CHK_DX (HW.pDevice->BeginScene()); - CHK_DX(HW.pDevice->Clear(0,0, - D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET| - (HW.Caps.bStencil?D3DCLEAR_STENCIL:0), - EPrefs->scene_clear_color,1,0 - )); - RCache.OnFrameBegin (); - g_bRendering = TRUE; - return TRUE; + { + // If the device was lost, do not render until we get it back + if (D3DERR_DEVICELOST==_hr) + { + Sleep(33); + return FALSE; + } + + // Check if the device is ready to be reset + if (D3DERR_DEVICENOTRESET==_hr) + { + Reset(); + } + } + + VERIFY(FALSE==g_bRendering); + CHK_DX(HW.pDevice->BeginScene()); + CHK_DX(HW.pDevice->Clear(0, 0, + D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET| + (HW.Caps.bStencil ? D3DCLEAR_STENCIL : 0), + EPrefs->scene_clear_color, 1, 0 + )); + RCache.OnFrameBegin(); + g_bRendering = TRUE; + return TRUE; } //--------------------------------------------------------------------------- void CEditorRenderDevice::End() { - VERIFY(HW.pDevice); - VERIFY(b_is_Ready); + VERIFY(HW.pDevice); + VERIFY(b_is_Ready); + + seqRender.Process(rp_Render); - seqRender.Process (rp_Render); - - Statistic->Show(pSystemFont); - EDevice.SetRS (D3DRS_FILLMODE,D3DFILL_SOLID); - pSystemFont->OnRender(); - EDevice.SetRS (D3DRS_FILLMODE,EDevice.dwFillMode); + Statistic->Show(pSystemFont); + EDevice.SetRS(D3DRS_FILLMODE, D3DFILL_SOLID); + pSystemFont->OnRender(); + EDevice.SetRS(D3DRS_FILLMODE, EDevice.dwFillMode); - g_bRendering = FALSE; + g_bRendering = FALSE; - // end scene - RCache.OnFrameEnd(); + // end scene + RCache.OnFrameEnd(); CHK_DX(HW.pDevice->EndScene()); - CHK_DX(HW.pDevice->Present( NULL, NULL, NULL, NULL )); + CHK_DX(HW.pDevice->Present(NULL, NULL, NULL, NULL)); } void CEditorRenderDevice::UpdateView() { -// set camera matrix - m_Camera.GetView(mView); + // set camera matrix + m_Camera.GetView(mView); RCache.set_xform_view(mView); - mFullTransform.mul(mProject,mView); + mFullTransform.mul(mProject, mView); -// frustum culling sets - ::Render->ViewBase.CreateFromMatrix(mFullTransform,FRUSTUM_P_ALL); + // frustum culling sets + ::Render->ViewBase.CreateFromMatrix(mFullTransform, FRUSTUM_P_ALL); } void CEditorRenderDevice::FrameMove() { - dwFrame++; + dwFrame++; - // Timer - float fPreviousFrameTime = Timer.GetElapsed_sec(); Timer.Start(); // previous frame - fTimeDelta = 0.1f * fTimeDelta + 0.9f*fPreviousFrameTime; // smooth random system activity - worst case ~7% error - if (fTimeDelta>.1f) fTimeDelta=.1f; // limit to 15fps minimum + // Timer + float fPreviousFrameTime = Timer.GetElapsed_sec(); + Timer.Start(); // previous frame + fTimeDelta = 0.1f*fTimeDelta+0.9f*fPreviousFrameTime; // smooth random system activity - worst case ~7% error + if (fTimeDelta>.1f) + fTimeDelta = .1f; // limit to 15fps minimum - fTimeGlobal = TimerGlobal.GetElapsed_sec(); //float(qTime)*CPU::cycles2seconds; - dwTimeGlobal = TimerGlobal.GetElapsed_ms (); //u32((qTime*u64(1000))/CPU::cycles_per_second); - dwTimeDelta = iFloor(fTimeDelta*1000.f+0.5f); - dwTimeContinual = dwTimeGlobal; + fTimeGlobal = TimerGlobal.GetElapsed_sec(); //float(qTime)*CPU::cycles2seconds; + dwTimeGlobal = TimerGlobal.GetElapsed_ms(); //u32((qTime*u64(1000))/CPU::cycles_per_second); + dwTimeDelta = iFloor(fTimeDelta*1000.f+0.5f); + dwTimeContinual = dwTimeGlobal; m_Camera.Update(fTimeDelta); // process objects - seqFrame.Process(rp_Frame); + seqFrame.Process(rp_Frame); } void CEditorRenderDevice::DP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 vBase, u32 pc) { - ref_shader S = m_CurrentShader?m_CurrentShader:m_WireShader; - u32 dwRequired = S->E[0]->passes.size(); - RCache.set_Geometry (geom); - for (u32 dwPass = 0; dwPassE[0]->passes.size(); + RCache.set_Geometry(geom); + for (u32 dwPass = 0; dwPassE[0]->passes.size(); - RCache.set_Geometry (geom); - for (u32 dwPass = 0; dwPassE[0]->passes.size(); + RCache.set_Geometry(geom); + for (u32 dwPass = 0; dwPassSetStatus("Reload textures..."); - Resources->ED_UpdateTextures(0); - UI->SetStatus(""); + UI->SetStatus("Reload textures..."); + Resources->ED_UpdateTextures(0); + UI->SetStatus(""); } void CEditorRenderDevice::UnloadTextures() { #ifndef _EDITOR Resources->DeferredUnload(); -#endif +#endif } -void CEditorRenderDevice::Reset(IReader* F, BOOL bKeepTextures) +void CEditorRenderDevice::Reset(IReader *F, BOOL bKeepTextures) { - CTimer tm; + CTimer tm; tm.Start(); - _Destroy (bKeepTextures); - _Create (F); - Msg ("*** RESET [%d ms]",tm.GetElapsed_ms()); + _Destroy(bKeepTextures); + _Create(F); + Msg("*** RESET [%d ms]", tm.GetElapsed_ms()); } void CEditorRenderDevice::time_factor(float v) { - Timer.time_factor(v); - TimerGlobal.time_factor(v); + Timer.time_factor(v); + TimerGlobal.time_factor(v); } diff --git a/src/editors/ECore/Editor/device.h b/src/editors/ECore/Editor/device.h index 4bd932469f6..6543913defb 100644 --- a/src/editors/ECore/Editor/device.h +++ b/src/editors/ECore/Editor/device.h @@ -1,16 +1,16 @@ #ifndef DeviceH #define DeviceH -#include "../../../xrengine/device.h" -#include "ui_camera.h" -#include "../../../Layers/xrRender/hwcaps.h" -#include "../../../Layers/xrRender/hw.h" -#include "../../../xrEngine/pure.h" -#include "../../../xrCore/ftimer.h" -#include "estats.h" -#include "../../../xrEngine/shader_xrlc.h" -#include "../../../Layers/xrRender/shader.h" -#include "../../../Layers/xrRender/R_Backend.h" +#include "xrEngine/device.h" +#include "UI_Camera.h" +#include "Layers/xrRender/HWCaps.h" +#include "Layers/xrRender/HW.h" +#include "xrEngine/pure.h" +#include "xrCore/FTimer.h" +#include "EStats.h" +#include "utils/Shader_xrLC.h" +#include "Layers/xrRender/Shader.h" +#include "Layers/xrRender/R_Backend.h" //--------------------------------------------------------------------------- @@ -21,42 +21,44 @@ class CResourceManager; //------------------------------------------------------------------------------ class ECORE_API CEditorRenderDevice : - public CRenderDeviceBase + +public +CRenderDeviceBase { - friend class CUI_Camera; - friend class TUI; + friend class CUI_Camera; + friend class TUI; - float m_fNearer; + float m_fNearer; - //u32 Timer_MM_Delta; - //CTimer Timer; - //CTimer TimerGlobal; + //u32 Timer_MM_Delta; + //CTimer Timer; + //CTimer TimerGlobal; - ref_shader m_CurrentShader; + ref_shader m_CurrentShader; - void _SetupStates(); - void _Create (IReader* F); - void _Destroy (BOOL bKeepTextures); - void Reset (); -public: - ref_shader m_WireShader; - ref_shader m_SelectionShader; + void _SetupStates(); + void _Create (IReader* F); + void _Destroy (BOOL bKeepTextures); + void Reset (); + public: + ref_shader m_WireShader; + ref_shader m_SelectionShader; - Fmaterial m_DefaultMat; -public: - // u32 dwWidth, dwHeight; - u32 m_RenderWidth_2, m_RenderHeight_2; - u32 m_RealWidth, m_RealHeight; - float m_RenderArea; - float m_ScreenQuality; - - u32 dwFillMode; - u32 dwShadeMode; -public: -// HWND m_hWnd; - HWND m_hRenderWnd; + Fmaterial m_DefaultMat; + public: + // u32 dwWidth, dwHeight; + u32 m_RenderWidth_2, m_RenderHeight_2; + u32 m_RealWidth, m_RealHeight; + float m_RenderArea; + float m_ScreenQuality; - IC void SetHandle(HWND main_hwnd, HWND render_hwnd){m_hWnd=main_hwnd; m_hRenderWnd=render_hwnd;} + u32 dwFillMode; + u32 dwShadeMode; + public: + // HWND m_hWnd; + HWND m_hRenderWnd; + + IC void SetHandle(HWND main_hwnd, HWND render_hwnd){m_hWnd=main_hwnd; m_hRenderWnd=render_hwnd;} // u32 dwFrame; // u32 dwPrecacheFrame; @@ -64,140 +66,139 @@ class ECORE_API CEditorRenderDevice : // BOOL b_is_Ready; // BOOL b_is_Active; - // Engine flow-control - //float fTimeDelta; - //float fTimeGlobal; - //u32 dwTimeDelta; - //u32 dwTimeGlobal; - // u32 dwTimeContinual; +// Engine flow-control +//float fTimeDelta; +//float fTimeGlobal; +//u32 dwTimeDelta; +//u32 dwTimeGlobal; +// u32 dwTimeContinual; - // camera - CUI_Camera m_Camera; +// camera +CUI_Camera m_Camera; - // Fvector vCameraPosition; - // Fvector vCameraDirection; - // Fvector vCameraTop; - // Fvector vCameraRight; - // - //Fmatrix mView; - //Fmatrix mProjection; - //Fmatrix mFullTransform; +// Fvector vCameraPosition; +// Fvector vCameraDirection; +// Fvector vCameraTop; +// Fvector vCameraRight; +// +//Fmatrix mView; +//Fmatrix mProjection; +//Fmatrix mFullTransform; - // float fFOV; - //float fASPECT; +// float fFOV; +//float fASPECT; - // Dependent classes - CResourceManager* Resources; - CEStats* Statistic; +// Dependent classes +CResourceManager* Resources; +CEStats* Statistic; - CGameFont* pSystemFont; +CGameFont* pSystemFont; - // registrators +// registrators // CRegistrator seqDevDestroy; // CRegistrator seqDevCreate; - //CRegistrator seqFrame; - //CRegistrator seqRender; - //CRegistrator seqAppStart; - //CRegistrator seqAppEnd; - //CRegistrator seqAppActivate; - //CRegistrator seqAppDeactivate; +//CRegistrator seqFrame; +//CRegistrator seqRender; +//CRegistrator seqAppStart; +//CRegistrator seqAppEnd; +//CRegistrator seqAppActivate; +//CRegistrator seqAppDeactivate; public: - CEditorRenderDevice (); - virtual ~CEditorRenderDevice (); - - void Pause (BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason){}; - BOOL Paused (){return FALSE;}; - void time_factor (float); - bool Create (); - void Destroy (); - void Resize (int w, int h); - void ReloadTextures (); - void UnloadTextures (); - - void RenderNearer (float f_Near); - void ResetNearer (); - - BOOL Begin (); - void End (); - - void Initialize (void); - void ShutDown (void); - void Reset (IReader* F, BOOL bKeepTextures); - - IC CTimer* GetTimerGlobal (){return &TimerGlobal;} - - IC float GetRenderArea (){return m_RenderArea;} - // Sprite rendering - IC float _x2real (float x) - { return (x+1)*m_RenderWidth_2; } - IC float _y2real (float y) - { return (y+1)*m_RenderHeight_2;} - - // draw - void SetShader (ref_shader sh){m_CurrentShader = sh;} - void DP (D3DPRIMITIVETYPE pt, ref_geom geom, u32 startV, u32 pc); - void DIP (D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV, u32 countV, u32 startI, u32 PC); - - IC void SetRS (D3DRENDERSTATETYPE p1, u32 p2) - { VERIFY(b_is_Ready); CHK_DX(HW.pDevice->SetRenderState(p1,p2)); } - IC void SetSS (u32 sampler, D3DSAMPLERSTATETYPE type, u32 value) - { VERIFY(b_is_Ready); CHK_DX(HW.pDevice->SetSamplerState(sampler,type,value)); } - - // light&material - IC void LightEnable (u32 dwLightIndex, BOOL bEnable) - { CHK_DX(HW.pDevice->LightEnable(dwLightIndex, bEnable));} - IC void SetLight (u32 dwLightIndex, Flight& lpLight) - { CHK_DX(HW.pDevice->SetLight(dwLightIndex, (D3DLIGHT9*)&lpLight));} - IC void SetMaterial (Fmaterial& mat) - { CHK_DX(HW.pDevice->SetMaterial((D3DMATERIAL9*)&mat));} - IC void ResetMaterial () - { CHK_DX(HW.pDevice->SetMaterial((D3DMATERIAL9*)&m_DefaultMat));} - - // update - void UpdateView (); - void FrameMove (); - - bool MakeScreenshot (U32Vec& pixels, u32 width, u32 height); - - void InitTimer (); - // Mode control - IC u32 TimerAsync (void) - { return TimerGlobal.GetElapsed_ms();} - IC u32 TimerAsync_MMT (void) - { return TimerAsync()+Timer_MM_Delta; } +CEditorRenderDevice (); +virtual ~CEditorRenderDevice (); + +void Pause (BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason){}; +BOOL Paused (){return FALSE;}; +void time_factor (float); +bool Create (); +void Destroy (); +void Resize (int w, int h); +void ReloadTextures (); +void UnloadTextures (); + +void RenderNearer (float f_Near); +void ResetNearer (); + +BOOL Begin (); +void End (); + +void Initialize (void); +void ShutDown (void); +void Reset (IReader* F, BOOL bKeepTextures); + +IC CTimer* GetTimerGlobal (){return &TimerGlobal;} + +IC float GetRenderArea (){return m_RenderArea;} +// Sprite rendering +IC float _x2real (float x) +{ return (x+1)*m_RenderWidth_2; } +IC float _y2real (float y) +{ return (y+1)*m_RenderHeight_2;} + +// draw +void SetShader (ref_shader sh){m_CurrentShader = sh;} +void DP (D3DPRIMITIVETYPE pt, ref_geom geom, u32 startV, u32 pc); +void DIP (D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV, u32 countV, u32 startI, u32 PC); + +IC void SetRS (D3DRENDERSTATETYPE p1, u32 p2) +{ VERIFY(b_is_Ready); CHK_DX(HW.pDevice->SetRenderState(p1,p2)); } +IC void SetSS (u32 sampler, D3DSAMPLERSTATETYPE type, u32 value) +{ VERIFY(b_is_Ready); CHK_DX(HW.pDevice->SetSamplerState(sampler,type,value)); } + +// light&material +IC void LightEnable (u32 dwLightIndex, BOOL bEnable) +{ CHK_DX(HW.pDevice->LightEnable(dwLightIndex, bEnable));} +IC void SetLight (u32 dwLightIndex, Flight& lpLight) +{ CHK_DX(HW.pDevice->SetLight(dwLightIndex, (D3DLIGHT9*)&lpLight));} +IC void SetMaterial (Fmaterial& mat) +{ CHK_DX(HW.pDevice->SetMaterial((D3DMATERIAL9*)&mat));} +IC void ResetMaterial () +{ CHK_DX(HW.pDevice->SetMaterial((D3DMATERIAL9*)&m_DefaultMat));} + +// update +void UpdateView (); +void FrameMove (); + +bool MakeScreenshot (U32Vec& pixels, u32 width, u32 height); + +void InitTimer (); +// Mode control +IC u32 TimerAsync (void) +{ return TimerGlobal.GetElapsed_ms();} +IC u32 TimerAsync_MMT (void) +{ return TimerAsync()+Timer_MM_Delta; } public: - Shader_xrLC_LIB ShaderXRLC; +Shader_xrLC_LIB ShaderXRLC; private: - virtual CStatsPhysics* _BCL StatPhysics () { return Statistic; } - virtual void _BCL AddSeqFrame ( pureFrame* f, bool mt ) { seqFrame.Add (f,REG_PRIORITY_LOW); } - virtual void _BCL RemoveSeqFrame ( pureFrame* f ) { seqFrame.Remove ( f );} +virtual CStatsPhysics* _BCL StatPhysics () { return Statistic; } +virtual void _BCL AddSeqFrame ( pureFrame* f, bool mt ) { seqFrame.Add (f,REG_PRIORITY_LOW); } +virtual void _BCL RemoveSeqFrame ( pureFrame* f ) { seqFrame.Remove ( f );} }; extern ECORE_API CEditorRenderDevice EDevice; // video -enum { - rsFilterLinear = (1ul<<20ul), - rsEdgedFaces = (1ul<<21ul), - rsRenderTextures = (1ul<<22ul), - rsLighting = (1ul<<23ul), - rsFog = (1ul<<24ul), - rsRenderRealTime = (1ul<<25ul), - rsDrawGrid = (1ul<<26ul), - rsDrawSafeRect = (1ul<<27ul), - rsMuteSounds = (1ul<<28ul), - rsEnvironment = (1ul<<29ul), +enum +{ + rsFilterLinear = (1ul<<20ul), + rsEdgedFaces = (1ul<<21ul), + rsRenderTextures = (1ul<<22ul), + rsLighting = (1ul<<23ul), + rsFog = (1ul<<24ul), + rsRenderRealTime = (1ul<<25ul), + rsDrawGrid = (1ul<<26ul), + rsDrawSafeRect = (1ul<<27ul), + rsMuteSounds = (1ul<<28ul), + rsEnvironment = (1ul<<29ul), }; #define DEFAULT_CLEARCOLOR 0x00555555 -#define REQ_CREATE() if (!EDevice.bReady) return; -#define REQ_DESTROY() if (EDevice.bReady) return; +#define REQ_CREATE() if (!EDevice.bReady) return; +#define REQ_DESTROY() if (EDevice.bReady) return; -#include "../xrCPU_Pipe/xrCPU_Pipe.h" -ENGINE_API extern xrDispatchTable PSGP; - -#include "../../Layers/xrRender/R_Backend_Runtime.h" +#include "Layers/xrRender/R_Backend_Runtime.h" #endif + diff --git a/src/editors/ECore/Editor/du_box.cpp b/src/editors/ECore/Editor/du_box.cpp index 9b146a94360..8bb0a05f855 100644 --- a/src/editors/ECore/Editor/du_box.cpp +++ b/src/editors/ECore/Editor/du_box.cpp @@ -6,43 +6,43 @@ //--------------------------------------------------------------------------- //#pragma package(smart_init) Fvector du_box_vertices2[DU_BOX_NUMVERTEX2] = { - {-0.5f, -0.5f, -0.5f}, {-0.5f, +0.5f, -0.5f}, {+0.5f, +0.5f, -0.5f}, - {+0.5f, +0.5f, -0.5f}, {+0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, -0.5f}, - {+0.5f, -0.5f, -0.5f}, {+0.5f, +0.5f, -0.5f}, {+0.5f, +0.5f, +0.5f}, - {+0.5f, +0.5f, +0.5f}, {+0.5f, -0.5f, +0.5f}, {+0.5f, -0.5f, -0.5f}, - {+0.5f, +0.5f, +0.5f}, {-0.5f, +0.5f, +0.5f}, {-0.5f, -0.5f, +0.5f}, - {+0.5f, +0.5f, +0.5f}, {-0.5f, -0.5f, +0.5f}, {+0.5f, -0.5f, +0.5f}, - {-0.5f, +0.5f, +0.5f}, {-0.5f, +0.5f, -0.5f}, {-0.5f, -0.5f, +0.5f}, - {-0.5f, +0.5f, -0.5f}, {-0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, +0.5f}, - {+0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, +0.5f}, {-0.5f, -0.5f, -0.5f}, - {+0.5f, -0.5f, -0.5f}, {+0.5f, -0.5f, +0.5f}, {-0.5f, -0.5f, +0.5f}, - {-0.5f, +0.5f, -0.5f}, {-0.5f, +0.5f, +0.5f}, {+0.5f, +0.5f, +0.5f}, - {-0.5f, +0.5f, -0.5f}, {+0.5f, +0.5f, +0.5f}, {+0.5f, +0.5f, -0.5f} + {-0.5f, -0.5f, -0.5f},{-0.5f, +0.5f, -0.5f},{+0.5f, +0.5f, -0.5f}, + {+0.5f, +0.5f, -0.5f},{+0.5f, -0.5f, -0.5f},{-0.5f, -0.5f, -0.5f}, + {+0.5f, -0.5f, -0.5f},{+0.5f, +0.5f, -0.5f},{+0.5f, +0.5f, +0.5f}, + {+0.5f, +0.5f, +0.5f},{+0.5f, -0.5f, +0.5f},{+0.5f, -0.5f, -0.5f}, + {+0.5f, +0.5f, +0.5f},{-0.5f, +0.5f, +0.5f},{-0.5f, -0.5f, +0.5f}, + {+0.5f, +0.5f, +0.5f},{-0.5f, -0.5f, +0.5f},{+0.5f, -0.5f, +0.5f}, + {-0.5f, +0.5f, +0.5f},{-0.5f, +0.5f, -0.5f},{-0.5f, -0.5f, +0.5f}, + {-0.5f, +0.5f, -0.5f},{-0.5f, -0.5f, -0.5f},{-0.5f, -0.5f, +0.5f}, + {+0.5f, -0.5f, -0.5f},{-0.5f, -0.5f, +0.5f},{-0.5f, -0.5f, -0.5f}, + {+0.5f, -0.5f, -0.5f},{+0.5f, -0.5f, +0.5f},{-0.5f, -0.5f, +0.5f}, + {-0.5f, +0.5f, -0.5f},{-0.5f, +0.5f, +0.5f},{+0.5f, +0.5f, +0.5f}, + {-0.5f, +0.5f, -0.5f},{+0.5f, +0.5f, +0.5f},{+0.5f, +0.5f, -0.5f} }; Fvector du_box_vertices[DU_BOX_NUMVERTEX] = { - {-0.5f, -0.5f, -0.5f}, - {-0.5f, +0.5f, -0.5f}, - {+0.5f, +0.5f, -0.5f}, - {+0.5f, -0.5f, -0.5f}, - {-0.5f, +0.5f, +0.5f}, - {-0.5f, -0.5f, +0.5f}, - {+0.5f, +0.5f, +0.5f}, - {+0.5f, -0.5f, +0.5f}, + {-0.5f, -0.5f, -0.5f}, + {-0.5f, +0.5f, -0.5f}, + {+0.5f, +0.5f, -0.5f}, + {+0.5f, -0.5f, -0.5f}, + {-0.5f, +0.5f, +0.5f}, + {-0.5f, -0.5f, +0.5f}, + {+0.5f, +0.5f, +0.5f}, + {+0.5f, -0.5f, +0.5f}, }; WORD du_box_faces[DU_BOX_NUMFACES*3] = { - 0, 1, 2, 2, 3, 0, - 3, 2, 6, 6, 7, 3, - 6, 4, 5, 6, 5, 7, - 4, 1, 5, 1, 0, 5, - 3, 5, 0, 3, 7, 5, // bottom - 1, 4, 6, 1, 6, 2 // top + 0, 1, 2, 2, 3, 0, + 3, 2, 6, 6, 7, 3, + 6, 4, 5, 6, 5, 7, + 4, 1, 5, 1, 0, 5, + 3, 5, 0, 3, 7, 5, // bottom + 1, 4, 6, 1, 6, 2 // top }; WORD du_box_lines[DU_BOX_NUMLINES*2] = { - 0, 1, 1, 2, 2, 3, 3, 0, - 4, 5, 5, 7, 6, 7, 6, 4, - 0, 5, 1, 4, 2, 6, 3, 7 + 0, 1, 1, 2, 2, 3, 3, 0, + 4, 5, 5, 7, 6, 7, 6, 4, + 0, 5, 1, 4, 2, 6, 3, 7 }; diff --git a/src/editors/ECore/Editor/du_box.h b/src/editors/ECore/Editor/du_box.h index b4cc4f21591..4f99ffb4c1b 100644 --- a/src/editors/ECore/Editor/du_box.h +++ b/src/editors/ECore/Editor/du_box.h @@ -14,3 +14,4 @@ extern ECORE_API WORD du_box_lines[]; extern ECORE_API Fvector du_box_vertices2[]; #endif + diff --git a/src/editors/ECore/Editor/du_cone.cpp b/src/editors/ECore/Editor/du_cone.cpp index cc25a8262c2..0adadc01f1b 100644 --- a/src/editors/ECore/Editor/du_cone.cpp +++ b/src/editors/ECore/Editor/du_cone.cpp @@ -5,45 +5,45 @@ #include "du_cone.h" //--------------------------------------------------------------------------- //#pragma package(smart_init) -Fvector du_cone_vertices[DU_CONE_NUMVERTEX]= +Fvector du_cone_vertices[DU_CONE_NUMVERTEX] = { - {0.0000f, 0.0000f, 0.0000f}, - {0.5000f, 0.0000f, 1.0000f}, - {0.4619f, 0.1913f, 1.0000f}, - {0.3536f, 0.3536f, 1.0000f}, - {0.1913f, 0.4619f, 1.0000f}, - {-0.0000f, 0.5000f, 1.0000f}, - {-0.1913f, 0.4619f, 1.0000f}, - {-0.3536f, 0.3536f, 1.0000f}, - {-0.4619f, 0.1913f, 1.0000f}, - {-0.5000f, -0.0000f, 1.0000f}, - {-0.4619f, -0.1913f, 1.0000f}, - {-0.3536f, -0.3536f, 1.0000f}, - {-0.1913f, -0.4619f, 1.0000f}, - {0.0000f, -0.5000f, 1.0000f}, - {0.1913f, -0.4619f, 1.0000f}, - {0.3536f, -0.3536f, 1.0000f}, - {0.4619f, -0.1913f, 1.0000f}, - {0.0000f, 0.0000f, 1.0000f} + {0.0000f, 0.0000f, 0.0000f}, + {0.5000f, 0.0000f, 1.0000f}, + {0.4619f, 0.1913f, 1.0000f}, + {0.3536f, 0.3536f, 1.0000f}, + {0.1913f, 0.4619f, 1.0000f}, + {-0.0000f, 0.5000f, 1.0000f}, + {-0.1913f, 0.4619f, 1.0000f}, + {-0.3536f, 0.3536f, 1.0000f}, + {-0.4619f, 0.1913f, 1.0000f}, + {-0.5000f, -0.0000f, 1.0000f}, + {-0.4619f, -0.1913f, 1.0000f}, + {-0.3536f, -0.3536f, 1.0000f}, + {-0.1913f, -0.4619f, 1.0000f}, + {0.0000f, -0.5000f, 1.0000f}, + {0.1913f, -0.4619f, 1.0000f}, + {0.3536f, -0.3536f, 1.0000f}, + {0.4619f, -0.1913f, 1.0000f}, + {0.0000f, 0.0000f, 1.0000f} }; -WORD du_cone_faces[DU_CONE_NUMFACES*3]= +WORD du_cone_faces[DU_CONE_NUMFACES*3] = { - 0, 2, 1, - 0, 3, 2, - 0, 4, 3, - 0, 5, 4, - 0, 6, 5, - 0, 7, 6, - 0, 8, 7, - 0, 9, 8, - 0, 10, 9, + 0, 2, 1, + 0, 3, 2, + 0, 4, 3, + 0, 5, 4, + 0, 6, 5, + 0, 7, 6, + 0, 8, 7, + 0, 9, 8, + 0, 10, 9, 0, 11, 10, 0, 12, 11, 0, 13, 12, 0, 14, 13, 0, 15, 14, 0, 16, 15, - 0, 1, 16, + 0, 1, 16, 17, 1, 2, 17, 2, 3, 17, 3, 4, @@ -62,41 +62,42 @@ WORD du_cone_faces[DU_CONE_NUMFACES*3]= 17,16, 1 }; -WORD du_cone_lines[DU_CONE_NUMLINES*2]= +WORD du_cone_lines[DU_CONE_NUMLINES*2] = { - // tile - 0, 1, -// 0, 2, - 0, 3, -// 0, 4, - 0, 5, -// 0, 6, - 0, 7, -// 0, 8, - 0, 9, -// 0, 10, - 0, 11, -// 0, 12, - 0, 13, -// 0, 14, - 0, 15, -// 0, 16, - - // cape - 1, 2, - 2, 3, - 3, 4, - 4, 5, - 5, 6, - 6, 7, - 7, 8, - 8, 9, - 9, 10, - 10, 11, - 11, 12, - 12, 13, - 13, 14, - 14, 15, - 15, 16, - 16, 1, + // tile + 0, 1, + // 0, 2, + 0, 3, + // 0, 4, + 0, 5, + // 0, 6, + 0, 7, + // 0, 8, + 0, 9, + // 0, 10, + 0, 11, + // 0, 12, + 0, 13, + // 0, 14, + 0, 15, + // 0, 16, + + // cape + 1, 2, + 2, 3, + 3, 4, + 4, 5, + 5, 6, + 6, 7, + 7, 8, + 8, 9, + 9, 10, + 10, 11, + 11, 12, + 12, 13, + 13, 14, + 14, 15, + 15, 16, + 16, 1, }; + diff --git a/src/editors/ECore/Editor/du_cone.h b/src/editors/ECore/Editor/du_cone.h index 705024211f8..d0e87765928 100644 --- a/src/editors/ECore/Editor/du_cone.h +++ b/src/editors/ECore/Editor/du_cone.h @@ -11,3 +11,4 @@ extern ECORE_API Fvector du_cone_vertices[]; extern ECORE_API WORD du_cone_faces[]; extern ECORE_API WORD du_cone_lines[]; #endif + diff --git a/src/editors/ECore/Editor/du_cylinder.cpp b/src/editors/ECore/Editor/du_cylinder.cpp index ab2a9012c26..be2703a3cc0 100644 --- a/src/editors/ECore/Editor/du_cylinder.cpp +++ b/src/editors/ECore/Editor/du_cylinder.cpp @@ -5,125 +5,125 @@ #include "du_cylinder.h" //--------------------------------------------------------------------------- //#pragma package(smart_init) -Fvector du_cylinder_vertices[DU_CYLINDER_NUMVERTEX]={ - {0.5000f, 0.0000f, 0.5000f }, // 0 - {0.5000f, -0.0000f, -0.5000f}, // 1 - {0.4330f, -0.2500f, -0.5000f}, // 2 - {0.4330f, -0.2500f, 0.5000f }, // 3 - {0.2500f, -0.4330f, -0.5000f}, // 4 - {0.2500f, -0.4330f, 0.5000f }, // 5 - {0.0000f, -0.5000f, -0.5000f}, // 6 - {-0.0000f, -0.5000f, 0.5000f }, // 7 - {-0.2500f, -0.4330f, -0.5000f}, // 8 - {-0.2500f, -0.4330f, 0.5000f }, // 9 - {-0.4330f, -0.2500f, -0.5000f}, // 10 - {-0.4330f, -0.2500f, 0.5000f }, // 11 - {-0.5000f, -0.0000f, -0.5000f}, // 12 - {-0.5000f, 0.0000f, 0.5000f }, // 13 - {-0.4330f, 0.2500f, -0.5000f}, // 14 - {-0.4330f, 0.2500f, 0.5000f }, // 15 - {-0.2500f, 0.4330f, -0.5000f}, // 16 - {-0.2500f, 0.4330f, 0.5000f }, // 17 - {0.0000f, 0.5000f, -0.5000f}, // 18 - {-0.0000f, 0.5000f, 0.5000f }, // 19 - {0.2500f, 0.4330f, -0.5000f}, // 20 - {0.2500f, 0.4330f, 0.5000f }, // 21 - {0.4330f, 0.2500f, -0.5000f}, // 22 - {0.4330f, 0.2500f, 0.5000f }, // 23 - {-0.0000f, 0.0000f, 0.5000f }, // 24 - {0.0000f, -0.0000f, -0.5000f}, // 25 +Fvector du_cylinder_vertices[DU_CYLINDER_NUMVERTEX] = { + {0.5000f, 0.0000f, 0.5000f}, // 0 + {0.5000f, -0.0000f, -0.5000f}, // 1 + {0.4330f, -0.2500f, -0.5000f}, // 2 + {0.4330f, -0.2500f, 0.5000f}, // 3 + {0.2500f, -0.4330f, -0.5000f}, // 4 + {0.2500f, -0.4330f, 0.5000f}, // 5 + {0.0000f, -0.5000f, -0.5000f}, // 6 + {-0.0000f, -0.5000f, 0.5000f}, // 7 + {-0.2500f, -0.4330f, -0.5000f}, // 8 + {-0.2500f, -0.4330f, 0.5000f}, // 9 + {-0.4330f, -0.2500f, -0.5000f}, // 10 + {-0.4330f, -0.2500f, 0.5000f}, // 11 + {-0.5000f, -0.0000f, -0.5000f}, // 12 + {-0.5000f, 0.0000f, 0.5000f}, // 13 + {-0.4330f, 0.2500f, -0.5000f}, // 14 + {-0.4330f, 0.2500f, 0.5000f}, // 15 + {-0.2500f, 0.4330f, -0.5000f}, // 16 + {-0.2500f, 0.4330f, 0.5000f}, // 17 + {0.0000f, 0.5000f, -0.5000f}, // 18 + {-0.0000f, 0.5000f, 0.5000f}, // 19 + {0.2500f, 0.4330f, -0.5000f}, // 20 + {0.2500f, 0.4330f, 0.5000f}, // 21 + {0.4330f, 0.2500f, -0.5000f}, // 22 + {0.4330f, 0.2500f, 0.5000f}, // 23 + {-0.0000f, 0.0000f, 0.5000f}, // 24 + {0.0000f, -0.0000f, -0.5000f}, // 25 }; -u16 du_cylinder_faces[DU_CYLINDER_NUMFACES*3]={ - 0, 2, 1, - 3, 2, 0, - 3, 4, 2, - 5, 4, 3, - 5, 6, 4, - 7, 6, 5, - 8, 6, 9, - 9, 6, 7, - 10, 8, 11, - 11, 8, 9, - 12, 10, 13, - 13, 10, 11, - 14, 12, 15, - 12, 13, 15, - 16, 14, 17, - 17, 14, 15, - 18, 16, 19, - 19, 16, 17, - 19, 20, 18, - 21, 20, 19, - 21, 22, 20, - 23, 22, 21, - 23, 1, 22, - 23, 0, 1, - 23, 24, 0, - 21, 24, 23, - 19, 24, 21, - 17, 24, 19, - 15, 24, 17, - 13, 24, 15, - 11, 24, 13, - 9, 24, 11, - 7, 24, 9, - 5, 24, 7, - 3, 24, 5, - 0, 24, 3, - 8, 25, 6, - 10, 25, 8, - 12, 25, 10, - 14, 25, 12, - 16, 25, 14, - 18, 25, 16, - 20, 25, 18, - 22, 25, 20, - 1, 25, 22, - 2, 25, 1, - 4, 25, 2, - 6, 25, 4, +u16 du_cylinder_faces[DU_CYLINDER_NUMFACES*3] = { + 0, 2, 1, + 3, 2, 0, + 3, 4, 2, + 5, 4, 3, + 5, 6, 4, + 7, 6, 5, + 8, 6, 9, + 9, 6, 7, + 10, 8, 11, + 11, 8, 9, + 12, 10, 13, + 13, 10, 11, + 14, 12, 15, + 12, 13, 15, + 16, 14, 17, + 17, 14, 15, + 18, 16, 19, + 19, 16, 17, + 19, 20, 18, + 21, 20, 19, + 21, 22, 20, + 23, 22, 21, + 23, 1, 22, + 23, 0, 1, + 23, 24, 0, + 21, 24, 23, + 19, 24, 21, + 17, 24, 19, + 15, 24, 17, + 13, 24, 15, + 11, 24, 13, + 9, 24, 11, + 7, 24, 9, + 5, 24, 7, + 3, 24, 5, + 0, 24, 3, + 8, 25, 6, + 10, 25, 8, + 12, 25, 10, + 14, 25, 12, + 16, 25, 14, + 18, 25, 16, + 20, 25, 18, + 22, 25, 20, + 1, 25, 22, + 2, 25, 1, + 4, 25, 2, + 6, 25, 4, }; -u16 du_cylinder_lines[DU_CYLINDER_NUMLINES*2]={ -// tile - 0, 1, -// 2, 3, - 4, 5, -// 6, 7, - 8, 9, -// 10, 11, - 12, 13, -// 14, 15, - 16, 17, -// 18, 19, - 20, 21, -// 22, 23, -// cape 0 - 1, 2, - 2, 4, - 4, 6, - 6, 8, - 8, 10, - 10, 12, - 12, 14, - 14, 16, - 16, 18, - 18, 20, - 20, 22, - 22, 1, -// cape1 - 0, 3, - 3, 5, - 5, 7, - 7, 9, - 9, 11, - 11, 13, - 13, 15, - 15, 17, - 17, 19, - 19, 21, - 21, 23, - 23, 0, +u16 du_cylinder_lines[DU_CYLINDER_NUMLINES*2] = { + // tile + 0, 1, + // 2, 3, + 4, 5, + // 6, 7, + 8, 9, + // 10, 11, + 12, 13, + // 14, 15, + 16, 17, + // 18, 19, + 20, 21, + // 22, 23, + // cape 0 + 1, 2, + 2, 4, + 4, 6, + 6, 8, + 8, 10, + 10, 12, + 12, 14, + 14, 16, + 16, 18, + 18, 20, + 20, 22, + 22, 1, + // cape1 + 0, 3, + 3, 5, + 5, 7, + 7, 9, + 9, 11, + 11, 13, + 13, 15, + 15, 17, + 17, 19, + 19, 21, + 21, 23, + 23, 0, }; diff --git a/src/editors/ECore/Editor/du_cylinder.h b/src/editors/ECore/Editor/du_cylinder.h index 5ef010b6b2d..dce40eae8cd 100644 --- a/src/editors/ECore/Editor/du_cylinder.h +++ b/src/editors/ECore/Editor/du_cylinder.h @@ -11,3 +11,4 @@ extern ECORE_API u16 du_cylinder_faces[]; extern ECORE_API u16 du_cylinder_lines[]; #endif + diff --git a/src/editors/ECore/Editor/du_sphere.cpp b/src/editors/ECore/Editor/du_sphere.cpp index 082ae993288..3f5b675d6be 100644 --- a/src/editors/ECore/Editor/du_sphere.cpp +++ b/src/editors/ECore/Editor/du_sphere.cpp @@ -5,409 +5,409 @@ #include "du_sphere.h" //--------------------------------------------------------------------------- //#pragma package(smart_init) -Fvector du_sphere_vertices[DU_SPHERE_NUMVERTEX]={ - {0.0000f, 1.0000f, 0.0000f }, - {0.8944f, 0.4472f, 0.0000f }, - {0.2764f, 0.4472f, 0.8507f }, - {-0.7236f, 0.4472f, 0.5257f }, - {-0.7236f, 0.4472f, -0.5257f}, - {0.2764f, 0.4472f, -0.8507f}, - {0.7236f, -0.4472f, 0.5257f }, - {-0.2764f, -0.4472f, 0.8507f }, - {-0.8944f, -0.4472f, -0.0000f}, - {-0.2764f, -0.4472f, -0.8507f}, - {0.7236f, -0.4472f, -0.5257f}, - {0.0000f, -1.0000f, 0.0000f }, - {0.3607f, 0.9327f, 0.0000f }, - {0.6729f, 0.7397f, 0.0000f }, - {0.1115f, 0.9327f, 0.3431f }, - {0.2079f, 0.7397f, 0.6399f }, - {-0.2918f, 0.9327f, 0.2120f }, - {-0.5444f, 0.7397f, 0.3955f }, - {-0.2918f, 0.9327f, -0.2120f}, - {-0.5444f, 0.7397f, -0.3955f}, - {0.1115f, 0.9327f, -0.3431f}, - {0.2079f, 0.7397f, -0.6399f}, - {0.7844f, 0.5168f, 0.3431f }, - {0.5687f, 0.5168f, 0.6399f }, - {-0.0839f, 0.5168f, 0.8520f }, - {-0.4329f, 0.5168f, 0.7386f }, - {-0.8362f, 0.5168f, 0.1835f }, - {-0.8362f, 0.5168f, -0.1835f}, - {-0.4329f, 0.5168f, -0.7386f}, - {-0.0839f, 0.5168f, -0.8520f}, - {0.5687f, 0.5168f, -0.6399f}, - {0.7844f, 0.5168f, -0.3431f}, - {0.9647f, 0.1561f, 0.2120f }, - {0.9051f, -0.1561f, 0.3955f }, - {0.0965f, 0.1561f, 0.9830f }, - {-0.0965f, -0.1561f, 0.9830f }, - {-0.9051f, 0.1561f, 0.3955f }, - {-0.9647f, -0.1561f, 0.2120f }, - {-0.6558f, 0.1561f, -0.7386f}, - {-0.4998f, -0.1561f, -0.8520f}, - {0.4998f, 0.1561f, -0.8520f}, - {0.6558f, -0.1561f, -0.7386f}, - {0.9647f, 0.1561f, -0.2120f}, - {0.9051f, -0.1561f, -0.3955f}, - {0.4998f, 0.1561f, 0.8520f }, - {0.6558f, -0.1561f, 0.7386f }, - {-0.6558f, 0.1561f, 0.7386f }, - {-0.4998f, -0.1561f, 0.8520f }, - {-0.9051f, 0.1561f, -0.3955f}, - {-0.9647f, -0.1561f, -0.2120f}, - {0.0965f, 0.1561f, -0.9830f}, - {-0.0965f, -0.1561f, -0.9830f}, - {0.4329f, -0.5168f, 0.7386f }, - {0.0839f, -0.5168f, 0.8520f }, - {-0.5687f, -0.5168f, 0.6399f }, - {-0.7844f, -0.5168f, 0.3431f }, - {-0.7844f, -0.5168f, -0.3431f}, - {-0.5687f, -0.5168f, -0.6399f}, - {0.0839f, -0.5168f, -0.8520f}, - {0.4329f, -0.5168f, -0.7386f}, - {0.8362f, -0.5168f, -0.1835f}, - {0.8362f, -0.5168f, 0.1835f }, - {0.2918f, -0.9327f, 0.2120f }, - {0.5444f, -0.7397f, 0.3955f }, - {-0.1115f, -0.9327f, 0.3431f }, - {-0.2079f, -0.7397f, 0.6399f }, - {-0.3607f, -0.9327f, -0.0000f}, - {-0.6729f, -0.7397f, -0.0000f}, - {-0.1115f, -0.9327f, -0.3431f}, - {-0.2079f, -0.7397f, -0.6399f}, - {0.2918f, -0.9327f, -0.2120f}, - {0.5444f, -0.7397f, -0.3955f}, - {0.4795f, 0.8054f, 0.3484f }, - {-0.1832f, 0.8054f, 0.5637f }, - {-0.5927f, 0.8054f, -0.0000f}, - {-0.1832f, 0.8054f, -0.5637f}, - {0.4795f, 0.8054f, -0.3484f}, - {0.9855f, -0.1699f, 0.0000f }, - {0.3045f, -0.1699f, 0.9372f }, - {-0.7973f, -0.1699f, 0.5792f }, - {-0.7973f, -0.1699f, -0.5792f}, - {0.3045f, -0.1699f, -0.9372f}, - {0.7973f, 0.1699f, 0.5792f }, - {-0.3045f, 0.1699f, 0.9372f }, - {-0.9855f, 0.1699f, -0.0000f}, - {-0.3045f, 0.1699f, -0.9372f}, - {0.7973f, 0.1699f, -0.5792f}, - {0.1832f, -0.8054f, 0.5637f }, - {-0.4795f, -0.8054f, 0.3484f }, - {-0.4795f, -0.8054f, -0.3484f}, - {0.1832f, -0.8054f, -0.5637f}, - {0.5927f, -0.8054f, 0.0000 } +Fvector du_sphere_vertices[DU_SPHERE_NUMVERTEX] = { + {0.0000f, 1.0000f, 0.0000f}, + {0.8944f, 0.4472f, 0.0000f}, + {0.2764f, 0.4472f, 0.8507f}, + {-0.7236f, 0.4472f, 0.5257f}, + {-0.7236f, 0.4472f, -0.5257f}, + {0.2764f, 0.4472f, -0.8507f}, + {0.7236f, -0.4472f, 0.5257f}, + {-0.2764f, -0.4472f, 0.8507f}, + {-0.8944f, -0.4472f, -0.0000f}, + {-0.2764f, -0.4472f, -0.8507f}, + {0.7236f, -0.4472f, -0.5257f}, + {0.0000f, -1.0000f, 0.0000f}, + {0.3607f, 0.9327f, 0.0000f}, + {0.6729f, 0.7397f, 0.0000f}, + {0.1115f, 0.9327f, 0.3431f}, + {0.2079f, 0.7397f, 0.6399f}, + {-0.2918f, 0.9327f, 0.2120f}, + {-0.5444f, 0.7397f, 0.3955f}, + {-0.2918f, 0.9327f, -0.2120f}, + {-0.5444f, 0.7397f, -0.3955f}, + {0.1115f, 0.9327f, -0.3431f}, + {0.2079f, 0.7397f, -0.6399f}, + {0.7844f, 0.5168f, 0.3431f}, + {0.5687f, 0.5168f, 0.6399f}, + {-0.0839f, 0.5168f, 0.8520f}, + {-0.4329f, 0.5168f, 0.7386f}, + {-0.8362f, 0.5168f, 0.1835f}, + {-0.8362f, 0.5168f, -0.1835f}, + {-0.4329f, 0.5168f, -0.7386f}, + {-0.0839f, 0.5168f, -0.8520f}, + {0.5687f, 0.5168f, -0.6399f}, + {0.7844f, 0.5168f, -0.3431f}, + {0.9647f, 0.1561f, 0.2120f}, + {0.9051f, -0.1561f, 0.3955f}, + {0.0965f, 0.1561f, 0.9830f}, + {-0.0965f, -0.1561f, 0.9830f}, + {-0.9051f, 0.1561f, 0.3955f}, + {-0.9647f, -0.1561f, 0.2120f}, + {-0.6558f, 0.1561f, -0.7386f}, + {-0.4998f, -0.1561f, -0.8520f}, + {0.4998f, 0.1561f, -0.8520f}, + {0.6558f, -0.1561f, -0.7386f}, + {0.9647f, 0.1561f, -0.2120f}, + {0.9051f, -0.1561f, -0.3955f}, + {0.4998f, 0.1561f, 0.8520f}, + {0.6558f, -0.1561f, 0.7386f}, + {-0.6558f, 0.1561f, 0.7386f}, + {-0.4998f, -0.1561f, 0.8520f}, + {-0.9051f, 0.1561f, -0.3955f}, + {-0.9647f, -0.1561f, -0.2120f}, + {0.0965f, 0.1561f, -0.9830f}, + {-0.0965f, -0.1561f, -0.9830f}, + {0.4329f, -0.5168f, 0.7386f}, + {0.0839f, -0.5168f, 0.8520f}, + {-0.5687f, -0.5168f, 0.6399f}, + {-0.7844f, -0.5168f, 0.3431f}, + {-0.7844f, -0.5168f, -0.3431f}, + {-0.5687f, -0.5168f, -0.6399f}, + {0.0839f, -0.5168f, -0.8520f}, + {0.4329f, -0.5168f, -0.7386f}, + {0.8362f, -0.5168f, -0.1835f}, + {0.8362f, -0.5168f, 0.1835f}, + {0.2918f, -0.9327f, 0.2120f}, + {0.5444f, -0.7397f, 0.3955f}, + {-0.1115f, -0.9327f, 0.3431f}, + {-0.2079f, -0.7397f, 0.6399f}, + {-0.3607f, -0.9327f, -0.0000f}, + {-0.6729f, -0.7397f, -0.0000f}, + {-0.1115f, -0.9327f, -0.3431f}, + {-0.2079f, -0.7397f, -0.6399f}, + {0.2918f, -0.9327f, -0.2120f}, + {0.5444f, -0.7397f, -0.3955f}, + {0.4795f, 0.8054f, 0.3484f}, + {-0.1832f, 0.8054f, 0.5637f}, + {-0.5927f, 0.8054f, -0.0000f}, + {-0.1832f, 0.8054f, -0.5637f}, + {0.4795f, 0.8054f, -0.3484f}, + {0.9855f, -0.1699f, 0.0000f}, + {0.3045f, -0.1699f, 0.9372f}, + {-0.7973f, -0.1699f, 0.5792f}, + {-0.7973f, -0.1699f, -0.5792f}, + {0.3045f, -0.1699f, -0.9372f}, + {0.7973f, 0.1699f, 0.5792f}, + {-0.3045f, 0.1699f, 0.9372f}, + {-0.9855f, 0.1699f, -0.0000f}, + {-0.3045f, 0.1699f, -0.9372f}, + {0.7973f, 0.1699f, -0.5792f}, + {0.1832f, -0.8054f, 0.5637f}, + {-0.4795f, -0.8054f, 0.3484f}, + {-0.4795f, -0.8054f, -0.3484f}, + {0.1832f, -0.8054f, -0.5637f}, + {0.5927f, -0.8054f, 0.0000} }; -WORD du_sphere_faces[DU_SPHERE_NUMFACES*3]={ - 14, 12, 0, - 72, 13, 12, - 14, 72, 12, - 15, 72, 14, - 22, 1, 13, - 72, 22, 13, - 23, 22, 72, - 15, 23, 72, - 2, 23, 15, - 16, 14, 0, - 73, 15, 14, - 16, 73, 14, - 17, 73, 16, - 24, 2, 15, - 73, 24, 15, - 25, 24, 73, - 17, 25, 73, - 3, 25, 17, - 18, 16, 0, - 74, 17, 16, - 18, 74, 16, - 19, 74, 18, - 26, 3, 17, - 74, 26, 17, - 27, 26, 74, - 19, 27, 74, - 4, 27, 19, - 20, 18, 0, - 75, 19, 18, - 20, 75, 18, - 21, 75, 20, - 28, 4, 19, - 75, 28, 19, - 29, 28, 75, - 21, 29, 75, - 5, 29, 21, - 12, 20, 0, - 76, 21, 20, - 12, 76, 20, - 13, 76, 12, - 30, 5, 21, - 76, 30, 21, - 31, 30, 76, - 13, 31, 76, - 1, 31, 13, - 32, 42, 1, - 77, 43, 42, - 32, 77, 42, - 33, 77, 32, - 60, 10, 43, - 77, 60, 43, - 61, 60, 77, - 33, 61, 77, - 6, 61, 33, - 34, 44, 2, - 78, 45, 44, - 34, 78, 44, - 35, 78, 34, - 52, 6, 45, - 78, 52, 45, - 53, 52, 78, - 35, 53, 78, - 7, 53, 35, - 36, 46, 3, - 79, 47, 46, - 36, 79, 46, - 37, 79, 36, - 54, 7, 47, - 79, 54, 47, - 55, 54, 79, - 37, 55, 79, - 8, 55, 37, - 38, 48, 4, - 80, 49, 48, - 38, 80, 48, - 39, 80, 38, - 56, 8, 49, - 80, 56, 49, - 57, 56, 80, - 39, 57, 80, - 9, 57, 39, - 40, 50, 5, - 81, 51, 50, - 40, 81, 50, - 41, 81, 40, - 58, 9, 51, - 81, 58, 51, - 59, 58, 81, - 41, 59, 81, - 10, 59, 41, - 33, 45, 6, - 82, 44, 45, - 33, 82, 45, - 32, 82, 33, - 23, 2, 44, - 82, 23, 44, - 22, 23, 82, - 32, 22, 82, - 1, 22, 32, - 35, 47, 7, - 83, 46, 47, - 35, 83, 47, - 34, 83, 35, - 25, 3, 46, - 83, 25, 46, - 24, 25, 83, - 34, 24, 83, - 2, 24, 34, - 37, 49, 8, - 84, 48, 49, - 37, 84, 49, - 36, 84, 37, - 27, 4, 48, - 84, 27, 48, - 26, 27, 84, - 36, 26, 84, - 3, 26, 36, - 39, 51, 9, - 85, 50, 51, - 39, 85, 51, - 38, 85, 39, - 29, 5, 50, - 85, 29, 50, - 28, 29, 85, - 38, 28, 85, - 4, 28, 38, - 41, 43, 10, - 86, 42, 43, - 41, 86, 43, - 40, 86, 41, - 31, 1, 42, - 86, 31, 42, - 30, 31, 86, - 40, 30, 86, - 5, 30, 40, - 62, 64, 11, - 87, 65, 64, - 62, 87, 64, - 63, 87, 62, - 53, 7, 65, - 87, 53, 65, - 52, 53, 87, - 63, 52, 87, - 6, 52, 63, - 64, 66, 11, - 88, 67, 66, - 64, 88, 66, - 65, 88, 64, - 55, 8, 67, - 88, 55, 67, - 54, 55, 88, - 65, 54, 88, - 7, 54, 65, - 66, 68, 11, - 89, 69, 68, - 66, 89, 68, - 67, 89, 66, - 57, 9, 69, - 89, 57, 69, - 56, 57, 89, - 67, 56, 89, - 8, 56, 67, - 68, 70, 11, - 90, 71, 70, - 68, 90, 70, - 69, 90, 68, - 59, 10, 71, - 90, 59, 71, - 58, 59, 90, - 69, 58, 90, - 9, 58, 69, - 70, 62, 11, - 91, 63, 62, - 70, 91, 62, - 71, 91, 70, - 61, 6, 63, - 91, 61, 63, - 60, 61, 91, - 71, 60, 91, - 10, 60, 71, +WORD du_sphere_faces[DU_SPHERE_NUMFACES*3] = { + 14, 12, 0, + 72, 13, 12, + 14, 72, 12, + 15, 72, 14, + 22, 1, 13, + 72, 22, 13, + 23, 22, 72, + 15, 23, 72, + 2, 23, 15, + 16, 14, 0, + 73, 15, 14, + 16, 73, 14, + 17, 73, 16, + 24, 2, 15, + 73, 24, 15, + 25, 24, 73, + 17, 25, 73, + 3, 25, 17, + 18, 16, 0, + 74, 17, 16, + 18, 74, 16, + 19, 74, 18, + 26, 3, 17, + 74, 26, 17, + 27, 26, 74, + 19, 27, 74, + 4, 27, 19, + 20, 18, 0, + 75, 19, 18, + 20, 75, 18, + 21, 75, 20, + 28, 4, 19, + 75, 28, 19, + 29, 28, 75, + 21, 29, 75, + 5, 29, 21, + 12, 20, 0, + 76, 21, 20, + 12, 76, 20, + 13, 76, 12, + 30, 5, 21, + 76, 30, 21, + 31, 30, 76, + 13, 31, 76, + 1, 31, 13, + 32, 42, 1, + 77, 43, 42, + 32, 77, 42, + 33, 77, 32, + 60, 10, 43, + 77, 60, 43, + 61, 60, 77, + 33, 61, 77, + 6, 61, 33, + 34, 44, 2, + 78, 45, 44, + 34, 78, 44, + 35, 78, 34, + 52, 6, 45, + 78, 52, 45, + 53, 52, 78, + 35, 53, 78, + 7, 53, 35, + 36, 46, 3, + 79, 47, 46, + 36, 79, 46, + 37, 79, 36, + 54, 7, 47, + 79, 54, 47, + 55, 54, 79, + 37, 55, 79, + 8, 55, 37, + 38, 48, 4, + 80, 49, 48, + 38, 80, 48, + 39, 80, 38, + 56, 8, 49, + 80, 56, 49, + 57, 56, 80, + 39, 57, 80, + 9, 57, 39, + 40, 50, 5, + 81, 51, 50, + 40, 81, 50, + 41, 81, 40, + 58, 9, 51, + 81, 58, 51, + 59, 58, 81, + 41, 59, 81, + 10, 59, 41, + 33, 45, 6, + 82, 44, 45, + 33, 82, 45, + 32, 82, 33, + 23, 2, 44, + 82, 23, 44, + 22, 23, 82, + 32, 22, 82, + 1, 22, 32, + 35, 47, 7, + 83, 46, 47, + 35, 83, 47, + 34, 83, 35, + 25, 3, 46, + 83, 25, 46, + 24, 25, 83, + 34, 24, 83, + 2, 24, 34, + 37, 49, 8, + 84, 48, 49, + 37, 84, 49, + 36, 84, 37, + 27, 4, 48, + 84, 27, 48, + 26, 27, 84, + 36, 26, 84, + 3, 26, 36, + 39, 51, 9, + 85, 50, 51, + 39, 85, 51, + 38, 85, 39, + 29, 5, 50, + 85, 29, 50, + 28, 29, 85, + 38, 28, 85, + 4, 28, 38, + 41, 43, 10, + 86, 42, 43, + 41, 86, 43, + 40, 86, 41, + 31, 1, 42, + 86, 31, 42, + 30, 31, 86, + 40, 30, 86, + 5, 30, 40, + 62, 64, 11, + 87, 65, 64, + 62, 87, 64, + 63, 87, 62, + 53, 7, 65, + 87, 53, 65, + 52, 53, 87, + 63, 52, 87, + 6, 52, 63, + 64, 66, 11, + 88, 67, 66, + 64, 88, 66, + 65, 88, 64, + 55, 8, 67, + 88, 55, 67, + 54, 55, 88, + 65, 54, 88, + 7, 54, 65, + 66, 68, 11, + 89, 69, 68, + 66, 89, 68, + 67, 89, 66, + 57, 9, 69, + 89, 57, 69, + 56, 57, 89, + 67, 56, 89, + 8, 56, 67, + 68, 70, 11, + 90, 71, 70, + 68, 90, 70, + 69, 90, 68, + 59, 10, 71, + 90, 59, 71, + 58, 59, 90, + 69, 58, 90, + 9, 58, 69, + 70, 62, 11, + 91, 63, 62, + 70, 91, 62, + 71, 91, 70, + 61, 6, 63, + 91, 61, 63, + 60, 61, 91, + 71, 60, 91, + 10, 60, 71, }; -Fvector du_sphere_verticesl[DU_SPHERE_NUMVERTEXL]={ - {0, -1.0, 0 }, - {0.309018f, -0.951056f, 0 }, - {0.587786f, -0.809018f, 0 }, - {0.809018f, -0.587786f, 0 }, - {0.951056f, -0.309018f, 0 }, - {1.0, 0, 0 }, - {0.951056f, 0.309018f, 0 }, - {0.809018f, 0.587786f, 0 }, - {0.587786f, 0.809018f, 0 }, - {0.309018f, 0.951056f, 0 }, - {0, 1.0, 0 }, - {-0.309018f, 0.951056f, 0 }, - {-0.587786f, 0.809018f, 0 }, - {-0.809018f, 0.587786f, 0 }, - {-0.951056f, 0.309018f, 0 }, - {-1.0, 0, 0 }, - {-0.951056f, -0.309018f,0 }, - {-0.809018f, -0.587786f,0 }, - {-0.587786f, -0.809018f,0 }, - {-0.309018f, -0.951056f,0 }, - {1.0, 0, 0 }, - {0.951056f, 0, -0.309018f}, - {0.809018f, 0, -0.587786f}, - {0.587786f, 0, -0.809018f}, - {0.309018f, 0, -0.951056f}, - {0, 0, -1.0 }, - {-0.309018f, 0, -0.951056f}, - {-0.587786f, 0, -0.809018f}, - {-0.809018f, 0, -0.587786f}, - {-0.951056f, 0, -0.309018f}, - {-1.0, 0, 0 }, - {-0.951056f, 0, 0.309018f }, - {-0.809018f, 0, 0.587786f }, - {-0.587786f, 0, 0.809018f }, - {-0.309018f, 0, 0.951056f }, - {0, 0, 1.0 }, - {0.309018f, 0, 0.951056f }, - {0.587786f, 0, 0.809018f }, - {0.809018f, 0, 0.587786f }, - {0.951056f, 0, 0.309018f }, - {0, -1.0, 0 }, - {0, -0.951056f, -0.309018f}, - {0, -0.809018f, -0.587786f}, - {0, -0.587786f, -0.809018f}, - {0, -0.309018f, -0.951056f}, - {0, 0, -1.0 }, - {0, 0.309018f, -0.951056f}, - {0, 0.587786f, -0.809018f}, - {0, 0.809018f, -0.587786f}, - {0, 0.951056f, -0.309018f}, - {0, 1.0, 0 }, - {0, 0.951056f, 0.309018f }, - {0, 0.809018f, 0.587786f }, - {0, 0.587786f, 0.809018f }, - {0, 0.309018f, 0.951056f }, - {0, 0, 1.0 }, - {0, -0.309018f, 0.951056f }, - {0, -0.587786f, 0.809018f }, - {0, -0.809018f, 0.587786f }, - {0, -0.951056f, 0.309018f }, +Fvector du_sphere_verticesl[DU_SPHERE_NUMVERTEXL] = { + {0, -1.0, 0}, + {0.309018f, -0.951056f, 0}, + {0.587786f, -0.809018f, 0}, + {0.809018f, -0.587786f, 0}, + {0.951056f, -0.309018f, 0}, + {1.0, 0, 0}, + {0.951056f, 0.309018f, 0}, + {0.809018f, 0.587786f, 0}, + {0.587786f, 0.809018f, 0}, + {0.309018f, 0.951056f, 0}, + {0, 1.0, 0}, + {-0.309018f, 0.951056f, 0}, + {-0.587786f, 0.809018f, 0}, + {-0.809018f, 0.587786f, 0}, + {-0.951056f, 0.309018f, 0}, + {-1.0, 0, 0}, + {-0.951056f, -0.309018f,0}, + {-0.809018f, -0.587786f,0}, + {-0.587786f, -0.809018f,0}, + {-0.309018f, -0.951056f,0}, + {1.0, 0, 0}, + {0.951056f, 0, -0.309018f}, + {0.809018f, 0, -0.587786f}, + {0.587786f, 0, -0.809018f}, + {0.309018f, 0, -0.951056f}, + {0, 0, -1.0}, + {-0.309018f, 0, -0.951056f}, + {-0.587786f, 0, -0.809018f}, + {-0.809018f, 0, -0.587786f}, + {-0.951056f, 0, -0.309018f}, + {-1.0, 0, 0}, + {-0.951056f, 0, 0.309018f}, + {-0.809018f, 0, 0.587786f}, + {-0.587786f, 0, 0.809018f}, + {-0.309018f, 0, 0.951056f}, + {0, 0, 1.0}, + {0.309018f, 0, 0.951056f}, + {0.587786f, 0, 0.809018f}, + {0.809018f, 0, 0.587786f}, + {0.951056f, 0, 0.309018f}, + {0, -1.0, 0}, + {0, -0.951056f, -0.309018f}, + {0, -0.809018f, -0.587786f}, + {0, -0.587786f, -0.809018f}, + {0, -0.309018f, -0.951056f}, + {0, 0, -1.0}, + {0, 0.309018f, -0.951056f}, + {0, 0.587786f, -0.809018f}, + {0, 0.809018f, -0.587786f}, + {0, 0.951056f, -0.309018f}, + {0, 1.0, 0}, + {0, 0.951056f, 0.309018f}, + {0, 0.809018f, 0.587786f}, + {0, 0.587786f, 0.809018f}, + {0, 0.309018f, 0.951056f}, + {0, 0, 1.0}, + {0, -0.309018f, 0.951056f}, + {0, -0.587786f, 0.809018f}, + {0, -0.809018f, 0.587786f}, + {0, -0.951056f, 0.309018f}, }; -WORD du_sphere_lines[DU_SPHERE_NUMLINES*2]={ - 0, 1, - 1, 2, - 2, 3, - 3, 4, - 4, 5, - 5, 6, - 6, 7, - 7, 8, - 8, 9, - 9, 10, - 10, 11, - 11, 12, - 12, 13, - 13, 14, - 14, 15, - 15, 16, - 16, 17, - 17, 18, - 18, 19, - 19, 0, +WORD du_sphere_lines[DU_SPHERE_NUMLINES*2] = { + 0, 1, + 1, 2, + 2, 3, + 3, 4, + 4, 5, + 5, 6, + 6, 7, + 7, 8, + 8, 9, + 9, 10, + 10, 11, + 11, 12, + 12, 13, + 13, 14, + 14, 15, + 15, 16, + 16, 17, + 17, 18, + 18, 19, + 19, 0, - 20, 21, - 21, 22, - 22, 23, - 23, 24, - 24, 25, - 25, 26, - 26, 27, - 27, 28, - 28, 29, - 29, 30, - 30, 31, - 31, 32, - 32, 33, - 33, 34, - 34, 35, - 35, 36, - 36, 37, - 37, 38, - 38, 39, - 39, 20, - - 40, 41, - 41, 42, - 42, 43, - 43, 44, - 44, 45, - 45, 46, - 46, 47, - 47, 48, - 48, 49, - 49, 50, - 50, 51, - 51, 52, - 52, 53, - 53, 54, - 54, 55, - 55, 56, - 56, 57, - 57, 58, - 58, 59, - 59, 40, + 20, 21, + 21, 22, + 22, 23, + 23, 24, + 24, 25, + 25, 26, + 26, 27, + 27, 28, + 28, 29, + 29, 30, + 30, 31, + 31, 32, + 32, 33, + 33, 34, + 34, 35, + 35, 36, + 36, 37, + 37, 38, + 38, 39, + 39, 20, + + 40, 41, + 41, 42, + 42, 43, + 43, 44, + 44, 45, + 45, 46, + 46, 47, + 47, 48, + 48, 49, + 49, 50, + 50, 51, + 51, 52, + 52, 53, + 53, 54, + 54, 55, + 55, 56, + 56, 57, + 57, 58, + 58, 59, + 59, 40, }; diff --git a/src/editors/ECore/Editor/du_sphere.h b/src/editors/ECore/Editor/du_sphere.h index 39c7eb4af1c..799f513a29b 100644 --- a/src/editors/ECore/Editor/du_sphere.h +++ b/src/editors/ECore/Editor/du_sphere.h @@ -13,3 +13,4 @@ extern ECORE_API Fvector du_sphere_verticesl[]; extern ECORE_API WORD du_sphere_lines[]; #endif + diff --git a/src/editors/ECore/Editor/du_sphere_part.cpp b/src/editors/ECore/Editor/du_sphere_part.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/du_sphere_part.cpp @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/du_sphere_part.h b/src/editors/ECore/Editor/du_sphere_part.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/du_sphere_part.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/engine.h b/src/editors/ECore/Editor/engine.h index 491a4f4dd84..5f0e3c53268 100644 --- a/src/editors/ECore/Editor/engine.h +++ b/src/editors/ECore/Editor/engine.h @@ -7,24 +7,24 @@ #pragma once #include "ELog.h" -#include "../../../xrCPU_Pipe/xrCPU_Pipe.h" class ENGINE_API CEngine { - HMODULE hPSGP; -public: - CEngine (); - ~CEngine (); + HMODULE hPSGP; + public: + CEngine(); + ~CEngine(); - void Initialize (); - void Destroy (); - LPCSTR LastWindowsError(); + void Initialize(); + void Destroy(); + LPCSTR LastWindowsError(); - void ReloadSettings (); + void ReloadSettings(); }; -ENGINE_API extern xrDispatchTable PSGP; -ENGINE_API extern CEngine Engine; +ENGINE_API extern CEngine Engine; #endif // !defined(AFX_ENGINE_H__22802DD7_D7EB_4234_9781_E237657471AC__INCLUDED_) + + diff --git a/src/editors/ECore/Editor/itterate_adjacents_dynamic.h b/src/editors/ECore/Editor/itterate_adjacents_dynamic.h index 7c7c2886a27..ff00538cb48 100644 --- a/src/editors/ECore/Editor/itterate_adjacents_dynamic.h +++ b/src/editors/ECore/Editor/itterate_adjacents_dynamic.h @@ -1,7 +1,7 @@ #ifndef _ITTERATE_ADJACENTS_DYNAMIC_H_ #define _ITTERATE_ADJACENTS_DYNAMIC_H_ -#include "common/face_smoth_flags.h" +#include "Common/face_smoth_flags.h" template struct itterate_adjacents_params_dynamic diff --git a/src/editors/ECore/Editor/lwo2.h b/src/editors/ECore/Editor/lwo2.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/lwo2.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/pDomain.cpp b/src/editors/ECore/Editor/pDomain.cpp index 8924972f83e..e18e01e0039 100644 --- a/src/editors/ECore/Editor/pDomain.cpp +++ b/src/editors/ECore/Editor/pDomain.cpp @@ -1,84 +1,82 @@ #include "stdafx.h" #pragma hdrstop -#include "d3dutils.h" +#include "D3DUtils.h" #include "ui_main.h" -#include "../../xrServerEntities/PropertiesListHelper.h" +#include "xrServerEntities/PropertiesListHelper.h" #include "ParticleEffectActions.h" using namespace PAPI; -PDomain::PDomain(EType et, BOOL ra, u32 color, PDomainEnum t, - float inA0, float inA1, float inA2, - float inA3, float inA4, float inA5, - float inA6, float inA7, float inA8 ) +PDomain::PDomain(EType et, BOOL ra, u32 color, PDomainEnum t, + float inA0, float inA1, float inA2, + float inA3, float inA4, float inA5, + float inA6, float inA7, float inA8) { - flags.set(flRenderable,ra); - e_type = et; - type = t; - clr = color; - f[0] = inA0; - f[1] = inA1; - f[2] = inA2; - f[3] = inA3; - f[4] = inA4; - f[5] = inA5; - f[6] = inA6; - f[7] = inA7; - f[8] = inA8; + flags.set(flRenderable, ra); + e_type = et; + type = t; + clr = color; + f[0] = inA0; + f[1] = inA1; + f[2] = inA2; + f[3] = inA3; + f[4] = inA4; + f[5] = inA5; + f[6] = inA6; + f[7] = inA7; + f[8] = inA8; } -PDomain::PDomain(const PDomain& inDomain) +PDomain::PDomain(const PDomain &inDomain) { - e_type = inDomain.e_type; - flags = inDomain.flags; - type = inDomain.type; - clr = inDomain.clr; - f[0] = inDomain.f[0]; - f[1] = inDomain.f[1]; - f[2] = inDomain.f[2]; - f[3] = inDomain.f[3]; - f[4] = inDomain.f[4]; - f[5] = inDomain.f[5]; - f[6] = inDomain.f[6]; - f[7] = inDomain.f[7]; - f[8] = inDomain.f[8]; + e_type = inDomain.e_type; + flags = inDomain.flags; + type = inDomain.type; + clr = inDomain.clr; + f[0] = inDomain.f[0]; + f[1] = inDomain.f[1]; + f[2] = inDomain.f[2]; + f[3] = inDomain.f[3]; + f[4] = inDomain.f[4]; + f[5] = inDomain.f[5]; + f[6] = inDomain.f[6]; + f[7] = inDomain.f[7]; + f[8] = inDomain.f[8]; } -PDomain::~PDomain() -{ -} +PDomain::~PDomain() {} -void PDomain::Load(IReader& F) +void PDomain::Load(IReader &F) { - type = PDomainEnum(F.r_u32()); - F.r_fvector3(v[0]); - F.r_fvector3(v[1]); - F.r_fvector3(v[2]); + type = PDomainEnum(F.r_u32()); + F.r_fvector3(v[0]); + F.r_fvector3(v[1]); + F.r_fvector3(v[2]); } -void PDomain::Load2(CInifile& ini, const shared_str& sect) +void PDomain::Load2(CInifile &ini, const shared_str §) { - type = PDomainEnum(ini.r_u32(sect,"type")); - v[0] = ini.r_fvector3(sect,"v0"); - v[1] = ini.r_fvector3(sect,"v1"); - v[2] = ini.r_fvector3(sect,"v2"); + type = PDomainEnum(ini.r_u32(sect, "type")); + v[0] = ini.r_fvector3(sect, "v0"); + v[1] = ini.r_fvector3(sect, "v1"); + v[2] = ini.r_fvector3(sect, "v2"); } -void PDomain::Save(IWriter& F) +void PDomain::Save(IWriter &F) { - F.w_u32 (type); - F.w_fvector3(v[0]); - F.w_fvector3(v[1]); - F.w_fvector3(v[2]); + F.w_u32(type); + F.w_fvector3(v[0]); + F.w_fvector3(v[1]); + F.w_fvector3(v[2]); } -void PDomain::Save2(CInifile& ini, const shared_str& sect) +void PDomain::Save2(CInifile &ini, const shared_str §) { - ini.w_u32 (sect.c_str(), "type", type); - ini.w_fvector3 (sect.c_str(), "v0", v[0]); - ini.w_fvector3 (sect.c_str(), "v1", v[1]); - ini.w_fvector3 (sect.c_str(), "v2", v[2]); + ini.w_u32(sect.c_str(), "type", type); + ini.w_fvector3(sect.c_str(), "v0", v[0]); + ini.w_fvector3(sect.c_str(), "v1", v[1]); + ini.w_fvector3(sect.c_str(), "v2", v[2]); } /* @@ -86,298 +84,411 @@ void PDomain::set(PAPI::PDomainEnum t, float inA0, float inA1, float inA2, float inA3, float inA4, float inA5, float inA6, float inA7, float inA8 ) { - type = t; - f[0] = inA0; - f[1] = inA1; - f[2] = inA2; - f[3] = inA3; - f[4] = inA4; - f[5] = inA5; - f[6] = inA6; - f[7] = inA7; - f[8] = inA8; + type = t; + f[0] = inA0; + f[1] = inA1; + f[2] = inA2; + f[3] = inA3; + f[4] = inA4; + f[5] = inA5; + f[6] = inA6; + f[7] = inA7; + f[8] = inA8; } */ //-------------------------------------------------------------------- -void PDomain::Render (u32 clr, const Fmatrix& parent) +void PDomain::Render(u32 clr, const Fmatrix &parent) { - if (!flags.is(flRenderable)) return; - u32 clr_s = subst_alpha (clr,0x60); - u32 clr_w = subst_alpha (clr,0xff); - RCache.set_xform_world (parent); - switch(type){ - case PDPoint: - EDevice.SetShader (EDevice.m_WireShader); - DU_impl.DrawCross (v[0], 0.05f,0.05f,0.05f, 0.05f,0.05f,0.05f, clr_w); - break; - case PDLine: - EDevice.SetShader (EDevice.m_WireShader); - DU_impl.DrawCross (v[0], 0.05f,0.05f,0.05f, 0.05f,0.05f,0.05f, clr_w); - DU_impl.DrawCross (v[1], 0.05f,0.05f,0.05f, 0.05f,0.05f,0.05f, clr_w); - DU_impl.DrawLine (v[0], v[1], clr_w); - break; - case PDTriangle: - EDevice.SetShader (EDevice.m_SelectionShader); - DU_impl.DrawFace (v[0], v[1], v[2], clr_s, clr_w, true, true); - break; - case PDPlane:{ - EDevice.SetShader (EDevice.m_SelectionShader); - Fvector2 sz = {100.f,100.f}; - DU_impl.DrawPlane (v[0],v[1],sz,clr_s,clr_w,true,true,true); - }break; - case PDBox: - EDevice.SetShader (EDevice.m_SelectionShader); - DU_impl.DrawAABB (v[0], v[1], clr_s, clr_w, true, true); - break; - case PDSphere: - DU_impl.DrawSphere (parent, v[0], f[4], clr_s, clr_w, true, true); - DU_impl.DrawSphere (parent, v[0], f[3], clr_s, clr_w, true, true); - break; - case PDCylinder:{ - Fvector c,d; - float h = d.sub(v[1],v[0]).magnitude(); - c.add (v[0],v[1]).div(2.f); - if (!fis_zero(h)){ - d.div (h); - DU_impl.DrawCylinder (parent, c, d, h, f[6], clr_s, clr_w, true, true); - DU_impl.DrawCylinder (parent, c, d, h, f[7], clr_s, clr_w, true, true); + if (!flags.is(flRenderable)) + return; + u32 clr_s = subst_alpha(clr, 0x60); + u32 clr_w = subst_alpha(clr, 0xff); + RCache.set_xform_world(parent); + switch (type) + { + case PDPoint: + EDevice.SetShader(EDevice.m_WireShader); + DU_impl.DrawCross(v[0], 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, clr_w); + break; + case PDLine: + EDevice.SetShader(EDevice.m_WireShader); + DU_impl.DrawCross(v[0], 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, clr_w); + DU_impl.DrawCross(v[1], 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, clr_w); + DU_impl.DrawLine(v[0], v[1], clr_w); + break; + case PDTriangle: + EDevice.SetShader(EDevice.m_SelectionShader); + DU_impl.DrawFace(v[0], v[1], v[2], clr_s, clr_w, true, true); + break; + case PDPlane: + { + EDevice.SetShader(EDevice.m_SelectionShader); + Fvector2 sz = {100.f,100.f}; + DU_impl.DrawPlane(v[0], v[1], sz, clr_s, clr_w, true, true, true); + } + break; + case PDBox: + EDevice.SetShader(EDevice.m_SelectionShader); + DU_impl.DrawAABB(v[0], v[1], clr_s, clr_w, true, true); + break; + case PDSphere: + DU_impl.DrawSphere(parent, v[0], f[4], clr_s, clr_w, true, true); + DU_impl.DrawSphere(parent, v[0], f[3], clr_s, clr_w, true, true); + break; + case PDCylinder: + { + Fvector c, d; + float h = d.sub(v[1], v[0]).magnitude(); + c.add(v[0], v[1]).div(2.f); + if (!fis_zero(h)) + { + d.div(h); + DU_impl.DrawCylinder(parent, c, d, h, f[6], clr_s, clr_w, true, true); + DU_impl.DrawCylinder(parent, c, d, h, f[7], clr_s, clr_w, true, true); + } } - }break; - case PDCone:{ - Fvector d; - float h = d.sub(v[1],v[0]).magnitude(); - if (!fis_zero(h)){ - d.div (h); - DU_impl.DrawCone (parent, v[0], d, h, f[6], clr_s, clr_w, true, true); - DU_impl.DrawCone (parent, v[0], d, h, f[7], clr_s, clr_w, true, true); + break; + case PDCone: + { + Fvector d; + float h = d.sub(v[1], v[0]).magnitude(); + if (!fis_zero(h)) + { + d.div(h); + DU_impl.DrawCone(parent, v[0], d, h, f[6], clr_s, clr_w, true, true); + DU_impl.DrawCone(parent, v[0], d, h, f[7], clr_s, clr_w, true, true); + } } - }break; - case PDBlob: - EDevice.SetShader (EDevice.m_WireShader); - DU_impl.DrawCross (v[0], f[3],f[3],f[3], f[3],f[3],f[3], clr); - break; - case PDDisc: - DU_impl.DrawCylinder (parent, v[0], v[1], 0.f, f[6], clr_s, clr_w, true, true); - DU_impl.DrawCylinder (parent, v[0], v[1], 0.f, f[7], clr_s, clr_w, true, true); - break; - case PDRectangle: - DU_impl.DrawRectangle (v[0], v[1], v[2], clr_s, clr_w, true, true); - break; - } + break; + case PDBlob: + EDevice.SetShader(EDevice.m_WireShader); + DU_impl.DrawCross(v[0], f[3], f[3], f[3], f[3], f[3], f[3], clr); + break; + case PDDisc: + DU_impl.DrawCylinder(parent, v[0], v[1], 0.f, f[6], clr_s, clr_w, true, true); + DU_impl.DrawCylinder(parent, v[0], v[1], 0.f, f[7], clr_s, clr_w, true, true); + break; + case PDRectangle: + DU_impl.DrawRectangle(v[0], v[1], v[2], clr_s, clr_w, true, true); + break; + } } -xr_token domain_token [ ]={ - { "Point", PDPoint }, - { "Line", PDLine }, - { "Triangle", PDTriangle }, - { "Plane", PDPlane }, - { "Box", PDBox }, - { "Sphere", PDSphere }, - { "Cylinder", PDCylinder }, - { "Cone", PDCone }, - { "Blob", PDBlob }, - { "Disc", PDDisc }, - { "Rectangle", PDRectangle }, - { 0, 0 } +xr_token domain_token [ ] = { + {"Point", PDPoint}, + {"Line", PDLine}, + {"Triangle", PDTriangle}, + {"Plane", PDPlane}, + {"Box", PDBox}, + {"Sphere", PDSphere}, + {"Cylinder", PDCylinder}, + {"Cone", PDCone}, + {"Blob", PDBlob}, + {"Disc", PDDisc}, + {"Rectangle", PDRectangle}, + {0, 0} }; -void PDomain::OnTypeChange(PropValue* sender) -{ - ExecCommand (COMMAND_UPDATE_PROPERTIES); +void PDomain::OnTypeChange(PropValue *sender) +{ + ExecCommand(COMMAND_UPDATE_PROPERTIES); } -void PDomain::FillProp (PropItemVec& items, LPCSTR pref, u32 clr) +void PDomain::FillProp(PropItemVec &items, LPCSTR pref, u32 clr) { - PropValue* V; - V=PHelper().CreateToken32(items,pref,(u32*)&type,domain_token); - V->OnChangeEvent.bind (this,&PDomain::OnTypeChange); - V->Owner()->prop_color = TColor(clr); - - switch(e_type){ - case vNum: - switch(type){ - case PDPoint: - V=PHelper().CreateVector (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDLine: - V=PHelper().CreateVector (items,PrepareKey(pref,"Point 1"), &v[0],flt_min,flt_max,0.001f,3); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Point 2"), &v[1],flt_min,flt_max,0.001f,3); V->Owner()->prop_color = TColor(clr); - break; - case PDTriangle: - V=PHelper().CreateVector (items,PrepareKey(pref,"Vertex 1"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Vertex 2"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Vertex 3"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDPlane: - V=PHelper().CreateVector (items,PrepareKey(pref,"Origin"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Normal"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDBox: - V=PHelper().CreateVector (items,PrepareKey(pref,"Min"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Max"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDSphere: - V=PHelper().CreateVector (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[3],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[4],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDCylinder: - V=PHelper().CreateVector (items,PrepareKey(pref,"Point 1"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Point 2"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDCone: - V=PHelper().CreateVector (items,PrepareKey(pref,"Apex"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"End Point"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDBlob: - V=PHelper().CreateVector (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[3],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDDisc: - V=PHelper().CreateVector (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Normal"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDRectangle: - V=PHelper().CreateVector (items,PrepareKey(pref,"Origin"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Basis U"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Basis V"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - default: - V=PHelper().CreateVector (items,PrepareKey(pref,"Translate"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Rotate"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVector (items,PrepareKey(pref,"Scale"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - } - break; - case vAngle: - switch(type){ - case PDPoint: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDLine: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Point 1"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Point 2"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDTriangle: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Vertex 1"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Vertex 2"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Vertex 3"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDPlane: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Origin"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Normal"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDBox: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Min"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Max"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDSphere: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[3],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[4],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDCylinder: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Point 1"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Point 2"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDCone: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Apex"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"End Point"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDBlob: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[3],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDDisc: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Center"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Normal"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - case PDRectangle: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Origin"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Basis U"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Basis V"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - default: - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Translate"), &v[0],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Rotate"), &v[1],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateAngle3 (items,PrepareKey(pref,"Scale"), &v[2],flt_min,flt_max,0.001f,3);V->Owner()->prop_color = TColor(clr); - break; - } - break; - case vColor: - switch(type){ - case PDPoint: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Center"), &v[0]); V->Owner()->prop_color = TColor(clr); - break; - case PDLine: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Point 1"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Point 2"), &v[1]); V->Owner()->prop_color = TColor(clr); - break; - case PDTriangle: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Vertex 1"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Vertex 2"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Vertex 3"), &v[2]); V->Owner()->prop_color = TColor(clr); - break; - case PDPlane: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Origin"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Normal"), &v[1]); V->Owner()->prop_color = TColor(clr); - break; - case PDBox: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Min"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Max"), &v[1]); V->Owner()->prop_color = TColor(clr); - break; - case PDSphere: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Center"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[3]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[4]); V->Owner()->prop_color = TColor(clr); - break; - case PDCylinder: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Point 1"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Point 2"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7]); V->Owner()->prop_color = TColor(clr); - break; - case PDCone: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Apex"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"End Point"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7]); V->Owner()->prop_color = TColor(clr); - break; - case PDBlob: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Center"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[3]); V->Owner()->prop_color = TColor(clr); - break; - case PDDisc: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Center"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Normal"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Inner"), &f[6]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateFloat (items,PrepareKey(pref,"Radius Outer"), &f[7]); V->Owner()->prop_color = TColor(clr); - break; - case PDRectangle: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Origin"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Basis U"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Basis V"), &v[2]); V->Owner()->prop_color = TColor(clr); - break; - default: - V=PHelper().CreateVColor (items,PrepareKey(pref,"Translate"), &v[0]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Rotate"), &v[1]); V->Owner()->prop_color = TColor(clr); - V=PHelper().CreateVColor (items,PrepareKey(pref,"Scale"), &v[2]); V->Owner()->prop_color = TColor(clr); - break; - } - break; + PropValue *V; + V = PHelper().CreateToken32(items, pref, (u32*)&type, domain_token); + V->OnChangeEvent.bind(this, &PDomain::OnTypeChange); + V->Owner()->prop_color = TColor(clr); + + switch (e_type) + { + case vNum: + switch (type) + { + case PDPoint: + V = PHelper().CreateVector(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDLine: + V = PHelper().CreateVector(items, PrepareKey(pref, "Point 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Point 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDTriangle: + V = PHelper().CreateVector(items, PrepareKey(pref, "Vertex 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Vertex 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Vertex 3"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDPlane: + V = PHelper().CreateVector(items, PrepareKey(pref, "Origin"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Normal"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDBox: + V = PHelper().CreateVector(items, PrepareKey(pref, "Min"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Max"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDSphere: + V = PHelper().CreateVector(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[3], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[4], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDCylinder: + V = PHelper().CreateVector(items, PrepareKey(pref, "Point 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Point 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDCone: + V = PHelper().CreateVector(items, PrepareKey(pref, "Apex"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "End Point"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDBlob: + V = PHelper().CreateVector(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[3], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDDisc: + V = PHelper().CreateVector(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Normal"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDRectangle: + V = PHelper().CreateVector(items, PrepareKey(pref, "Origin"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Basis U"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Basis V"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + default: + V = PHelper().CreateVector(items, PrepareKey(pref, "Translate"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Rotate"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVector(items, PrepareKey(pref, "Scale"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + } + break; + case vAngle: + switch (type) + { + case PDPoint: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDLine: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Point 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Point 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDTriangle: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Vertex 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Vertex 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Vertex 3"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDPlane: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Origin"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Normal"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDBox: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Min"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Max"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDSphere: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[3], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[4], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDCylinder: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Point 1"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Point 2"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDCone: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Apex"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "End Point"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDBlob: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[3], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDDisc: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Center"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Normal"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + case PDRectangle: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Origin"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Basis U"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Basis V"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + default: + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Translate"), &v[0], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Rotate"), &v[1], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateAngle3(items, PrepareKey(pref, "Scale"), &v[2], flt_min, flt_max, 0.001f, 3); + V->Owner()->prop_color = TColor(clr); + break; + } + break; + case vColor: + switch (type) + { + case PDPoint: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Center"), &v[0]); + V->Owner()->prop_color = TColor(clr); + break; + case PDLine: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Point 1"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Point 2"), &v[1]); + V->Owner()->prop_color = TColor(clr); + break; + case PDTriangle: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Vertex 1"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Vertex 2"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Vertex 3"), &v[2]); + V->Owner()->prop_color = TColor(clr); + break; + case PDPlane: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Origin"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Normal"), &v[1]); + V->Owner()->prop_color = TColor(clr); + break; + case PDBox: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Min"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Max"), &v[1]); + V->Owner()->prop_color = TColor(clr); + break; + case PDSphere: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Center"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[3]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[4]); + V->Owner()->prop_color = TColor(clr); + break; + case PDCylinder: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Point 1"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Point 2"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7]); + V->Owner()->prop_color = TColor(clr); + break; + case PDCone: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Apex"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "End Point"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7]); + V->Owner()->prop_color = TColor(clr); + break; + case PDBlob: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Center"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[3]); + V->Owner()->prop_color = TColor(clr); + break; + case PDDisc: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Center"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Normal"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Inner"), &f[6]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateFloat(items, PrepareKey(pref, "Radius Outer"), &f[7]); + V->Owner()->prop_color = TColor(clr); + break; + case PDRectangle: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Origin"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Basis U"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Basis V"), &v[2]); + V->Owner()->prop_color = TColor(clr); + break; + default: + V = PHelper().CreateVColor(items, PrepareKey(pref, "Translate"), &v[0]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Rotate"), &v[1]); + V->Owner()->prop_color = TColor(clr); + V = PHelper().CreateVColor(items, PrepareKey(pref, "Scale"), &v[2]); + V->Owner()->prop_color = TColor(clr); + break; + } + break; } } @@ -385,212 +496,213 @@ void PDomain::FillProp (PropItemVec& items, LPCSTR pref, u32 clr) /* void PDomain::MoveXYZ(float x, float y, float z) { - switch(type) - { - case PDPoint: - a0+=x; a1+=y; a2+=z; - break; - case PDLine: - a0+=x; a1+=y; a2+=z; - a3+=x; a4+=y; a5+=z; - break; - case PDTriangle: - a0+=x; a1+=y; a2+=z; - a3+=x; a4+=y; a5+=z; - a6+=x; a7+=y; a8+=z; - break; - case PDPlane: - a0+=x; a1+=y; a2+=z; - break; - case PDBox: - a0+=x; a1+=y; a2+=z; - a3+=x; a4+=y; a5+=z; - break; - case PDSphere: - a0+=x; a1+=y; a2+=z; - break; - case PDCylinder: - a0+=x; a1+=y; a2+=z; - a3+=x; a4+=y; a5+=z; - break; - case PDCone: - a0+=x; a1+=y; a2+=z; - a3+=x; a4+=y; a5+=z; - break; - case PDBlob: - a0+=x; a1+=y; a2+=z; - break; - case PDDisc: - a0+=x; a1+=y; a2+=z; - break; - } - + switch(type) + { + case PDPoint: + a0+=x; a1+=y; a2+=z; + break; + case PDLine: + a0+=x; a1+=y; a2+=z; + a3+=x; a4+=y; a5+=z; + break; + case PDTriangle: + a0+=x; a1+=y; a2+=z; + a3+=x; a4+=y; a5+=z; + a6+=x; a7+=y; a8+=z; + break; + case PDPlane: + a0+=x; a1+=y; a2+=z; + break; + case PDBox: + a0+=x; a1+=y; a2+=z; + a3+=x; a4+=y; a5+=z; + break; + case PDSphere: + a0+=x; a1+=y; a2+=z; + break; + case PDCylinder: + a0+=x; a1+=y; a2+=z; + a3+=x; a4+=y; a5+=z; + break; + case PDCone: + a0+=x; a1+=y; a2+=z; + a3+=x; a4+=y; a5+=z; + break; + case PDBlob: + a0+=x; a1+=y; a2+=z; + break; + case PDDisc: + a0+=x; a1+=y; a2+=z; + break; + } + } //---------------------------------------------------------- void PDomain::RotateXYZ (float x, float y, float z) { - MVertex v1; - MVertex v2; - MVertex v3; - MVertex r1; - MVertex r2; - MVertex r3; + MVertex v1; + MVertex v2; + MVertex v3; + MVertex r1; + MVertex r2; + MVertex r3; // MVertex tmpV; - MMatrix trans; - - MVertex c; - - trans.setIdentity(); - trans.rotateX(x); - trans.rotateZ(z); - trans.rotateY(y); + MMatrix trans; + + MVertex c; + + trans.setIdentity(); + trans.rotateX(x); + trans.rotateZ(z); + trans.rotateY(y); // float xloc; // float yloc; // float zloc; - switch(type) - { - case PDPoint: - break; - case PDLine: - r1 = trans*(v1.set( a0, a1, a2 )); - r2 = trans*(v2.set( a3, a4, a5 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - break; - case PDTriangle: - c = GetCenter(); - r1 = trans*(v1.set( (float)a0-c.X(), (float)a1-c.Y(), (float)a2-c.Z() )); - r2 = trans*(v2.set( (float)a3-c.X(), (float)a4-c.Y(), (float)a5-c.Z() )); - r3 = trans*(v3.set( (float)a6-c.X(), (float)a7-c.Y(), (float)a8-c.Z() )); - a0 = r1.X()+c.X(); a1 = r1.Y()+c.Y(); a2 = r1.Z()+c.Z(); - a3 = r2.X()+c.X(); a4 = r2.Y()+c.Y(); a5 = r2.Z()+c.Z(); - a6 = r3.X()+c.X(); a7 = r3.Y()+c.Y(); a8 = r3.Z()+c.Z(); - break; - case PDPlane: + switch(type) + { + case PDPoint: + break; + case PDLine: + r1 = trans*(v1.set( a0, a1, a2 )); + r2 = trans*(v2.set( a3, a4, a5 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + break; + case PDTriangle: + c = GetCenter(); + r1 = trans*(v1.set( (float)a0-c.X(), (float)a1-c.Y(), (float)a2-c.Z() )); + r2 = trans*(v2.set( (float)a3-c.X(), (float)a4-c.Y(), (float)a5-c.Z() )); + r3 = trans*(v3.set( (float)a6-c.X(), (float)a7-c.Y(), (float)a8-c.Z() )); + a0 = r1.X()+c.X(); a1 = r1.Y()+c.Y(); a2 = r1.Z()+c.Z(); + a3 = r2.X()+c.X(); a4 = r2.Y()+c.Y(); a5 = r2.Z()+c.Z(); + a6 = r3.X()+c.X(); a7 = r3.Y()+c.Y(); a8 = r3.Z()+c.Z(); + break; + case PDPlane: // r2 = trans*(v2.set( a3, a4, a5 )); // r3 = trans*(v3.set( a6, a7, a8 )); // a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); // a6 = r3.X(); a7 = r3.Y(); a8 = r3.Z(); - - c = GetCenter(); - v1.set(a0-c.X(), a1-c.Y(), a2-c.Z()); - v2.set((float)a0+((float)a3/2.0), (float)a1+((float)a4/2.0), (float)a2+((float)a5/2.0)); - v3.set((float)a0+((float)a6/2.0), (float)a1+((float)a7/2.0), (float)a2+((float)a8/2.0)); - - r1 = trans*v1; - r2 = trans*v2; - r3 = trans*v3; - - a0 = r1.X()+c.X(); a1 = r1.Y()+c.Y(); a2 = r1.Z()+c.Z(); - - - break; - case PDBox: - r1 = trans*(v1.set( a0, a1, a2 )); - r2 = trans*(v2.set( a3, a4, a5 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); - break; - case PDSphere: - r1 = trans*(v1.set( a0, a1, a2 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - break; - case PDCylinder: - r1 = trans*(v1.set( a0, a1, a2 )); - r2 = trans*(v2.set( a3, a4, a5 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); - break; - case PDCone: - r1 = trans*(v1.set( a0, a1, a2 )); - r2 = trans*(v2.set( a3, a4, a5 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); - break; - case PDBlob: - r1 = trans*(v1.set( a0, a1, a2 )); - a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); - break; - case PDDisc: - break; - } + + c = GetCenter(); + v1.set(a0-c.X(), a1-c.Y(), a2-c.Z()); + v2.set((float)a0+((float)a3/2.0), (float)a1+((float)a4/2.0), (float)a2+((float)a5/2.0)); + v3.set((float)a0+((float)a6/2.0), (float)a1+((float)a7/2.0), (float)a2+((float)a8/2.0)); + + r1 = trans*v1; + r2 = trans*v2; + r3 = trans*v3; + + a0 = r1.X()+c.X(); a1 = r1.Y()+c.Y(); a2 = r1.Z()+c.Z(); + + + break; + case PDBox: + r1 = trans*(v1.set( a0, a1, a2 )); + r2 = trans*(v2.set( a3, a4, a5 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); + break; + case PDSphere: + r1 = trans*(v1.set( a0, a1, a2 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + break; + case PDCylinder: + r1 = trans*(v1.set( a0, a1, a2 )); + r2 = trans*(v2.set( a3, a4, a5 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); + break; + case PDCone: + r1 = trans*(v1.set( a0, a1, a2 )); + r2 = trans*(v2.set( a3, a4, a5 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + a3 = r2.X(); a4 = r2.Y(); a5 = r2.Z(); + break; + case PDBlob: + r1 = trans*(v1.set( a0, a1, a2 )); + a0 = r1.X(); a1 = r1.Y(); a2 = r1.Z(); + break; + case PDDisc: + break; + } } //---------------------------------------------------------- void PDomain::ScaleXYZ (float x, float y, float z) { - x = x; - y = y; - z = z; - - switch(type) - { - case PDPoint: - break; - case PDLine: - break; - case PDTriangle: - break; - case PDPlane: - break; - case PDBox: - break; - case PDSphere: - break; - case PDCylinder: - break; - case PDCone: - break; - case PDBlob: - break; - case PDDisc: - break; - } + x = x; + y = y; + z = z; + + switch(type) + { + case PDPoint: + break; + case PDLine: + break; + case PDTriangle: + break; + case PDPlane: + break; + case PDBox: + break; + case PDSphere: + break; + case PDCylinder: + break; + case PDCone: + break; + case PDBlob: + break; + case PDDisc: + break; + } } //---------------------------------------------------------- MVertex& PDomain::GetCenter() { - static MVertex center; - MVertex v1; - MVertex v2; - MVertex v3; - MVertex v4; - - switch(type) - { - case PDPoint: - center.set(a0, a1, a2); - break; - case PDLine: - break; - case PDTriangle: - center.set( ((float)a0+(float)a3+(float)a6)/3.0, - ((float)a1+(float)a4+(float)a7)/3.0, - ((float)a2+(float)a5+(float)a8)/3.0 ); - break; - case PDPlane: - v1.set(a0, a1, a2); - v2.set(a0+(a3/2.0f), a1+(a4/2.0f), a2+(a5/2.0f)); - v3.set(a0+(a6/2.0f), a1+(a7/2.0f), a2+(a8/2.0f)); - v4.set(a0+(a6/2.0f)+(a3/2.0f), a1+(a7/2.0f)+(a4/2.0f), a2+(a8/2.0f)+(a5/2.0f)); - center.set( (v1.X()+v2.X()+v3.X()+v4.X())/4.0, - (v1.Y()+v2.Y()+v3.Y()+v4.Y())/4.0, - (v1.Z()+v2.Z()+v3.Z()+v4.Z())/4.0 ); - break; - case PDBox: - break; - case PDSphere: - break; - case PDCylinder: - break; - case PDCone: - break; - case PDBlob: - break; - case PDDisc: - center.set(a0, a1, a2); - break; - } - return center; + static MVertex center; + MVertex v1; + MVertex v2; + MVertex v3; + MVertex v4; + + switch(type) + { + case PDPoint: + center.set(a0, a1, a2); + break; + case PDLine: + break; + case PDTriangle: + center.set( ((float)a0+(float)a3+(float)a6)/3.0, + ((float)a1+(float)a4+(float)a7)/3.0, + ((float)a2+(float)a5+(float)a8)/3.0 ); + break; + case PDPlane: + v1.set(a0, a1, a2); + v2.set(a0+(a3/2.0f), a1+(a4/2.0f), a2+(a5/2.0f)); + v3.set(a0+(a6/2.0f), a1+(a7/2.0f), a2+(a8/2.0f)); + v4.set(a0+(a6/2.0f)+(a3/2.0f), a1+(a7/2.0f)+(a4/2.0f), a2+(a8/2.0f)+(a5/2.0f)); + center.set( (v1.X()+v2.X()+v3.X()+v4.X())/4.0, + (v1.Y()+v2.Y()+v3.Y()+v4.Y())/4.0, + (v1.Z()+v2.Z()+v3.Z()+v4.Z())/4.0 ); + break; + case PDBox: + break; + case PDSphere: + break; + case PDCylinder: + break; + case PDCone: + break; + case PDBlob: + break; + case PDDisc: + center.set(a0, a1, a2); + break; + } + return center; } */ + diff --git a/src/editors/ECore/Editor/pick_definition.h b/src/editors/ECore/Editor/pick_definition.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Editor/pick_definition.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Editor/render.cpp b/src/editors/ECore/Editor/render.cpp index a1b0fb42758..974298d71df 100644 --- a/src/editors/ECore/Editor/render.cpp +++ b/src/editors/ECore/Editor/render.cpp @@ -2,230 +2,284 @@ #pragma hdrstop #include "render.h" -#include "ResourceManager.h" -#include "../../Include/xrAPI/xrAPI.h" +#include "Layers/xrRender/ResourceManager.h" +#include "Include/xrAPI/xrAPI.h" //--------------------------------------------------------------------------- -float ssaDISCARD = 4.f; -float ssaDONTSORT = 32.f; +float ssaDISCARD = 4.f; +float ssaDONTSORT = 32.f; -ECORE_API float r_ssaDISCARD; -ECORE_API float g_fSCREEN; +ECORE_API +float r_ssaDISCARD; +ECORE_API +float g_fSCREEN; -CRender RImplementation; -ECORE_API CRender* Render = &RImplementation; +CRender RImplementation; +ECORE_API CRender* Render = &RImplementation; //--------------------- -IRenderFactory* RenderFactory = NULL; +IRenderFactory *RenderFactory = NULL; + //--------------------------------------------------------------------------- -CRender::CRender () +CRender::CRender() { - m_skinning = 0; + m_skinning = 0; } -CRender::~CRender () +CRender::~CRender() { - xr_delete (Target); + xr_delete(Target); } -void CRender::Initialize () +void CRender::Initialize() { - PSLibrary.OnCreate (); + PSLibrary.OnCreate(); } -void CRender::ShutDown () + +void CRender::ShutDown() { - PSLibrary.OnDestroy (); + PSLibrary.OnDestroy(); } -void CRender::OnDeviceCreate () +void CRender::OnDeviceCreate() { - Models = xr_new (); - Models->Logging (FALSE); + Models = xr_new(); + Models->Logging(FALSE); } -void CRender::OnDeviceDestroy () + +void CRender::OnDeviceDestroy() { - xr_delete (Models); + xr_delete(Models); } -ref_shader CRender::getShader (int id){ return 0; }//VERIFY(id(); + D->Load(F); + return D; +} + +IRenderVisual *CRender::model_CreatePE(LPCSTR name) +{ + PS::CPEDef *source = PSLibrary.FindPED(name); + return Models->CreatePE(source); +} + +IRenderVisual *CRender::model_CreateParticles(LPCSTR name) +{ + PS::CPEDef *SE = PSLibrary.FindPED(name); + if (SE) + return Models->CreatePE(SE); + else + { + PS::CPGDef *SG = PSLibrary.FindPGD(name); + return SG ? Models->CreatePG(SG) : 0; + } +} + +void CRender::rmNear() +{ + CRenderTarget *T = getTarget(); + D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0,0.02f}; + CHK_DX(HW.pDevice->SetViewport(&VP)); +} + +void CRender::rmFar() +{ + CRenderTarget *T = getTarget(); + D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0.99999f,1.f}; + CHK_DX(HW.pDevice->SetViewport(&VP)); +} + +void CRender::rmNormal() { + CRenderTarget *T = getTarget(); + D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0,1.f}; + CHK_DX(HW.pDevice->SetViewport(&VP)); } -IRender_DetailModel* CRender::model_CreateDM(IReader* F) +void CRender::set_Transform(Fmatrix *M) { - VERIFY (F); - CDetail* D = xr_new (); - D->Load (F); - return D; + current_matrix.set(*M); } -IRenderVisual* CRender::model_CreatePE(LPCSTR name) +void CRender::add_Visual(IRenderVisual *visual) { - PS::CPEDef* source = PSLibrary.FindPED (name); - return Models->CreatePE (source); + Models->RenderSingle(dynamic_cast(visual), current_matrix, 1.f); } -IRenderVisual* CRender::model_CreateParticles (LPCSTR name) +IRenderVisual *CRender::model_Create(LPCSTR name, IReader *data) { - PS::CPEDef* SE = PSLibrary.FindPED (name); - if (SE) return Models->CreatePE (SE); - else{ - PS::CPGDef* SG = PSLibrary.FindPGD (name); - return SG?Models->CreatePG (SG):0; - } + return Models->Create(name, data); } -void CRender::rmNear () +IRenderVisual *CRender::model_CreateChild(LPCSTR name, IReader *data) { - CRenderTarget* T = getTarget (); - D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0,0.02f }; - CHK_DX (HW.pDevice->SetViewport(&VP)); + return Models->CreateChild(name, data); } -void CRender::rmFar () + +void CRender::model_Delete(IRenderVisual * &V, BOOL bDiscard) { - CRenderTarget* T = getTarget (); - D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0.99999f,1.f }; - CHK_DX (HW.pDevice->SetViewport(&VP)); + Models->Delete(dynamic_cast(V), bDiscard); } -void CRender::rmNormal () + +IRenderVisual *CRender::model_Duplicate(IRenderVisual *V) { - CRenderTarget* T = getTarget (); - D3DVIEWPORT9 VP = {0,0,T->get_width(),T->get_height(),0,1.f }; - CHK_DX (HW.pDevice->SetViewport(&VP)); + return Models->Instance_Duplicate(dynamic_cast(V)); } -void CRender::set_Transform (Fmatrix* M) +void CRender::model_Render(IRenderVisual *m_pVisual, const Fmatrix &mTransform, int priority, bool strictB2F, float m_fLOD) { - current_matrix.set(*M); + Models->Render(dynamic_cast(m_pVisual), mTransform, priority, strictB2F, m_fLOD); } -void CRender::add_Visual (IRenderVisual* visual) { Models->RenderSingle (dynamic_cast(visual),current_matrix,1.f);} -IRenderVisual* CRender::model_Create (LPCSTR name, IReader* data) { return Models->Create(name,data); } -IRenderVisual* CRender::model_CreateChild (LPCSTR name, IReader* data) { return Models->CreateChild(name,data);} -void CRender::model_Delete (IRenderVisual* &V, BOOL bDiscard) { Models->Delete(dynamic_cast(V),bDiscard); } -IRenderVisual* CRender::model_Duplicate (IRenderVisual* V) { return Models->Instance_Duplicate(dynamic_cast(V)); } -void CRender::model_Render (IRenderVisual* m_pVisual, const Fmatrix& mTransform, int priority, bool strictB2F, float m_fLOD){Models->Render(dynamic_cast(m_pVisual), mTransform, priority, strictB2F, m_fLOD);} -void CRender::model_RenderSingle (IRenderVisual* m_pVisual, const Fmatrix& mTransform, float m_fLOD){Models->RenderSingle(dynamic_cast(m_pVisual), mTransform, m_fLOD);} +void CRender::model_RenderSingle(IRenderVisual *m_pVisual, const Fmatrix &mTransform, float m_fLOD) +{ + Models->RenderSingle(dynamic_cast(m_pVisual), mTransform, m_fLOD); +} //#pragma comment(lib,"d3dx_r1") -HRESULT CRender::CompileShader ( - LPCSTR pSrcData, - UINT SrcDataLen, - void* _pDefines, - void* _pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - void* _ppShader, - void* _ppErrorMsgs, - void* _ppConstantTable) -{ - CONST D3DXMACRO* pDefines = (CONST D3DXMACRO*) _pDefines; - LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE) _pInclude; - LPD3DXBUFFER* ppShader = (LPD3DXBUFFER*) _ppShader; - LPD3DXBUFFER* ppErrorMsgs = (LPD3DXBUFFER*) _ppErrorMsgs; - LPD3DXCONSTANTTABLE* ppConstantTable = (LPD3DXCONSTANTTABLE*)_ppConstantTable; - return D3DXCompileShader (pSrcData,SrcDataLen,pDefines,pInclude,pFunctionName,pTarget,Flags,ppShader,ppErrorMsgs,ppConstantTable); -} -HRESULT CRender::shader_compile ( - LPCSTR name, - LPCSTR pSrcData, - UINT SrcDataLen, - void* _pDefines, - void* _pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - void* _ppShader, - void* _ppErrorMsgs, - void* _ppConstantTable) -{ - D3DXMACRO defines [128]; - int def_it = 0; - CONST D3DXMACRO* pDefines = (CONST D3DXMACRO*) _pDefines; - if (pDefines) { - // transfer existing defines - for (;;def_it++) { - if (0==pDefines[def_it].Name) break; - defines[def_it] = pDefines[def_it]; - } - } - // options - if (m_skinning<0) { - defines[def_it].Name = "SKIN_NONE"; - defines[def_it].Definition = "1"; - def_it ++; - } - if (0==m_skinning) { - defines[def_it].Name = "SKIN_0"; - defines[def_it].Definition = "1"; - def_it ++; - } - if (1==m_skinning) { - defines[def_it].Name = "SKIN_1"; - defines[def_it].Definition = "1"; - def_it ++; - } - if (2==m_skinning) { - defines[def_it].Name = "SKIN_2"; - defines[def_it].Definition = "1"; - def_it ++; - } - // finish - defines[def_it].Name = 0; - defines[def_it].Definition = 0; - def_it ++; - - LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE) _pInclude; - LPD3DXBUFFER* ppShader = (LPD3DXBUFFER*) _ppShader; - LPD3DXBUFFER* ppErrorMsgs = (LPD3DXBUFFER*) _ppErrorMsgs; - LPD3DXCONSTANTTABLE* ppConstantTable = (LPD3DXCONSTANTTABLE*)_ppConstantTable; -//. return D3DXCompileShader (pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags,ppShader,ppErrorMsgs,ppConstantTable); +HRESULT CRender::CompileShader( + LPCSTR pSrcData, + UINT SrcDataLen, + void *_pDefines, + void *_pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + void *_ppShader, + void *_ppErrorMsgs, + void *_ppConstantTable) +{ + CONST D3DXMACRO* pDefines = (CONST + D3DXMACRO* + ) + _pDefines; + LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE) _pInclude; + LPD3DXBUFFER *ppShader = (LPD3DXBUFFER*) _ppShader; + LPD3DXBUFFER *ppErrorMsgs = (LPD3DXBUFFER*) _ppErrorMsgs; + LPD3DXCONSTANTTABLE *ppConstantTable = (LPD3DXCONSTANTTABLE*)_ppConstantTable; + return D3DXCompileShader(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pTarget, Flags, ppShader, ppErrorMsgs, ppConstantTable); +} + +HRESULT CRender::shader_compile( + LPCSTR name, + LPCSTR pSrcData, + UINT SrcDataLen, + void *_pDefines, + void *_pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + void *_ppShader, + void *_ppErrorMsgs, + void *_ppConstantTable) +{ + D3DXMACRO defines [128]; + int def_it = 0; + CONST D3DXMACRO* pDefines = (CONST + D3DXMACRO* + ) + _pDefines; + if (pDefines) + { + // transfer existing defines + for (;; def_it++) + { + if (0==pDefines[def_it].Name) + break; + defines[def_it] = pDefines[def_it]; + } + } + // options + if (m_skinning<0) + { + defines[def_it].Name = "SKIN_NONE"; + defines[def_it].Definition = "1"; + def_it ++; + } + if (0==m_skinning) + { + defines[def_it].Name = "SKIN_0"; + defines[def_it].Definition = "1"; + def_it ++; + } + if (1==m_skinning) + { + defines[def_it].Name = "SKIN_1"; + defines[def_it].Definition = "1"; + def_it ++; + } + if (2==m_skinning) + { + defines[def_it].Name = "SKIN_2"; + defines[def_it].Definition = "1"; + def_it ++; + } + // finish + defines[def_it].Name = 0; + defines[def_it].Definition = 0; + def_it ++; + + LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE) _pInclude; + LPD3DXBUFFER *ppShader = (LPD3DXBUFFER*) _ppShader; + LPD3DXBUFFER *ppErrorMsgs = (LPD3DXBUFFER*) _ppErrorMsgs; + LPD3DXCONSTANTTABLE *ppConstantTable = (LPD3DXCONSTANTTABLE*)_ppConstantTable; + //. return D3DXCompileShader (pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags,ppShader,ppErrorMsgs,ppConstantTable); #ifdef D3DXSHADER_USE_LEGACY_D3DX9_31_DLL // December 2006 and later + HRESULT _result = D3DXCompileShader(pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags|D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,ppShader,ppErrorMsgs,ppConstantTable); #else - HRESULT _result = D3DXCompileShader(pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags,ppShader,ppErrorMsgs,ppConstantTable); + HRESULT _result = D3DXCompileShader(pSrcData, SrcDataLen, defines, pInclude, pFunctionName, pTarget, Flags, ppShader, ppErrorMsgs, ppConstantTable); #endif - return _result; + return _result; } -void CRender::reset_begin () +void CRender::reset_begin() { - xr_delete (Target); + xr_delete(Target); } -void CRender::reset_end () + +void CRender::reset_end() { - Target = xr_new (); + Target = xr_new(); } diff --git a/src/editors/ECore/Editor/render.h b/src/editors/ECore/Editor/render.h index 16daaaccb5f..f19eaf4d337 100644 --- a/src/editors/ECore/Editor/render.h +++ b/src/editors/ECore/Editor/render.h @@ -2,156 +2,171 @@ #ifndef renderH #define renderH -#include "..\..\xrCDB\frustum.h" +#include "xrCDB\Frustum.h" #include "vis_common.h" -#include "..\..\Layers\xrRender\blenders\blender.h" -#include "..\..\Layers\xrRender\blenders\blender_clsid.h" -#include "..\..\Layers\xrRender\xrRender_console.h" -#include "..\..\Layers\xrRender\PSLibrary.h" -#include "..\..\Layers\xrRender\IRenderDetailModel.H" -#include "..\..\Layers\xrRender\DetailModel.H" -#include "..\..\Layers\xrRender\ModelPool.h" -#include "..\..\Layers\xrRender\SkeletonCustom.h" -#include "..\..\Include/xrAPI/xrAPI.h" +#include "Layers/xrRender/blenders/Blender.h" +#include "Layers/xrRender/blenders/Blender_CLSID.h" +#include "Layers/xrRender/xrRender_console.h" +#include "Layers/xrRender/PSLibrary.h" +#include "Layers/xrRender/IRenderDetailModel.H" +#include "Layers/xrRender/DetailModel.H" +#include "Layers/xrRender/ModelPool.h" +#include "Layers/xrRender/SkeletonCustom.h" +#include "Include/xrAPI/xrAPI.h" // definition (Renderer) class CRenderTarget /*:public IRender_Target*/ { public: - virtual u32 get_width () { return EDevice.dwWidth; } - virtual u32 get_height () { return EDevice.dwHeight; } + virtual u32 get_width() + { + return EDevice.dwWidth; + } + + virtual u32 get_height() + { + return EDevice.dwHeight; + } }; class IRender { public: - enum GenerationLevel - { - GENERATION_R1 = 81, - GENERATION_DX81 = 81, - GENERATION_R2 = 90, - GENERATION_DX90 = 90, - GENERATION_forcedword = u32(-1) - }; - // feature level - virtual GenerationLevel get_generation ()=0; + enum GenerationLevel + { + GENERATION_R1 = 81, + GENERATION_DX81 = 81, + GENERATION_R2 = 90, + GENERATION_DX90 = 90, + GENERATION_forcedword = u32(-1) + }; + + // feature level + virtual GenerationLevel get_generation() =0; }; -class ECORE_API CRender: public IRender +class ECORE_API CRender: + +public +IRender { - CRenderTarget* Target; - Fmatrix current_matrix; + CRenderTarget* Target; + Fmatrix current_matrix; -public: - // options - s32 m_skinning; + public: + // options + s32 m_skinning; - // Data - CFrustum ViewBase; - CPSLibrary PSLibrary; + // Data + CFrustum ViewBase; + CPSLibrary PSLibrary; - CModelPool* Models; -public: - // Occlusion culling - virtual BOOL occ_visible (Fbox& B); - virtual BOOL occ_visible (sPoly& P); - virtual BOOL occ_visible (vis_data& P); + CModelPool* Models; + public: + // Occlusion culling + virtual BOOL occ_visible (Fbox& B); + virtual BOOL occ_visible (sPoly& P); + virtual BOOL occ_visible (vis_data& P); - // Constructor/destructor - CRender (); - virtual ~CRender (); + // Constructor/destructor + CRender (); + virtual ~CRender (); - void shader_option_skinning (u32 mode) { m_skinning=mode; } + void shader_option_skinning (u32 mode) { m_skinning=mode; } - void Initialize (); - void ShutDown (); +void Initialize (); +void ShutDown (); - void OnDeviceCreate (); - void OnDeviceDestroy (); +void OnDeviceCreate (); +void OnDeviceDestroy (); - void Calculate (); - void Render (); +void Calculate (); +void Render (); - void set_Transform (Fmatrix* M); - void add_Visual (IRenderVisual* visual); +void set_Transform (Fmatrix* M); +void add_Visual (IRenderVisual* visual); - virtual ref_shader getShader (int id); - CRenderTarget* getTarget (){return Target;} +virtual ref_shader getShader (int id); +CRenderTarget* getTarget (){return Target;} //. virtual IRender_Target* getTarget (){return Target;} - void reset_begin (); - void reset_end (); - virtual IRenderVisual* model_Create (LPCSTR name, IReader* data=0); - virtual IRenderVisual* model_CreateChild (LPCSTR name, IReader* data); - virtual IRenderVisual* model_CreatePE (LPCSTR name); - virtual IRenderVisual* model_CreateParticles (LPCSTR name); +void reset_begin (); +void reset_end (); +virtual IRenderVisual* model_Create (LPCSTR name, IReader* data=0); +virtual IRenderVisual* model_CreateChild (LPCSTR name, IReader* data); +virtual IRenderVisual* model_CreatePE (LPCSTR name); +virtual IRenderVisual* model_CreateParticles (LPCSTR name); - virtual IRender_DetailModel* model_CreateDM (IReader* R); - virtual IRenderVisual* model_Duplicate (IRenderVisual* V); - virtual void model_Delete (IRenderVisual* & V, BOOL bDiscard=TRUE); - virtual void model_Delete (IRender_DetailModel* & F) +virtual IRender_DetailModel* model_CreateDM (IReader* R); +virtual IRenderVisual* model_Duplicate (IRenderVisual* V); +virtual void model_Delete (IRenderVisual* & V, BOOL bDiscard=TRUE); +virtual void model_Delete (IRender_DetailModel* & F) +{ + if (F) { - if (F) - { - CDetail* D = (CDetail*)F; - D->Unload (); - xr_delete (D); - F = NULL; - } - } - void model_Render (IRenderVisual* m_pVisual, const Fmatrix& mTransform, int priority, bool strictB2F, float m_fLOD); - void model_RenderSingle (IRenderVisual* m_pVisual, const Fmatrix& mTransform, float m_fLOD); - virtual GenerationLevel get_generation (){return GENERATION_R1;} - virtual bool is_sun_static () {return true;}; - - virtual void add_SkeletonWallmark (intrusive_ptr wm){}; - virtual void add_SkeletonWallmark (const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size){}; - - // Render mode - virtual void rmNear (); - virtual void rmFar (); - virtual void rmNormal (); - - void apply_lmaterial (){} - - virtual LPCSTR getShaderPath (){return "R1\\";} - - virtual HRESULT CompileShader ( - LPCSTR pSrcData, - UINT SrcDataLen, - void* pDefines, - void* pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - void* ppShader, - void* ppErrorMsgs, - void* ppConstantTable); - - virtual IDirect3DBaseTexture9* texture_load (LPCSTR fname, u32& mem_size); - virtual HRESULT shader_compile ( - LPCSTR name, - LPCSTR pSrcData, - UINT SrcDataLen, - void* pDefines, - void* pInclude, - LPCSTR pFunctionName, - LPCSTR pTarget, - DWORD Flags, - void* ppShader, - void* ppErrorMsgs, - void* ppConstantTable); + CDetail* D = (CDetail*)F; + D->Unload (); + xr_delete (D); + F = NULL; +} +} +void model_Render (IRenderVisual* m_pVisual, const Fmatrix& mTransform, int priority, bool strictB2F, float m_fLOD); +void model_RenderSingle (IRenderVisual* m_pVisual, const Fmatrix& mTransform, float m_fLOD); +virtual GenerationLevel get_generation (){return GENERATION_R1;} +virtual bool is_sun_static () {return true;}; + +virtual void add_SkeletonWallmark (intrusive_ptr wm){}; +virtual void add_SkeletonWallmark (const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size){}; + +// Render mode +virtual void rmNear (); +virtual void rmFar (); +virtual void rmNormal (); + +void apply_lmaterial (){} + +virtual LPCSTR getShaderPath (){return "R1\\";} + +virtual HRESULT CompileShader ( + LPCSTR pSrcData, + UINT SrcDataLen, + void* pDefines, + void* pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + void* ppShader, + void* ppErrorMsgs, + void* ppConstantTable); + +virtual IDirect3DBaseTexture9* texture_load (LPCSTR fname, u32& mem_size); +virtual HRESULT shader_compile ( + LPCSTR name, + LPCSTR pSrcData, + UINT SrcDataLen, + void* pDefines, + void* pInclude, + LPCSTR pFunctionName, + LPCSTR pTarget, + DWORD Flags, + void* ppShader, + void* ppErrorMsgs, + void* ppConstantTable); }; -IC float CalcSSA(Fvector& C, float R) +IC + +float CalcSSA(Fvector &C, float R) { - float distSQ = EDevice.m_Camera.GetPosition().distance_to_sqr(C); - return R*R/distSQ; + float distSQ = EDevice.m_Camera.GetPosition().distance_to_sqr(C); + return R*R/distSQ; } -extern ECORE_API CRender RImplementation; + +extern ECORE_API CRender RImplementation; //.extern ECORE_API CRender* Render; #endif + diff --git a/src/editors/ECore/Editor/ui_main.cpp b/src/editors/ECore/Editor/ui_main.cpp index 4b66e1a6572..5ed1da1d872 100644 --- a/src/editors/ECore/Editor/ui_main.cpp +++ b/src/editors/ECore/Editor/ui_main.cpp @@ -3,128 +3,148 @@ #include "stdafx.h" #pragma hdrstop -#include "xr_input.h" +#include "xrEngine/xr_input.h" #include "UI_ToolsCustom.h" #include "UI_Main.h" -#include "d3dutils.h" +#include "D3DUtils.h" #include "SoundManager.h" -#include "PSLibrary.h" +#include "Layers/xrRender/PSLibrary.h" #include "ImageEditor.h" #include "SoundEditor.h" -#include "ChoseForm.h" -#include "ETools.h" +#include "editors/xrEProps/ChoseForm.h" +#include "utils/ETools/ETools.h" -TUI* UI = 0; +TUI *UI = 0; TUI::TUI() { - UI = this; - m_bAppActive = false; - m_bReady = false; - m_D3DWindow = 0; - m_D3DPanel = 0; - bNeedAbort = false; + UI = this; + m_bAppActive = false; + m_bReady = false; + m_D3DWindow = 0; + m_D3DPanel = 0; + bNeedAbort = false; - m_CurrentRStart.set(0,0,0); - m_CurrentRDir.set(0,0,0); + m_CurrentRStart.set(0, 0, 0); + m_CurrentRDir.set(0, 0, 0); - m_Flags.assign (flResize); + m_Flags.assign(flResize); - m_Pivot.set ( 0, 0, 0 ); + m_Pivot.set(0, 0, 0); - m_MouseCaptured = false; + m_MouseCaptured = false; m_MouseMultiClickCaptured = false; - m_SelectionRect = false; - bMouseInUse = false; + m_SelectionRect = false; + bMouseInUse = false; - m_bHintShowing = false; - m_pHintWindow = 0; - m_LastHint = ""; + m_bHintShowing = false; + m_pHintWindow = 0; + m_LastHint = ""; } + //--------------------------------------------------------------------------- TUI::~TUI() { - VERIFY(m_ProgressItems.size()==0); + VERIFY(m_ProgressItems.size()==0); VERIFY(m_EditorState.size()==0); } void TUI::OnDeviceCreate() { - DU_impl.OnDeviceCreate(); + DU_impl.OnDeviceCreate(); } void TUI::OnDeviceDestroy() { - DU_impl.OnDeviceDestroy(); + DU_impl.OnDeviceDestroy(); } bool TUI::IsModified() { - return ExecCommand(COMMAND_CHECK_MODIFIED); + return ExecCommand(COMMAND_CHECK_MODIFIED); } + //--------------------------------------------------------------------------- -void TUI::EnableSelectionRect( bool flag ){ - m_SelectionRect = flag; - m_SelEnd.x = m_SelStart.x = 0; - m_SelEnd.y = m_SelStart.y = 0; +void TUI::EnableSelectionRect(bool flag) +{ + m_SelectionRect = flag; + m_SelEnd.x = m_SelStart.x = 0; + m_SelEnd.y = m_SelStart.y = 0; } -void TUI::UpdateSelectionRect( const Ivector2& from, const Ivector2& to ){ - m_SelStart.set(from); - m_SelEnd.set(to); +void TUI::UpdateSelectionRect(const Ivector2 &from, const Ivector2 &to) +{ + m_SelStart.set(from); + m_SelEnd.set(to); } -bool __fastcall TUI::KeyDown (WORD Key, TShiftState Shift) +bool __fastcall TUI::KeyDown(WORD Key, TShiftState Shift) { - if (!m_bReady) return false; -// m_ShiftState = Shift; -// Log("Dn ",Shift.Contains(ssShift)?"1":"0"); - if (EDevice.m_Camera.KeyDown(Key,Shift)) return true; + if (!m_bReady) + return false; + // m_ShiftState = Shift; + // Log("Dn ",Shift.Contains(ssShift)?"1":"0"); + if (EDevice.m_Camera.KeyDown(Key, Shift)) + return true; return Tools->KeyDown(Key, Shift); } -bool __fastcall TUI::KeyUp (WORD Key, TShiftState Shift) +bool __fastcall TUI::KeyUp(WORD Key, TShiftState Shift) { - if (!m_bReady) return false; -// m_ShiftState = Shift; - if (EDevice.m_Camera.KeyUp(Key,Shift)) return true; + if (!m_bReady) + return false; + // m_ShiftState = Shift; + if (EDevice.m_Camera.KeyUp(Key, Shift)) + return true; return Tools->KeyUp(Key, Shift); } bool __fastcall TUI::KeyPress(WORD Key, TShiftState Shift) { - if (!m_bReady) return false; + if (!m_bReady) + return false; return Tools->KeyPress(Key, Shift); } + //---------------------------------------------------- void TUI::MousePress(TShiftState Shift, int X, int Y) { - if (!m_bReady) return; - if (m_MouseCaptured) return; + if (!m_bReady) + return; + if (m_MouseCaptured) + return; bMouseInUse = true; m_ShiftState = Shift; // camera activate - if(!EDevice.m_Camera.MoveStart(m_ShiftState)){ - if (Tools->Pick(Shift)) return; - if( !m_MouseCaptured ){ - if( Tools->HiddenMode() ){ - IR_GetMousePosScreen(m_StartCpH); - m_DeltaCpH.set(0,0); - }else{ + if (!EDevice.m_Camera.MoveStart(m_ShiftState)) + { + if (Tools->Pick(Shift)) + return; + if (!m_MouseCaptured) + { + if (Tools->HiddenMode()) + { + IR_GetMousePosScreen(m_StartCpH); + m_DeltaCpH.set(0, 0); + } + else + { IR_GetMousePosReal(EDevice.m_hRenderWnd, m_CurrentCp); m_StartCp = m_CurrentCp; - EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart, m_CurrentRDir, m_CurrentCp ); + EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart, m_CurrentRDir, m_CurrentCp); } - if(Tools->MouseStart(m_ShiftState)){ - if(Tools->HiddenMode()) ShowCursor( FALSE ); + if (Tools->MouseStart(m_ShiftState)) + { + if (Tools->HiddenMode()) + ShowCursor(FALSE); m_MouseCaptured = true; } } @@ -134,475 +154,583 @@ void TUI::MousePress(TShiftState Shift, int X, int Y) void TUI::MouseRelease(TShiftState Shift, int X, int Y) { - if (!m_bReady) return; + if (!m_bReady) + return; m_ShiftState = Shift; - if( EDevice.m_Camera.IsMoving() ){ - if (EDevice.m_Camera.MoveEnd(m_ShiftState)) bMouseInUse = false; - }else{ - bMouseInUse = false; - if( m_MouseCaptured ){ - if( !Tools->HiddenMode() ){ + if (EDevice.m_Camera.IsMoving()) + { + if (EDevice.m_Camera.MoveEnd(m_ShiftState)) + bMouseInUse = false; + } + else + { + bMouseInUse = false; + if (m_MouseCaptured) + { + if (!Tools->HiddenMode()) + { IR_GetMousePosReal(EDevice.m_hRenderWnd, m_CurrentCp); - EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart,m_CurrentRDir,m_CurrentCp ); + EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart, m_CurrentRDir, m_CurrentCp); } - if( Tools->MouseEnd(m_ShiftState) ){ - if( Tools->HiddenMode() ){ - SetCursorPos(m_StartCpH.x,m_StartCpH.y); - ShowCursor( TRUE ); + if (Tools->MouseEnd(m_ShiftState)) + { + if (Tools->HiddenMode()) + { + SetCursorPos(m_StartCpH.x, m_StartCpH.y); + ShowCursor(TRUE); } m_MouseCaptured = false; } } } // update tools (change action) - Tools->OnFrame (); - RedrawScene (); + Tools->OnFrame(); + RedrawScene(); } + //---------------------------------------------------- void TUI::MouseMove(TShiftState Shift, int X, int Y) { - if (!m_bReady) return; + if (!m_bReady) + return; m_ShiftState = Shift; } + //---------------------------------------------------- -void TUI::IR_OnMouseMove(int x, int y){ - if (!m_bReady) return; +void TUI::IR_OnMouseMove(int x, int y) +{ + if (!m_bReady) + return; bool bRayUpdated = false; - if (!EDevice.m_Camera.Process(m_ShiftState,x,y)){ - if( m_MouseCaptured || m_MouseMultiClickCaptured ){ - if( Tools->HiddenMode() ){ - m_DeltaCpH.set(x,y); - if( m_DeltaCpH.x || m_DeltaCpH.y ){ - Tools->MouseMove(m_ShiftState); + if (!EDevice.m_Camera.Process(m_ShiftState, x, y)) + { + if (m_MouseCaptured||m_MouseMultiClickCaptured) + { + if (Tools->HiddenMode()) + { + m_DeltaCpH.set(x, y); + if (m_DeltaCpH.x||m_DeltaCpH.y) + { + Tools->MouseMove(m_ShiftState); } - }else{ + } + else + { IR_GetMousePosReal(EDevice.m_hRenderWnd, m_CurrentCp); - EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart,m_CurrentRDir,m_CurrentCp); + EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart, m_CurrentRDir, m_CurrentCp); Tools->MouseMove(m_ShiftState); } - RedrawScene(); + RedrawScene(); bRayUpdated = true; } } - if (!bRayUpdated){ - IR_GetMousePosReal(EDevice.m_hRenderWnd, m_CurrentCp); - EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart,m_CurrentRDir,m_CurrentCp); + if (!bRayUpdated) + { + IR_GetMousePosReal(EDevice.m_hRenderWnd, m_CurrentCp); + EDevice.m_Camera.MouseRayFromPoint(m_CurrentRStart, m_CurrentRDir, m_CurrentCp); } // Out cursor pos - OutUICursorPos (); + OutUICursorPos(); } + //--------------------------------------------------------------------------- void TUI::OnAppActivate() { - VERIFY(m_bReady); - if (pInput){ + VERIFY(m_bReady); + if (pInput) + { m_ShiftState.Clear(); - pInput->OnAppActivate(); - EDevice.seqAppActivate.Process (rp_AppActivate); + pInput->OnAppActivate(); + EDevice.seqAppActivate.Process(rp_AppActivate); } - m_bAppActive = true; + m_bAppActive = true; } + //--------------------------------------------------------------------------- void TUI::OnAppDeactivate() { - VERIFY(m_bReady); - if (pInput){ - pInput->OnAppDeactivate(); + VERIFY(m_bReady); + if (pInput) + { + pInput->OnAppDeactivate(); m_ShiftState.Clear(); EDevice.seqAppDeactivate.Process(rp_AppDeactivate); } HideHint(); - m_bAppActive = false; + m_bAppActive = false; } + //--------------------------------------------------------------------------- -bool TUI::ShowHint(const AStringVec& SS) +bool TUI::ShowHint(const AStringVec &SS) { - VERIFY(m_bReady); - if (SS.size()){ - AnsiString S=_ListToSequence2(SS); - if (m_bHintShowing&&(S==m_LastHint)) return true; + VERIFY(m_bReady); + if (SS.size()) + { + AnsiString S = _ListToSequence2(SS); + if (m_bHintShowing&&(S==m_LastHint)) + return true; m_LastHint = S; m_bHintShowing = true; - if (!m_pHintWindow){ + if (!m_pHintWindow) + { m_pHintWindow = xr_new((TComponent*)0); m_pHintWindow->Brush->Color = (TColor)0x0d9F2FF; } - TRect rect = m_pHintWindow->CalcHintRect(320,S,0); - rect.Left+=m_HintPoint.x; rect.Top+=m_HintPoint.y; - rect.Right+=m_HintPoint.x; rect.Bottom+=m_HintPoint.y; - m_pHintWindow->ActivateHint(rect,S); - }else{ - m_bHintShowing = false; + TRect rect = m_pHintWindow->CalcHintRect(320, S, 0); + rect.Left += m_HintPoint.x; + rect.Top += m_HintPoint.y; + rect.Right += m_HintPoint.x; + rect.Bottom += m_HintPoint.y; + m_pHintWindow->ActivateHint(rect, S); + } + else + { + m_bHintShowing = false; m_LastHint = ""; } return m_bHintShowing; } + //--------------------------------------------------------------------------- void TUI::HideHint() { - VERIFY(m_bReady); + VERIFY(m_bReady); m_bHintShowing = false; xr_delete(m_pHintWindow); } + //--------------------------------------------------------------------------- -void TUI::ShowHint(const AnsiString& s) +void TUI::ShowHint(const AnsiString &s) { - VERIFY (m_bReady); - GetCursorPos (&m_HintPoint); - AStringVec SS; - SS.push_back (s); - Tools->OnShowHint(SS); - if (!ShowHint(SS)&&m_pHintWindow) HideHint(); + VERIFY(m_bReady); + GetCursorPos(&m_HintPoint); + AStringVec SS; + SS.push_back(s); + Tools->OnShowHint(SS); + if (!ShowHint(SS)&&m_pHintWindow) + HideHint(); } + //--------------------------------------------------------------------------- void TUI::ShowObjectHint() { - VERIFY(m_bReady); - if (!EPrefs->object_flags.is(epoShowHint)){ -// if (m_bHintShowing) HideHint(); - return; + VERIFY(m_bReady); + if (!EPrefs->object_flags.is(epoShowHint)) + { + // if (m_bHintShowing) HideHint(); + return; } - if (EDevice.m_Camera.IsMoving()||m_MouseCaptured) return; - if (!m_bAppActive) return; + if (EDevice.m_Camera.IsMoving()||m_MouseCaptured) + return; + if (!m_bAppActive) + return; GetCursorPos(&m_HintPoint); - TWinControl* ctr = FindVCLWindow(m_HintPoint); - if (ctr!=m_D3DWindow) return; + TWinControl *ctr = FindVCLWindow(m_HintPoint); + if (ctr!=m_D3DWindow) + return; - AStringVec SS; - Tools->OnShowHint(SS); - if (!ShowHint(SS)&&m_pHintWindow) HideHint(); + AStringVec SS; + Tools->OnShowHint(SS); + if (!ShowHint(SS)&&m_pHintWindow) + HideHint(); } + //--------------------------------------------------------------------------- -void TUI::CheckWindowPos(TForm* form) +void TUI::CheckWindowPos(TForm *form) { - if (form->Left+form->Width>Screen->Width) form->Left = Screen->Width-form->Width; - if (form->Top+form->Height>Screen->Height) form->Top = Screen->Height-form->Height; - if (form->Left<0) form->Left = 0; - if (form->Top<0) form->Top = 0; + if (form->Left+form->Width>Screen->Width) + form->Left = Screen->Width-form->Width; + if (form->Top+form->Height>Screen->Height) + form->Top = Screen->Height-form->Height; + if (form->Left<0) + form->Left = 0; + if (form->Top<0) + form->Top = 0; } + //--------------------------------------------------------------------------- -#include "igame_persistent.h" +#include "xrEngine/IGame_Persistent.h" #include "environment.h" void TUI::PrepareRedraw() { - VERIFY(m_bReady); - if (m_Flags.is(flResize)) RealResize(); -// set render state - EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); + VERIFY(m_bReady); + if (m_Flags.is(flResize)) + RealResize(); + // set render state + EDevice.SetRS(D3DRS_TEXTUREFACTOR, 0xffffffff); // fog u32 fog_color; - float fog_start, fog_end; - Tools->GetCurrentFog (fog_color, fog_start, fog_end); -/* - if (0==g_pGamePersistent->Environment().GetWeather().size()) + float fog_start, fog_end; + Tools->GetCurrentFog(fog_color, fog_start, fog_end); + /* + if (0==g_pGamePersistent->Environment().GetWeather().size()) + { + g_pGamePersistent->Environment().CurrentEnv->fog_color.set (color_get_R(fog_color),color_get_G(fog_color),color_get_B(fog_color)); + g_pGamePersistent->Environment().CurrentEnv->fog_far = fog_end; + g_pGamePersistent->Environment().CurrentEnv->fog_near = fog_start; + } + */ + EDevice.SetRS(D3DRS_FOGCOLOR, fog_color); + EDevice.SetRS(D3DRS_RANGEFOGENABLE, FALSE); + if (HW.Caps.bTableFog) + { + EDevice.SetRS(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR); + EDevice.SetRS(D3DRS_FOGVERTEXMODE, D3DFOG_NONE); + } + else { - g_pGamePersistent->Environment().CurrentEnv->fog_color.set (color_get_R(fog_color),color_get_G(fog_color),color_get_B(fog_color)); - g_pGamePersistent->Environment().CurrentEnv->fog_far = fog_end; - g_pGamePersistent->Environment().CurrentEnv->fog_near = fog_start; + EDevice.SetRS(D3DRS_FOGTABLEMODE, D3DFOG_NONE); + EDevice.SetRS(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); } -*/ - EDevice.SetRS( D3DRS_FOGCOLOR, fog_color ); - EDevice.SetRS( D3DRS_RANGEFOGENABLE, FALSE ); - if (HW.Caps.bTableFog) { - EDevice.SetRS( D3DRS_FOGTABLEMODE, D3DFOG_LINEAR ); - EDevice.SetRS( D3DRS_FOGVERTEXMODE, D3DFOG_NONE ); - } else { - EDevice.SetRS( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); - EDevice.SetRS( D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR ); - } - EDevice.SetRS( D3DRS_FOGSTART, *(DWORD *)(&fog_start) ); - EDevice.SetRS( D3DRS_FOGEND, *(DWORD *)(&fog_end) ); + EDevice.SetRS(D3DRS_FOGSTART, *(DWORD *)(&fog_start)); + EDevice.SetRS(D3DRS_FOGEND, *(DWORD *)(&fog_end)); // filter - for (u32 k=0; kRenderDUMP_RT.Begin(); - if (EDevice.Begin()){ - EDevice.UpdateView (); - EDevice.ResetMaterial (); + PrepareRedraw(); + try + { + EDevice.Statistic->RenderDUMP_RT.Begin(); + if (EDevice.Begin()) + { + EDevice.UpdateView(); + EDevice.ResetMaterial(); - Tools->RenderEnvironment (); + Tools->RenderEnvironment(); //. temporary reset filter ( ) - for (u32 k=0; kRender (); - }catch(...){ - ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type B]"); + try + { + Tools->Render(); + } catch (...) + { + ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type B]"); } // draw selection rect - if(m_SelectionRect) DU_impl.DrawSelectionRect(m_SelStart,m_SelEnd); + if (m_SelectionRect) + DU_impl.DrawSelectionRect(m_SelStart, m_SelEnd); // draw axis DU_impl.DrawAxis(EDevice.m_Camera.GetTransform()); - try{ - // end draw - EDevice.End(); - }catch(...){ - ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type C]"); + try + { + // end draw + EDevice.End(); + } catch (...) + { + ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type C]"); } } - EDevice.Statistic->RenderDUMP_RT.End(); - }catch(...){ - ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type A]"); -// _clear87(); -// FPU::m24r(); -// ELog.DlgMsg(mtError, "Critical error has occured in render routine.\nEditor may work incorrectly."); + EDevice.Statistic->RenderDUMP_RT.End(); + } catch (...) + { + ELog.DlgMsg(mtError, "Please notify AlexMX!!! Critical error has occured in render routine!!! [Type A]"); + // _clear87(); + // FPU::m24r(); + // ELog.DlgMsg(mtError, "Critical error has occured in render routine.\nEditor may work incorrectly."); EDevice.End(); -// EDevice.Resize(m_D3DWindow->Width,m_D3DWindow->Height); + // EDevice.Resize(m_D3DWindow->Width,m_D3DWindow->Height); } - OutInfo(); + OutInfo(); } + //--------------------------------------------------------------------------- void TUI::RealResize() { - EDevice.Resize (m_D3DWindow->Width,m_D3DWindow->Height); - m_Flags.set (flResize,FALSE); - ExecCommand (COMMAND_UPDATE_PROPERTIES); + EDevice.Resize(m_D3DWindow->Width, m_D3DWindow->Height); + m_Flags.set(flResize, FALSE); + ExecCommand(COMMAND_UPDATE_PROPERTIES); } + void TUI::RealUpdateScene() { - Tools->UpdateProperties (false); - m_Flags.set (flUpdateScene,FALSE); + Tools->UpdateProperties(false); + m_Flags.set(flUpdateScene, FALSE); } + void TUI::RealRedrawScene() { - if (!psDeviceFlags.is(rsRenderRealTime)) - m_Flags.set (flRedraw,FALSE); - Redraw (); + if (!psDeviceFlags.is(rsRenderRealTime)) + m_Flags.set(flRedraw, FALSE); + Redraw(); } + void TUI::OnFrame() { - EDevice.FrameMove (); - SndLib->OnFrame (); + EDevice.FrameMove(); + SndLib->OnFrame(); // tools on frame - if (m_Flags.is(flUpdateScene)) RealUpdateScene(); - Tools->OnFrame (); - // show hint - ShowObjectHint (); - ResetBreak (); - // check mail - CheckMailslot (); + if (m_Flags.is(flUpdateScene)) + RealUpdateScene(); + Tools->OnFrame(); + // show hint + ShowObjectHint(); + ResetBreak(); + // check mail + CheckMailslot(); // OnFrame TfrmImageLib::OnFrame(); TfrmSoundLib::OnFrame(); TfrmChoseItem::OnFrame(); // Progress - ProgressDraw (); + ProgressDraw(); } -void TUI::Idle() + +void TUI::Idle() { - VERIFY(m_bReady); - EDevice.b_is_Active = Application->Active; - // input + VERIFY(m_bReady); + EDevice.b_is_Active = Application->Active; + // input pInput->OnFrame(); Sleep(1); - if (ELog.in_use) return; + if (ELog.in_use) + return; - OnFrame (); - if (m_Flags.is(flRedraw)) RealRedrawScene(); + OnFrame(); + if (m_Flags.is(flRedraw)) + RealRedrawScene(); // test quit - if (m_Flags.is(flNeedQuit)) RealQuit(); + if (m_Flags.is(flNeedQuit)) + RealQuit(); } + //--------------------------------------------------------------------------- void ResetActionToSelect() { ExecCommand(COMMAND_CHANGE_ACTION, etaSelect); } + //--------------------------------------------------------------------------- #define MIN_PANEL_HEIGHT 15 + void __fastcall PanelMinMax(TPanel *pa) { - if (pa&&(pa->Align!=alClient)){ - if (pa->Tag > 0){ + if (pa&&(pa->Align!=alClient)) + { + if (pa->Tag>0) + { pa->Height = pa->Tag; - pa->Tag = 0; - }else{ - pa->Tag = pa->Height; + pa->Tag = 0; + } + else + { + pa->Tag = pa->Height; pa->Height = MIN_PANEL_HEIGHT; } ExecCommand(COMMAND_UPDATE_TOOLBAR); } } + void __fastcall PanelMinimize(TPanel *pa) { - if (pa&&(pa->Align!=alClient)){ - if (pa->Tag <= 0){ - pa->Tag = pa->Height; + if (pa&&(pa->Align!=alClient)) + { + if (pa->Tag<=0) + { + pa->Tag = pa->Height; pa->Height = MIN_PANEL_HEIGHT; } ExecCommand(COMMAND_UPDATE_TOOLBAR); } } + void __fastcall PanelMaximize(TPanel *pa) { - if (pa&&(pa->Align!=alClient)){ - if (pa->Tag > 0){ + if (pa&&(pa->Align!=alClient)) + { + if (pa->Tag>0) + { pa->Height = pa->Tag; - pa->Tag = 0; + pa->Tag = 0; } ExecCommand(COMMAND_UPDATE_TOOLBAR); } } -void __fastcall PanelMinMaxClick(TObject* Sender) + +void __fastcall PanelMinMaxClick(TObject *Sender) { PanelMinMax(((TPanel*)((TControl*)Sender)->Parent)); } -void __fastcall PanelMinimizeClick(TObject* Sender) + +void __fastcall PanelMinimizeClick(TObject *Sender) { PanelMinimize(((TPanel*)((TControl*)Sender)->Parent)); } -void __fastcall PanelMaximizeClick(TObject* Sender) + +void __fastcall PanelMaximizeClick(TObject *Sender) { PanelMaximize(((TPanel*)((TControl*)Sender)->Parent)); } + //--------------------------------------------------------------------------- -bool TUI::OnCreate(TD3DWindow* w, TPanel* p) +bool TUI::OnCreate(TD3DWindow *w, TPanel *p) { -// create base class - EDevice.InitTimer(); + // create base class + EDevice.InitTimer(); - m_D3DWindow = w; - m_D3DPanel = p; + m_D3DWindow = w; + m_D3DPanel = p; VERIFY(m_D3DWindow); EDevice.Initialize(); - - // Creation - ETOOLS::ray_options (CDB::OPT_ONLYNEAREST | CDB::OPT_CULL); - pInput = xr_new(FALSE,mouse_device_key); - UI->IR_Capture (); + // Creation + ETOOLS::ray_options(CDB::OPT_ONLYNEAREST|CDB::OPT_CULL); - m_bReady = true; + pInput = xr_new(FALSE, mouse_device_key); + UI->IR_Capture(); - if (!CreateMailslot()){ - ELog.DlgMsg (mtError,"Can't create mail slot.\nIt's possible two Editors started."); - return false; + m_bReady = true; + + if (!CreateMailslot()) + { + ELog.DlgMsg(mtError, "Can't create mail slot.\nIt's possible two Editors started."); + return false; } - if (!FS.path_exist(_local_root_)){ - ELog.DlgMsg (mtError,"Undefined Editor local directory."); - return false; + if (!FS.path_exist(_local_root_)) + { + ELog.DlgMsg(mtError, "Undefined Editor local directory."); + return false; } - BeginEState (esEditScene); + BeginEState(esEditScene); return true; } void TUI::OnDestroy() { - VERIFY(m_bReady); - m_bReady = false; - UI->IR_Release (); - xr_delete (pInput); - EndEState (); + VERIFY(m_bReady); + m_bReady = false; + UI->IR_Release(); + xr_delete(pInput); + EndEState(); - EDevice.ShutDown (); - + EDevice.ShutDown(); } -SPBItem* TUI::ProgressStart (float max_val, LPCSTR text) +SPBItem *TUI::ProgressStart(float max_val, LPCSTR text) { - VERIFY(m_bReady); - SPBItem* item = xr_new(text,"",max_val); - m_ProgressItems.push_back (item); - ELog.Msg (mtInformation,text); - ProgressDraw (); - return item; + VERIFY(m_bReady); + SPBItem*item = xr_new(text,"",max_val); + m_ProgressItems.push_back(item); + ELog.Msg(mtInformation, text); + ProgressDraw(); + return item; } -void TUI::ProgressEnd (SPBItem*& pbi) + +void TUI::ProgressEnd(SPBItem *&pbi) { - VERIFY(m_bReady); - if (pbi){ - PBVecIt it=std::find(m_ProgressItems.begin(),m_ProgressItems.end(),pbi); VERIFY(it!=m_ProgressItems.end()); - m_ProgressItems.erase (it); - xr_delete (pbi); - ProgressDraw (); + VERIFY(m_bReady); + if (pbi) + { + PBVecIt it = std::find(m_ProgressItems.begin(), m_ProgressItems.end(), pbi); + VERIFY(it!=m_ProgressItems.end()); + m_ProgressItems.erase(it); + xr_delete(pbi); + ProgressDraw(); } } -void SPBItem::GetInfo (AnsiString& txt, float& p, float& m) +void SPBItem::GetInfo(AnsiString &txt, float &p, float &m) { - if (info.size())txt.sprintf("%s (%s)",text.c_str(),info.c_str()); - else txt.sprintf("%s",text.c_str()); - p = progress; - m = max; -} -void SPBItem::Inc (LPCSTR info, bool bWarn) + if (info.size()) + txt.sprintf("%s (%s)", text.c_str(), info.c_str()); + else + txt.sprintf("%s", text.c_str()); + p = progress; + m = max; +} + +void SPBItem::Inc(LPCSTR info, bool bWarn) { - Info (info,bWarn); - Update (progress+1.f); + Info(info, bWarn); + Update(progress+1.f); } -void SPBItem::Update (float val) + +void SPBItem::Update(float val) { - progress = val; - UI->ProgressDraw (); + progress = val; + UI->ProgressDraw(); } -void SPBItem::Info (LPCSTR text, bool bWarn) + +void SPBItem::Info(LPCSTR text, bool bWarn) { - if (text&&text[0]){ - info = text; - AnsiString txt; - float p,m; - GetInfo (txt,p,m); - ELog.Msg (bWarn?mtError:mtInformation,txt.c_str()); - UI->ProgressDraw (); + if (text&&text[0]) + { + info = text; + AnsiString txt; + float p, m; + GetInfo(txt, p, m); + ELog.Msg(bWarn ? mtError : mtInformation, txt.c_str()); + UI->ProgressDraw(); } } diff --git a/src/editors/ECore/Editor/ui_main.h b/src/editors/ECore/Editor/ui_main.h index 39ccf48cb5a..e7928b16b5c 100644 --- a/src/editors/ECore/Editor/ui_main.h +++ b/src/editors/ECore/Editor/ui_main.h @@ -11,10 +11,12 @@ class CCustomObject; class TUI_Tools; class TUI_Tools; class C3DCursor; + //------------------------------------------------------------------------------ -enum EEditorState{ - esNone, +enum EEditorState +{ + esNone, esEditScene, esEditLibrary, esEditLightAnim, @@ -22,223 +24,234 @@ enum EEditorState{ }; struct ECORE_API SPBItem{ - shared_str text; - shared_str info; - float max; - float progress; -public: - SPBItem (LPCSTR txt, LPCSTR inf, float mx):text(txt),info(inf),max(mx),progress(0.f){} - void GetInfo (AnsiString& txt, float& p, float& m); - void Inc (LPCSTR info=0, bool bWarn=false); - void Update (float val); - void Info (LPCSTR text, bool bWarn=false); + shared_str text; + shared_str info; + float max; + float progress; + public: + SPBItem(LPCSTR txt, LPCSTR inf, float mx):text(txt),info(inf),max(mx),progress(0.f){} + void GetInfo(AnsiString&txt, float& p, float& m); + void Inc(LPCSTR info = 0, bool bWarn = false); + void Update(float val); + void Info(LPCSTR text, bool bWarn = false); }; typedef xr_vector EStateList; typedef EStateList::iterator EStateIt; -class ECORE_API TUI: public IInputReceiver{ -protected: +class ECORE_API TUI: + +public +IInputReceiver +{ + protected: friend class CCustomPreferences; friend class CEditorRenderDevice; TD3DWindow* m_D3DWindow; - TPanel* m_D3DPanel; + TPanel* m_D3DPanel; TShiftState m_ShiftState; bool m_bAppActive; -protected: + protected: EStateList m_EditorState; bool bNeedAbort; -public: - bool m_bReady; + public: + bool m_bReady; TD3DWindow* GetD3DWindow(){return m_D3DWindow;} protected: - Fvector m_Pivot; +Fvector m_Pivot; protected: - bool m_SelectionRect; - Ivector2 m_SelStart; - Ivector2 m_SelEnd; +bool m_SelectionRect; +Ivector2 m_SelStart; +Ivector2 m_SelEnd; protected: - enum{ - flRedraw = (1<<0), - flUpdateScene = (1<<1), - flResize = (1<<2), - flNeedQuit = (1<<3), - }; - Flags32 m_Flags; +enum{ + flRedraw = (1<<0), + flUpdateScene = (1<<1), + flResize = (1<<2), + flNeedQuit = (1<<3), +}; +Flags32 m_Flags; protected: - long m_StartTime; +long m_StartTime; - void PrepareRedraw (); - void Redraw (); +void PrepareRedraw (); +void Redraw (); protected: - void D3D_CreateStateBlocks(); - void D3D_DestroyStateBlocks(); +void D3D_CreateStateBlocks(); +void D3D_DestroyStateBlocks(); public: - virtual void OutUICursorPos ()=0; - virtual void OutGridSize ()=0; - virtual void OutInfo ()=0; +virtual void OutUICursorPos ()=0; +virtual void OutGridSize ()=0; +virtual void OutInfo ()=0; public: - // non-hidden ops - Ivector2 m_StartCp; - Ivector2 m_CurrentCp; +// non-hidden ops +Ivector2 m_StartCp; +Ivector2 m_CurrentCp; - Fvector m_CurrentRStart; - Fvector m_CurrentRDir; +Fvector m_CurrentRStart; +Fvector m_CurrentRDir; - // hidden ops - Ivector2 m_StartCpH; - Ivector2 m_DeltaCpH; +// hidden ops +Ivector2 m_StartCpH; +Ivector2 m_DeltaCpH; protected: - bool m_MouseCaptured; - bool m_MouseMultiClickCaptured; - bool bMouseInUse; +bool m_MouseCaptured; +bool m_MouseMultiClickCaptured; +bool bMouseInUse; - THintWindow* m_pHintWindow; - AnsiString m_LastHint; - bool m_bHintShowing; - POINT m_HintPoint; +THintWindow* m_pHintWindow; +AnsiString m_LastHint; +bool m_bHintShowing; +POINT m_HintPoint; - // mailslot - HANDLE hMailSlot; +// mailslot +HANDLE hMailSlot; public: - void ShowObjectHint(); - void ShowHint(const AnsiString& s); - bool ShowHint(const AStringVec& SS); - void HideHint(); +void ShowObjectHint(); +void ShowHint(const AnsiString& s); +bool ShowHint(const AStringVec& SS); +void HideHint(); public: - // mouse sensetive - float m_MouseSM, m_MouseSS, m_MouseSR; +// mouse sensetive +float m_MouseSM, m_MouseSS, m_MouseSR; protected: - virtual void RealQuit ()=0; - virtual void RealUpdateScene ()=0; - void RealRedrawScene (); - void RealResize (); - void OnFrame (); +virtual void RealQuit ()=0; +virtual void RealUpdateScene ()=0; +void RealRedrawScene (); +void RealResize (); +void OnFrame (); public: - TUI (); - virtual ~TUI (); +TUI (); +virtual ~TUI (); - void Quit () { m_Flags.set(flNeedQuit,TRUE); } +void Quit () { m_Flags.set(flNeedQuit,TRUE); } - IC HANDLE GetHWND () { return m_D3DWindow->Handle; } - int GetRenderWidth () { return EDevice.dwWidth; } - int GetRenderHeight () { return EDevice.dwHeight; } - int GetRealWidth () { return EDevice.m_RealWidth; } - int GetRealHeight () { return EDevice.m_RealHeight; } +IC HANDLE GetHWND () { return m_D3DWindow->Handle; } +int GetRenderWidth () { return EDevice.dwWidth; } +int GetRenderHeight () { return EDevice.dwHeight; } +int GetRealWidth () { return EDevice.m_RealWidth; } +int GetRealHeight () { return EDevice.m_RealHeight; } - IC float ZFar () { return EDevice.m_Camera.m_Zfar; } - IC TShiftState GetShiftState () { return m_ShiftState; } +IC float ZFar () { return EDevice.m_Camera.m_Zfar; } +IC TShiftState GetShiftState () { return m_ShiftState; } - virtual bool OnCreate (TD3DWindow* w, TPanel* p); - virtual void OnDestroy (); +virtual bool OnCreate (TD3DWindow* w, TPanel* p); +virtual void OnDestroy (); - virtual char* GetCaption ()=0; +virtual char* GetCaption ()=0; - bool IsModified (); +bool IsModified (); - void __fastcall Idle (); - void Resize (bool bForced=false){ m_Flags.set(flResize|flRedraw,TRUE);if (bForced) RealResize(); } - // add, remove, changing objects/scene - void UpdateScene (bool bForced=false){ m_Flags.set(flUpdateScene,TRUE); if (bForced) RealUpdateScene();} - // only redraw scene - void RedrawScene (bool bForced=false){ m_Flags.set(flRedraw,TRUE); if (bForced) RealRedrawScene();} +void __fastcall Idle (); +void Resize (bool bForced=false){ m_Flags.set(flResize|flRedraw,TRUE);if (bForced) RealResize(); } +// add, remove, changing objects/scene +void UpdateScene (bool bForced=false){ m_Flags.set(flUpdateScene,TRUE); if (bForced) RealUpdateScene();} +// only redraw scene +void RedrawScene (bool bForced=false){ m_Flags.set(flRedraw,TRUE); if (bForced) RealRedrawScene();} - void SetRenderQuality (float q) { EDevice.m_ScreenQuality = q;} +void SetRenderQuality (float q) { EDevice.m_ScreenQuality = q;} // mouse action - void EnableSelectionRect (bool flag ); - void UpdateSelectionRect (const Ivector2& from, const Ivector2& to ); - - void MouseMultiClickCapture(bool b){m_MouseMultiClickCaptured = b;} - - bool __fastcall IsMouseCaptured () { return m_MouseCaptured|m_MouseMultiClickCaptured;} - bool __fastcall IsMouseInUse () { return bMouseInUse;} - - bool __fastcall KeyDown (WORD Key, TShiftState Shift); - bool __fastcall KeyUp (WORD Key, TShiftState Shift); - bool __fastcall KeyPress (WORD Key, TShiftState Shift); - void __fastcall MousePress (TShiftState Shift, int X, int Y); - void __fastcall MouseRelease (TShiftState Shift, int X, int Y); - void __fastcall MouseMove (TShiftState Shift, int X, int Y); - - void BeginEState (EEditorState st){ m_EditorState.push_back(st); } - void EndEState (){ m_EditorState.pop_back(); } - void EndEState (EEditorState st){ - VERIFY(std::find(m_EditorState.begin(),m_EditorState.end(),st)!=m_EditorState.end()); - for (EStateIt it=m_EditorState.end()-1; it>=m_EditorState.begin(); it--) - if (*it==st){ - m_EditorState.erase(it,m_EditorState.end()); - break; - } - } - EEditorState GetEState (){ return m_EditorState.back(); } - bool ContainEState (EEditorState st){ return std::find(m_EditorState.begin(),m_EditorState.end(),st)!=m_EditorState.end(); } - - virtual void OutCameraPos ()=0; - virtual void SetStatus (LPSTR s, bool bOutLog=true)=0; - virtual void ResetStatus ()=0; - - // direct input - virtual void IR_OnMouseMove (int x, int y); - - void OnAppActivate (); - void OnAppDeactivate (); - - bool NeedAbort (){Application->ProcessMessages(); return bNeedAbort;} - void NeedBreak (){bNeedAbort = true;} - void ResetBreak (){bNeedAbort = false;} - - virtual bool ApplyShortCut (WORD Key, TShiftState Shift)=0; - virtual bool ApplyGlobalShortCut (WORD Key, TShiftState Shift)=0; - - void SetGradient (u32 color){;} - - void OnDeviceCreate (); - void OnDeviceDestroy (); - - // mailslot - bool CreateMailslot (); - void CheckMailslot (); - void OnReceiveMail (LPCSTR msg); - void SendMail (LPCSTR name, LPCSTR dest, LPCSTR msg); - - void CheckWindowPos (TForm* form); - - virtual LPCSTR EditorName ()=0; - virtual LPCSTR EditorDesc ()=0; +void EnableSelectionRect (bool flag ); +void UpdateSelectionRect (const Ivector2& from, const Ivector2& to ); + +void MouseMultiClickCapture(bool b){m_MouseMultiClickCaptured = b;} + +bool __fastcall IsMouseCaptured () { return m_MouseCaptured|m_MouseMultiClickCaptured;} +bool __fastcall IsMouseInUse () { return bMouseInUse;} + +bool __fastcall KeyDown (WORD Key, TShiftState Shift); +bool __fastcall KeyUp (WORD Key, TShiftState Shift); +bool __fastcall KeyPress (WORD Key, TShiftState Shift); +void __fastcall MousePress (TShiftState Shift, int X, int Y); +void __fastcall MouseRelease (TShiftState Shift, int X, int Y); +void __fastcall MouseMove (TShiftState Shift, int X, int Y); + +void BeginEState (EEditorState st){ m_EditorState.push_back(st); } +void EndEState (){ m_EditorState.pop_back(); } +void EndEState (EEditorState st){ + VERIFY(std::find(m_EditorState.begin(),m_EditorState.end(),st)!=m_EditorState.end()); + for (EStateIt it=m_EditorState.end()-1; it>=m_EditorState.begin(); it--) + if (*it==st){ + m_EditorState.erase(it,m_EditorState.end()); + break; +} +} +EEditorState GetEState (){ return m_EditorState.back(); } +bool ContainEState (EEditorState st){ return std::find(m_EditorState.begin(),m_EditorState.end(),st)!=m_EditorState.end(); } + +virtual void OutCameraPos ()=0; +virtual void SetStatus (LPSTR s, bool bOutLog=true)=0; +virtual void ResetStatus ()=0; + +// direct input +virtual void IR_OnMouseMove (int x, int y); + +void OnAppActivate (); +void OnAppDeactivate (); + +bool NeedAbort (){Application->ProcessMessages(); return bNeedAbort;} +void NeedBreak (){bNeedAbort = true;} +void ResetBreak (){bNeedAbort = false;} + +virtual bool ApplyShortCut (WORD Key, TShiftState Shift)=0; +virtual bool ApplyGlobalShortCut (WORD Key, TShiftState Shift)=0; + +void SetGradient (u32 color){;} + +void OnDeviceCreate (); +void OnDeviceDestroy (); + +// mailslot +bool CreateMailslot (); +void CheckMailslot (); +void OnReceiveMail (LPCSTR msg); +void SendMail (LPCSTR name, LPCSTR dest, LPCSTR msg); + +void CheckWindowPos (TForm* form); + +virtual LPCSTR EditorName ()=0; +virtual LPCSTR EditorDesc ()=0; // commands - virtual void RegisterCommands ()=0; - void ClearCommands (); - - CCommandVar CommandRenderFocus (CCommandVar p1, CCommandVar p2); - CCommandVar CommandBreakLastOperation (CCommandVar p1, CCommandVar p2); - CCommandVar CommandRenderResize (CCommandVar p1, CCommandVar p2); - - virtual void SaveSettings (CInifile*){} - virtual void LoadSettings (CInifile*){} -protected: +virtual void RegisterCommands ()=0; +void ClearCommands (); + +CCommandVar CommandRenderFocus (CCommandVar p1, CCommandVar p2); +CCommandVar CommandBreakLastOperation (CCommandVar p1, CCommandVar p2); +CCommandVar CommandRenderResize (CCommandVar p1, CCommandVar p2); + +virtual void SaveSettings (CInifile*){} +virtual void LoadSettings (CInifile*){} +protected: // progress bar - DEFINE_VECTOR (SPBItem*,PBVec,PBVecIt); - PBVec m_ProgressItems; +DEFINE_VECTOR (SPBItem*,PBVec,PBVecIt); +PBVec m_ProgressItems; public: - SPBItem* ProgressStart (float max_val, LPCSTR text); - void ProgressEnd (SPBItem*&); - virtual void ProgressDraw ()=0; - SPBItem* ProgressLast (){return m_ProgressItems.empty()?0:m_ProgressItems.back();} +SPBItem* ProgressStart (float max_val, LPCSTR text); +void ProgressEnd (SPBItem*&); +virtual void ProgressDraw ()=0; +SPBItem* ProgressLast (){return m_ProgressItems.empty()?0:m_ProgressItems.back();} }; //--------------------------------------------------------------------------- -extern ECORE_API TUI* UI; +extern ECORE_API TUI* UI; //--------------------------------------------------------------------------- void ECORE_API ResetActionToSelect(); #define COMMAND0(cmd) {ExecCommand(cmd);bExec=true;} #define COMMAND1(cmd,p0) {ExecCommand(cmd,p0);bExec=true;} -extern ECORE_API void __fastcall PanelMinMax (TPanel *pa); -extern ECORE_API void __fastcall PanelMinimize (TPanel *pa); -extern ECORE_API void __fastcall PanelMaximize (TPanel *pa); -extern ECORE_API void __fastcall PanelMinMaxClick (TObject *sender); -extern ECORE_API void __fastcall PanelMinimizeClick (TObject *sender); -extern ECORE_API void __fastcall PanelMaximizeClick (TObject *sender); +extern ECORE_API +void __fastcall PanelMinMax(TPanel*pa); +extern ECORE_API +void __fastcall PanelMinimize(TPanel*pa); +extern ECORE_API +void __fastcall PanelMaximize(TPanel*pa); +extern ECORE_API +void __fastcall PanelMinMaxClick(TObject*sender); +extern ECORE_API +void __fastcall PanelMinimizeClick(TObject*sender); +extern ECORE_API +void __fastcall PanelMaximizeClick(TObject*sender); //--------------------------------------------------------------------------- #endif + diff --git a/src/editors/ECore/Editor/xrLoadSurface.cpp b/src/editors/ECore/Editor/xrLoadSurface.cpp index 706ba64c4bc..5d72387349a 100644 --- a/src/editors/ECore/Editor/xrLoadSurface.cpp +++ b/src/editors/ECore/Editor/xrLoadSurface.cpp @@ -3,125 +3,152 @@ #include "freeimage/freeimage.h" -struct SExts{ - xr_vector exts; +struct SExts +{ + xr_vector exts; + void format_register(LPCSTR ext) { - if (ext&&ext[0]){ - for (u32 i=0; i0) { - _close(h); - return TRUE; - } - } - return FALSE; + for (u32 i = 0; i0) + { + _close(h); + return TRUE; + } + } + return FALSE; } -FIBITMAP* Surface_Load(char* full_name) +FIBITMAP *Surface_Load(char *full_name) { - // load - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(full_name); - FIBITMAP* map = FreeImage_Load(fif,full_name); - if (0==map) return NULL; + // load + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(full_name); + FIBITMAP *map = FreeImage_Load(fif, full_name); + if (0==map) + return NULL; - // check if already 32bpp - if (32==FreeImage_GetBPP(map)) return map; + // check if already 32bpp + if (32==FreeImage_GetBPP(map)) + return map; - // convert - FIBITMAP* map32 = FreeImage_ConvertTo32Bits(map); - if (0==map32) map32 = map; - else FreeImage_Unload(map); + // convert + FIBITMAP *map32 = FreeImage_ConvertTo32Bits(map); + if (0==map32) + map32 = map; + else + FreeImage_Unload(map); - return map32; + return map32; } -u32* Surface_Load(char* name, u32& w, u32& h) +u32 *Surface_Load(char *name, u32 &w, u32 &h) { - if (strchr(name,'.')) *(strchr(name,'.')) = 0; + if (strchr(name, '.')) + *(strchr(name, '.')) = 0; - // detect format - string_path full; - if (!Surface_Detect(full,name)) return NULL; + // detect format + string_path full; + if (!Surface_Detect(full, name)) + return NULL; - FIBITMAP* map32 = Surface_Load(full); + FIBITMAP *map32 = Surface_Load(full); - h = FreeImage_GetHeight (map32); - w = FreeImage_GetWidth (map32); + h = FreeImage_GetHeight(map32); + w = FreeImage_GetWidth(map32); - u32 memSize = w*h*4; - u32* memPTR = (u32*)(xr_malloc(memSize)); - u32* memDATA = (u32*)(FreeImage_GetScanLine(map32,0)); - CopyMemory (memPTR,memDATA,memSize); - FreeImage_Unload (map32); - return memPTR; + u32 memSize = w*h*4; + u32 *memPTR = (u32*)(xr_malloc(memSize)); + u32 *memDATA = (u32*)(FreeImage_GetScanLine(map32, 0)); + CopyMemory(memPTR, memDATA, memSize); + FreeImage_Unload(map32); + return memPTR; } + diff --git a/src/editors/ECore/Engine/GameMtlLib.cpp b/src/editors/ECore/Engine/GameMtlLib.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Engine/GameMtlLib.cpp @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Engine/GameMtlLib.h b/src/editors/ECore/Engine/GameMtlLib.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Engine/GameMtlLib.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Engine/GameMtlLib_Engine.cpp b/src/editors/ECore/Engine/GameMtlLib_Engine.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Engine/GameMtlLib_Engine.cpp @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Engine/Image.cpp b/src/editors/ECore/Engine/Image.cpp index 8c3a4c047b9..0a340bd82f0 100644 --- a/src/editors/ECore/Engine/Image.cpp +++ b/src/editors/ECore/Engine/Image.cpp @@ -8,103 +8,116 @@ #include "Image.h" #include "../../../Layers/xrRender/tga.h" -void CImage::Create(u32 w, u32 h, u32* data) +void CImage::Create(u32 w, u32 h, u32 *data) { - Create(w,h); - CopyMemory(pData,data,w*h*sizeof(u32)); + Create(w, h); + CopyMemory(pData, data, w*h*sizeof(u32)); } void CImage::Create(u32 w, u32 h) { - xr_free (pData); - dwWidth = w; - dwHeight = h; - pData = (u32*)(xr_malloc(w*h*sizeof(u32))); + xr_free(pData); + dwWidth = w; + dwHeight = h; + pData = (u32*)(xr_malloc(w*h*sizeof(u32))); } void CImage::SaveTGA(LPCSTR name, BOOL b24) { - // Save - TGAdesc tga; - tga.data = pData; - tga.format = b24?IMG_24B:IMG_32B; - tga.height = dwHeight; - tga.width = dwWidth; - tga.scanlenght=dwWidth*4; - - IWriter* F = FS.w_open(name); - if (F){ - tga.maketga (*F); - FS.w_close (F); - }else{ - Log ("!Can't save tga:",name); + // Save + TGAdesc tga; + tga.data = pData; + tga.format = b24 ? IMG_24B : IMG_32B; + tga.height = dwHeight; + tga.width = dwWidth; + tga.scanlenght = dwWidth*4; + + IWriter *F = FS.w_open(name); + if (F) + { + tga.maketga(*F); + FS.w_close(F); + } + else + { + Log("!Can't save tga:", name); } } void CImage::Vflip() { - R_ASSERT(pData); - for (u32 y=0; y255) c=255; + int c = iFloor(a); + if (c<0) + c = 0; else if (c>255) + c = 255; return BYTE(c); } void CImage::Contrast(float _fc) { - R_ASSERT(pData); + R_ASSERT(pData); // Apply contrast correction - char *ptr = (char *)pData; - float fc = _fc*2.f; - for (u32 i=0; idwWidth; - dwHeight= hdr->dwHeight; - bAlpha = TUisAlphaPresents(hdr->fmt); + void* data = DownloadFile(name); + _fileT* hdr = (_fileT*)data; + u32* pixels = (u32 *) ((char *)data + sizeof(_fileT)); + dwWidth = hdr->dwWidth; + dwHeight= hdr->dwHeight; + bAlpha = TUisAlphaPresents(hdr->fmt); - pData = (u32*)xr_malloc(dwWidth*dwHeight*4); - // CopyMemory(pData,pixels,dwWidth*dwHeight*4); + pData = (u32*)xr_malloc(dwWidth*dwHeight*4); + // CopyMemory(pData,pixels,dwWidth*dwHeight*4); - xr_free(data); + xr_free(data); } */ @@ -162,137 +175,165 @@ void CImage::LoadT(char *name) #define RGBA_GETBLUE(rgb) u32((rgb) & 0xff) #endif -#pragma pack(push,1) // Gotta pack these structures! +#pragma pack(push,1) // Gotta pack these structures! + struct TGAHeader { - BYTE idlen; - BYTE cmtype; - BYTE imgtype; - - u16 cmorg; - u16 cmlen; - BYTE cmes; - - short xorg; - short yorg; - short width; - short height; - BYTE pixsize; - BYTE desc; + BYTE idlen; + BYTE cmtype; + BYTE imgtype; + + u16 cmorg; + u16 cmlen; + BYTE cmes; + + short xorg; + short yorg; + short width; + short height; + BYTE pixsize; + BYTE desc; }; #pragma pack(pop) -extern u32 *Surface_Load(char*,u32&,u32&); +extern u32 *Surface_Load(char *, u32 &, u32 &); -void CImage::Load (LPCSTR name) +void CImage::Load(LPCSTR name) { - VERIFY (!pData); - pData = Surface_Load((LPSTR)name,dwWidth,dwHeight); + VERIFY(!pData); + pData = Surface_Load((LPSTR)name, dwWidth, dwHeight); } bool CImage::LoadTGA(LPCSTR name) { - destructor TGA(FS.r_open(name)); + destructor TGA(FS.r_open(name)); - TGAHeader hdr; - BOOL hflip, vflip; + TGAHeader hdr; + BOOL hflip, vflip; - TGA().r(&hdr,sizeof(TGAHeader)); + TGA().r(&hdr, sizeof(TGAHeader)); - if (!((hdr.imgtype==2)||(hdr.imgtype==10))){ - Msg("Unsupported texture format (%s)",name); + if (!((hdr.imgtype==2)||(hdr.imgtype==10))) + { + Msg("Unsupported texture format (%s)", name); return false; } - if (!((hdr.pixsize==24)||(hdr.pixsize==32))){ - Msg("Texture (%s) - invalid pixsize: %d",name,hdr.pixsize); + if (!((hdr.pixsize==24)||(hdr.pixsize==32))) + { + Msg("Texture (%s) - invalid pixsize: %d", name, hdr.pixsize); return false; } #ifndef _EDITOR - if (!btwIsPow2(hdr.width)){ - Msg("Texture (%s) - invalid width: %d",name,hdr.width); + if (!btwIsPow2(hdr.width)) + { + Msg("Texture (%s) - invalid width: %d", name, hdr.width); return false; } - if (!btwIsPow2(hdr.height)){ - Msg("Texture (%s) - invalid height: %d",name,hdr.height); + if (!btwIsPow2(hdr.height)) + { + Msg("Texture (%s) - invalid height: %d", name, hdr.height); return false; } #endif - // Skip funky stuff - if (hdr.idlen) TGA().advance(hdr.idlen); - if (hdr.cmlen) TGA().advance(hdr.cmlen*((hdr.cmes+7)/8)); + // Skip funky stuff + if (hdr.idlen) + TGA().advance(hdr.idlen); + if (hdr.cmlen) + TGA().advance(hdr.cmlen*((hdr.cmes+7)/8)); - hflip = (hdr.desc & 0x10) ? TRUE : FALSE; // Need hflip - vflip = (hdr.desc & 0x20) ? TRUE : FALSE; // Need vflip + hflip = (hdr.desc&0x10) ? TRUE : FALSE; // Need hflip + vflip = (hdr.desc&0x20) ? TRUE : FALSE; // Need vflip - dwWidth = hdr.width; - dwHeight = hdr.height; - bAlpha = (hdr.pixsize==32); + dwWidth = hdr.width; + dwHeight = hdr.height; + bAlpha = (hdr.pixsize==32); - // Alloc memory - pData = (u32*)xr_malloc(dwWidth*dwHeight*4); + // Alloc memory + pData = (u32*)xr_malloc(dwWidth*dwHeight*4); u32 pixel; - u32* ptr = pData; - for( int y=0; y Mapping; - typedef xr_set< Edge > EdgeSet; - typedef xr_vector< xr_set< unsigned int > > IdenticalVertices; + typedef xr_map Mapping; + typedef xr_set EdgeSet; + typedef xr_vector> IdenticalVertices; IdenticalVertices IdenticalVertices_; // make room for potential tex coords, normals, binormals and tangents - output.resize( input.size() + 4 ); + output.resize(input.size()+4); Mapping inmap; Mapping outmap; - for ( unsigned int a = 0; a < input.size(); ++a ) + for (unsigned int a = 0; a EmptySet; + xr_set EmptySet; - for ( unsigned int i = 0; i < positions.size(); i += 3 ) + for (unsigned int i = 0; i(positions.size() / 3.0f); - - for ( unsigned int i = 0; i < theCount; ++i ) - { - maxPosition.x = nv_max( maxPosition.x, pPositions[ i ].x ); - maxPosition.y = nv_max( maxPosition.y, pPositions[ i ].y ); - maxPosition.z = nv_max( maxPosition.z, pPositions[ i ].z ); - - minPosition.x = nv_min( minPosition.x, pPositions[ i ].x ); - minPosition.y = nv_min( minPosition.y, pPositions[ i ].y ); - minPosition.z = nv_min( minPosition.z, pPositions[ i ].z ); - } - - // Find major, minor and other axis for cylindrical texgen - - vec3 delta = maxPosition - minPosition; - - delta.x = _abs( delta.x ); - delta.y = _abs( delta.y ); - delta.z = _abs( delta.z ); - - bool maxx,maxy,maxz; - maxx = maxy = maxz = false; - bool minz,miny,minx; - minx = miny = minz = false; - - nv_scalar deltaMajor; - - if ( ( delta.x >= delta.y ) && ( delta.x >= delta.z ) ) - { - maxx = true; - deltaMajor = delta.x; - if ( delta.y > delta.z ) - { - minz = true; - } - else - { - miny = true; - } - } - else - if ( ( delta.z >= delta.y ) && ( delta.z >= delta.x ) ) - { - maxz = true; - deltaMajor = delta.z; - if ( delta.y > delta.x ) - { - minx = true; - } - else - { - miny = true; - } - } - else - if ( ( delta.y >= delta.z ) && ( delta.y >= delta.x ) ) - { - maxy = true; - deltaMajor = delta.y; - if ( delta.x > delta.z ) - { - minz = true; - } - else - { - minx = true; - } - } - - for ( unsigned int p = 0; p < theCount; ++p ) - { - // Find position relative to center of bounding box - - vec3 texCoords = ( ( maxPosition + minPosition ) / 2.0f ) - pPositions[ p ]; - - nv_scalar Major, Minor, Other = nv_zero; - - if ( maxx ) - { - Major = texCoords.x; - if ( miny ) - { - Minor = texCoords.y; - Other = texCoords.z; - } else { - Minor = texCoords.z; - Other = texCoords.y; - } - } - else - if ( maxy ) - { - Major = texCoords.y; - if ( minx ) - { - Minor = texCoords.x; - Other = texCoords.z; - } else { - Minor = texCoords.z; - Other = texCoords.x; - } - } - else - if ( maxz ) - { - Major = texCoords.z; - if ( miny ) - { - Minor = texCoords.y; - Other = texCoords.x; - } else { - Minor = texCoords.x; - Other = texCoords.y; - } - } - - nv_scalar longitude = nv_zero; - - // Prevent zero or near-zero from being passed into atan2 - if ( _abs( Other ) < 0.0001f ) - { - if ( Other >= nv_zero ) - { - Other = 0.0001f; - } else { - Other = -0.0001f; - } - } - - // perform cylindrical mapping onto object, and remap from -pi,pi to -1,1 - - longitude = (( atan2( Minor, Other ) ) / nv_scalar(3.141592654)); - - texCoords.x = 0.5f * longitude + 0.5f; - texCoords.y = (Major/deltaMajor) + 0.5f; - - texCoords.x = nv_max( texCoords.x, nv_zero ); - texCoords.y = nv_max( texCoords.y, nv_zero ); - - texCoords.x = nv_min( texCoords.x, 1.0f ); - texCoords.y = nv_min( texCoords.y, 1.0f ); - - pTex0[ p ].x = texCoords.x-0.25f; - if ( pTex0[ p ].x < nv_zero ) pTex0[ p ].x += 1.0; - pTex0[ p ].y = 1.0f-texCoords.y; - pTex0[ p ].z = 1.0f; - } - } - - if ( _FixCylindricalTexGen == FixCylindricalTexGen ) - { - Mapping::iterator texIter = outmap.find( "tex0" ); - - VertexAttribute::FloatVector& texcoords = ( output[ (*texIter).second ].floatVector_ ); - - const unsigned int theSize = indices.size(); - - for ( unsigned int f = 0; f < theSize; f += 3 ) - { - for ( int v = 0; v < 3; ++v ) - { - int start = f + v; - int end = start + 1; - - if ( v == 2 ) - { - end = f; - } - - nv_scalar dS = texcoords[ indices[ end ] * 3 + 0 ] - texcoords[ indices[ start ] * 3 + 0 ]; - - nv_scalar newS = nv_zero; - - bool bDoS = false; - - unsigned int theOneToChange = start; - - if ( _abs( dS ) >= 0.5f ) - { - bDoS = true; - if ( texcoords[ indices[ start ] * 3 + 0 ] < texcoords[ indices[ end ] * 3 + 0 ] ) - { - newS = texcoords[ indices[ start ]* 3 + 0 ] + 1.0f; - } - else - { - theOneToChange = end; - newS = texcoords[ indices[ end ] * 3 + 0 ] + 1.0f; - } - } - - if ( bDoS == true ) - { - unsigned int theNewIndex = texcoords.size() / 3; - // Duplicate every part of the vertex - for ( unsigned int att = 0; att < output.size(); ++att ) - { - // No new indices are created, just vertex attributes - if ( output[ att ].Name_ != "indices" ) - { - if ( output[ att ].Name_ == "tex0" ) - { - output[ att ].floatVector_.push_back( (float)newS ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 1 ] ); // x - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 2 ] ); // z - } - else - { - // *3 b/c we are looking up 3vectors in an array of floats - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 0 ] ); // x - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 1 ] ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 2 ] ); // z - } - } - } - - IdenticalVertices_.push_back( EmptySet ); - - IdenticalVertices_[ indices[ theOneToChange ] ].insert( theNewIndex ); - IdenticalVertices_[ theNewIndex ].insert( indices[ theOneToChange ] ); - - // point to where the new vertices will go - indices[ theOneToChange ] = theNewIndex; - } - - } // for v - - { - - for ( int v = 0; v < 3; ++v ) - { - int start = f + v; - int end = start + 1; - - if ( v == 2 ) - { - end = f; - } - - nv_scalar dT = texcoords[ indices[ end ] * 3 + 1 ] - texcoords[ indices[ start ] * 3 + 1 ]; - - nv_scalar newT = nv_zero; - - bool bDoT = false; - - unsigned int theOneToChange = start; - - if ( _abs( dT ) >= 0.5f ) - { - bDoT = true; - if ( texcoords[ indices[ start ] * 3 + 1 ] < texcoords[ indices[ end ] * 3 + 1 ] ) - { - newT = texcoords[ indices[ start ] * 3 + 1 ] + 1.0f; - } - else - { - theOneToChange = end; - newT = texcoords[ indices[ end ] * 3 + 1 ] + 1.0f; - } - } - - if ( bDoT == true ) - { - unsigned int theNewIndex = texcoords.size() / 3; - // Duplicate every part of the vertex - for ( unsigned int att = 0; att < output.size(); ++att ) - { - // No new indices are created, just vertex attributes - if ( output[ att ].Name_ != "indices" ) - { - if ( output[ att ].Name_ == "tex0" ) - { - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 0 ] ); // x - output[ att ].floatVector_.push_back( (float) newT ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 2 ] ); // z - } - else - { - // *3 b/c we are looking up 3vectors in an array of floats - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 0 ] ); // x - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 1 ] ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ theOneToChange ] * 3 + 2 ] ); // z - } - } - } - - IdenticalVertices_.push_back( EmptySet ); - - IdenticalVertices_[ theNewIndex ].insert( indices[ theOneToChange ] ); - IdenticalVertices_[ indices[ theOneToChange ] ].insert( theNewIndex ); - - // point to where the new vertices will go - indices[ theOneToChange ] = theNewIndex; - } - } - - } // for v - - } // for f - } // if fix texgen - if (pTextureMatrix) { - const mat4 M( pTextureMatrix[0], pTextureMatrix[1], pTextureMatrix[2], pTextureMatrix[3], - pTextureMatrix[4], pTextureMatrix[5], pTextureMatrix[6], pTextureMatrix[7], - pTextureMatrix[8], pTextureMatrix[9], pTextureMatrix[10], pTextureMatrix[11], - pTextureMatrix[12], pTextureMatrix[13], pTextureMatrix[14], pTextureMatrix[15]); - Mapping::iterator texIter = outmap.find("tex0"); - VertexAttribute::FloatVector& texcoords = output[(*texIter).second].floatVector_; - - // now apply matrix - for (unsigned int v = 0; v < texcoords.size(); v += 3) { - vec3& V = *reinterpret_cast(&texcoords[v]); - V = V * M; - } - } + if (have_texcoords) + output[(*want).second].floatVector_ = input[(*have).second].floatVector_; + else + { + // just initialize array so it's the correct size + output[(*want).second].floatVector_ = positions; + + pTex0 = (vec3*)(&(output[(*want).second].floatVector_[0])); + + // Generate cylindrical coordinates + + // Find min and max positions for object bounding box + + vec3 maxPosition(-flt_max, -flt_max, -flt_max); + vec3 minPosition(flt_max, flt_max, flt_max); + + // there are 1/3 as many vectors as floats + const unsigned int theCount = static_cast(positions.size()/3.0f); + + for (unsigned int i = 0; i=delta.y)&&(delta.x>=delta.z)) + { + maxx = true; + deltaMajor = delta.x; + if (delta.y>delta.z) + { + minz = true; + } + else + { + miny = true; + } + } + else if ((delta.z>=delta.y)&&(delta.z>=delta.x)) + { + maxz = true; + deltaMajor = delta.z; + if (delta.y>delta.x) + { + minx = true; + } + else + { + miny = true; + } + } + else if ((delta.y>=delta.z)&&(delta.y>=delta.x)) + { + maxy = true; + deltaMajor = delta.y; + if (delta.x>delta.z) + { + minz = true; + } + else + { + minx = true; + } + } + + for (unsigned int p = 0; p=nv_zero) + { + Other = 0.0001f; + } + else + { + Other = -0.0001f; + } + } + + // perform cylindrical mapping onto object, and remap from -pi,pi to -1,1 + + longitude = ((atan2(Minor, Other))/nv_scalar(3.141592654)); + + texCoords.x = 0.5f*longitude+0.5f; + texCoords.y = (Major/deltaMajor)+0.5f; + + texCoords.x = nv_max(texCoords.x, nv_zero); + texCoords.y = nv_max(texCoords.y, nv_zero); + + texCoords.x = nv_min(texCoords.x, 1.0f); + texCoords.y = nv_min(texCoords.y, 1.0f); + + pTex0[p].x = texCoords.x-0.25f; + if (pTex0[p].x=0.5f) + { + bDoS = true; + if (texcoords[indices[start]*3+0]=0.5f) + { + bDoT = true; + if (texcoords[indices[start]*3+1](&texcoords[v]); + V = V*M; + } + } } - if ( bComputeTangentSpace ) - { + if (bComputeTangentSpace) + { EdgeSet Edges; - Mapping::iterator texIter = outmap.find( "tex0" ); + Mapping::iterator texIter = outmap.find("tex0"); - vec3* tex = (vec3*)&( output[ (*texIter).second ].floatVector_[ 0 ] ); + vec3 *tex = (vec3*)&(output[(*texIter).second].floatVector_[0]); - typedef xr_vector< vec3 > VecVector; + typedef xr_vector VecVector; // create tangents - want = outmap.find( "tangent" ); - if ( want == outmap.end() ) - { - VertexAttribute tanAtt; - tanAtt.Name_ = "tangent"; - output.push_back( tanAtt ); - outmap[ "tangent" ] = output.size() - 1; - want = outmap.find( "tangent" ); + want = outmap.find("tangent"); + if (want==outmap.end()) + { + VertexAttribute tanAtt; + tanAtt.Name_ = "tangent"; + output.push_back(tanAtt); + outmap["tangent"] = output.size()-1; + want = outmap.find("tangent"); } - // just initialize array so it's the correct size - output[ (*want).second ].floatVector_ = positions; + // just initialize array so it's the correct size + output[(*want).second].floatVector_ = positions; // create binormals - want = outmap.find( "binormal" ); - if ( want == outmap.end() ) - { - VertexAttribute binAtt; - binAtt.Name_ = "binormal"; - output.push_back( binAtt ); - outmap[ "binormal" ] = output.size() - 1; - want = outmap.find( "binormal" ); + want = outmap.find("binormal"); + if (want==outmap.end()) + { + VertexAttribute binAtt; + binAtt.Name_ = "binormal"; + output.push_back(binAtt); + outmap["binormal"] = output.size()-1; + want = outmap.find("binormal"); } - // just initialize array so it's the correct size - output[ (*want).second ].floatVector_ = positions; + // just initialize array so it's the correct size + output[(*want).second].floatVector_ = positions; // Create a vector of s,t and sxt for each face of the model VecVector sVector; @@ -679,210 +682,227 @@ bool NVMeshMender::Munge( const NVMeshMender::VAVector& input, VecVector sxtVector; const unsigned int theSize = indices.size(); - // for each face, calculate its S,T & SxT vector, & store its edges - for ( unsigned int f = 0; f < theSize; f += 3 ) - { - vec3d edge0; - vec3d edge1; + // for each face, calculate its S,T & SxT vector, & store its edges + for (unsigned int f = 0; f _eps ) ds_dx = - b / a; - double dt_dx = nv_zero; if ( _abs( a ) > _eps ) dt_dx = - c / a; - - // create an edge out of y, s and t - edge0.x = pPositions[ indices[ f + 1 ] ].y - pPositions[ indices[ f ] ].y; - edge1.x = pPositions[ indices[ f + 2 ] ].y - pPositions[ indices[ f ] ].y; - sxt = edge0 ^ edge1; - - a=sxt.x;b=sxt.y;c= sxt.z; - double ds_dy = nv_zero; if ( _abs( a ) > _eps ) ds_dy = -b / a; - double dt_dy = nv_zero; if ( _abs( a ) > _eps ) dt_dy = -c / a; - - // create an edge out of z, s and t - edge0.x = pPositions[ indices[ f + 1 ] ].z - pPositions[ indices[ f ] ].z; - edge1.x = pPositions[ indices[ f + 2 ] ].z - pPositions[ indices[ f ] ].z; - sxt = edge0 ^ edge1; - - a=sxt.x;b=sxt.y;c= sxt.z; - double ds_dz = nv_zero; if ( _abs( a ) > _eps ) ds_dz = -b / a; - double dt_dz = nv_zero; if ( _abs( a ) > _eps ) dt_dz = -c / a; + pPositions = (vec3*) (&(positions[0])); + tex = (vec3*) (&(output[(*texIter).second].floatVector_[0])); + + double _eps = type_epsilon(double)*10; + double a, b, c; + vec3d sxt; + + // create an edge(s) out of s and t + edge0.y = tex[indices[f+1]].x-tex[indices[f]].x; + edge0.z = tex[indices[f+1]].y-tex[indices[f]].y; + edge1.y = tex[indices[f+2]].x-tex[indices[f]].x; + edge1.z = tex[indices[f+2]].y-tex[indices[f]].y; + + // create an edge out of x, s and t + edge0.x = pPositions[indices[f+1]].x-pPositions[indices[f]].x; + edge1.x = pPositions[indices[f+2]].x-pPositions[indices[f]].x; + sxt = edge0^edge1; + + a = sxt.x; + b = sxt.y; + c = sxt.z; + double ds_dx = nv_zero; + if (_abs(a)>_eps) + ds_dx = - b/a; + double dt_dx = nv_zero; + if (_abs(a)>_eps) + dt_dx = - c/a; + + // create an edge out of y, s and t + edge0.x = pPositions[indices[f+1]].y-pPositions[indices[f]].y; + edge1.x = pPositions[indices[f+2]].y-pPositions[indices[f]].y; + sxt = edge0^edge1; + + a = sxt.x; + b = sxt.y; + c = sxt.z; + double ds_dy = nv_zero; + if (_abs(a)>_eps) + ds_dy = -b/a; + double dt_dy = nv_zero; + if (_abs(a)>_eps) + dt_dy = -c/a; + + // create an edge out of z, s and t + edge0.x = pPositions[indices[f+1]].z-pPositions[indices[f]].z; + edge1.x = pPositions[indices[f+2]].z-pPositions[indices[f]].z; + sxt = edge0^edge1; + + a = sxt.x; + b = sxt.y; + c = sxt.z; + double ds_dz = nv_zero; + if (_abs(a)>_eps) + ds_dz = -b/a; + double dt_dz = nv_zero; + if (_abs(a)>_eps) + dt_dz = -c/a; // generate coordinate frame from the gradients - s = vec3d( ds_dx, ds_dy, ds_dz ); - t = vec3d( dt_dx, dt_dy, dt_dz ); + s = vec3d(ds_dx, ds_dy, ds_dz); + t = vec3d(dt_dx, dt_dy, dt_dz); - s.normalize (); - t.normalize (); - sxt = s ^ t; - sxt.normalize (); + s.normalize(); + t.normalize(); + sxt = s^t; + sxt.normalize(); // save vectors for this face - sVector.push_back ( vec3(s) ); - tVector.push_back ( vec3(t) ); - sxtVector.push_back ( vec3(sxt) ); - - if ( _FixTangents == FixTangents ) - { - // Look for each edge of the triangle in the edge map, in order to find - // a neighboring face along the edge - - for ( int e = 0; e < 3; ++e ) - { - Edge edge; - - int start = f + e; - int end = start + 1; - - if ( e == 2 ) - { - end = f; - } - // order vertex indices ( low, high ) - edge.v0 = (unsigned int)nv_min( (nv_scalar)indices[ start ], (nv_scalar)indices[ end ] ); - edge.v1 = (unsigned int)nv_max( (nv_scalar)indices[ start ], (nv_scalar)indices[ end ] ); - - EdgeSet::iterator iter = Edges.find( edge ); - - // if we are the only triangle with this edge... - if ( iter == Edges.end() ) - { - // ...then add us to the set of edges - edge.face = f / 3; - Edges.insert( edge ); - } - else - { - // otherwise, check our neighbor's s,t & sxt vectors vs our own - const nv_scalar sAgreement = dot(s, sVector[(*iter).face]); - const nv_scalar tAgreement = dot(t, tVector[(*iter).face]); - const nv_scalar sxtAgreement = dot(sxt, sxtVector[(*iter).face]); - - // Check Radian angle split limit - const nv_scalar epsilon = _cos( bSmoothCreaseAngleRadians ); - - // if the discontinuity in s, t, or sxt is greater than some epsilon, - // duplicate the vertex so it won't smooth with its neighbor anymore - - if ( ( _abs( sAgreement ) < epsilon ) || - ( _abs( tAgreement ) < epsilon ) || - ( _abs( sxtAgreement ) < epsilon ) ) - { - // Duplicate two vertices of this edge for this triangle only. - // This way the faces won't smooth with each other, thus - // preventing the tangent basis from becoming degenerate - - // divide by 3 b/c vector is of floats and not vectors - const unsigned int theNewIndex = positions.size() / 3; - - // Duplicate every part of the vertex - for ( unsigned int att = 0; att < output.size(); ++att ) - { - // No new indices are created, just vertex attributes - if ( output[ att ].Name_ != "indices" ) - { - // *3 b/c we are looking up 3vectors in an array of floats - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ start ] * 3 + 0 ] ); // x - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ start ] * 3 + 1 ] ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ start ] * 3 + 2 ] ); // z - - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ end ] * 3 + 0 ] ); // x - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ end ] * 3 + 1 ] ); // y - output[ att ].floatVector_.push_back( output[ att ].floatVector_[ indices[ end ] * 3 + 2 ] ); // z - } - } - - IdenticalVertices_.push_back( EmptySet ); - IdenticalVertices_.push_back( EmptySet ); - - // point to where the new vertices will go - indices[ start ] = theNewIndex; - indices[ end ] = theNewIndex + 1; - - } - - // Now that the vertices are duplicated, smoothing won't occur over this edge, - // because the two faces will sum their tangent basis vectors into separate indices - } - } - } // if fixtangents - } + sVector.push_back(vec3(s)); + tVector.push_back(vec3(t)); + sxtVector.push_back(vec3(sxt)); + + if (_FixTangents==FixTangents) + { + // Look for each edge of the triangle in the edge map, in order to find + // a neighboring face along the edge + + for (int e = 0; e<3; ++e) + { + Edge edge; + + int start = f+e; + int end = start+1; + + if (e==2) + { + end = f; + } + // order vertex indices ( low, high ) + edge.v0 = (unsigned int)nv_min((nv_scalar)indices[start], (nv_scalar)indices[end]); + edge.v1 = (unsigned int)nv_max((nv_scalar)indices[start], (nv_scalar)indices[end]); + + EdgeSet::iterator iter = Edges.find(edge); + + // if we are the only triangle with this edge... + if (iter==Edges.end()) + { + // ...then add us to the set of edges + edge.face = f/3; + Edges.insert(edge); + } + else + { + // otherwise, check our neighbor's s,t & sxt vectors vs our own + const nv_scalar sAgreement = dot(s, sVector[(*iter).face]); + const nv_scalar tAgreement = dot(t, tVector[(*iter).face]); + const nv_scalar sxtAgreement = dot(sxt, sxtVector[(*iter).face]); + + // Check Radian angle split limit + const nv_scalar epsilon = _cos(bSmoothCreaseAngleRadians); + + // if the discontinuity in s, t, or sxt is greater than some epsilon, + // duplicate the vertex so it won't smooth with its neighbor anymore + + if ((_abs(sAgreement)::iterator iter = IdenticalVertices_[ v ].begin(); - iter != IdenticalVertices_[ v ].end(); - ++iter ) + for (xr_set::iterator iter = IdenticalVertices_[v].begin(); + iter!=IdenticalVertices_[v].end(); + ++iter) { - avgS[ v ] += avgS[ *iter ]; - avgT[ v ] += avgT[ *iter ]; + avgS[v] += avgS[*iter]; + avgT[v] += avgT[*iter]; } } } - Mapping::iterator tangent = outmap.find( "tangent" ); - Mapping::iterator binormal = outmap.find( "binormal" ); + Mapping::iterator tangent = outmap.find("tangent"); + Mapping::iterator binormal = outmap.find("binormal"); // now renormalize - for ( unsigned int b = 0; b < positions.size(); b += 3 ) + for (unsigned int b = 0; b(&output[(*tangent).second].floatVector_[b]) = normalize(avgS[b / 3]); // s - *reinterpret_cast(&output[(*binormal).second].floatVector_[b]) = normalize(avgT[b / 3]); // T + *reinterpret_cast(&output[(*tangent).second].floatVector_[b]) = normalize(avgS[b/3]); // s + *reinterpret_cast(&output[(*binormal).second].floatVector_[b]) = normalize(avgT[b/3]); // T } - } + } - // At this point, tex coords, normals, binormals and tangents should be generated if necessary, - // and other attributes are simply copied as available + // At this point, tex coords, normals, binormals and tangents should be generated if necessary, + // and other attributes are simply copied as available return true; } diff --git a/src/editors/ECore/Engine/NVMeshMender.h b/src/editors/ECore/Engine/NVMeshMender.h index d2680b5aeda..d6dc2930344 100644 --- a/src/editors/ECore/Engine/NVMeshMender.h +++ b/src/editors/ECore/Engine/NVMeshMender.h @@ -129,127 +129,130 @@ Questions to sim.dietrich@nvidia.com class NVMeshMender { - private : +private : - mutable xr_vector< xr_string > LastErrors_; + mutable xr_vector LastErrors_; - struct Edge - { - unsigned int v0; - unsigned int v1; + struct Edge + { + unsigned int v0; + unsigned int v1; - unsigned int face; - unsigned int face2; + unsigned int face; + unsigned int face2; - bool operator==( const Edge& rhs ) const - { - return ( ( v0 == rhs.v0 ) && ( v1 == rhs.v1 ) ); - } - - bool operator<( const Edge& rhs ) const - { - if ( v0 < rhs.v0 ) - { - return true; - } - - if ( v0 > rhs.v0 ) - { - return false; - } - - return ( v1 < rhs.v1 ); - } - }; - - public : - - void SetLastError( const xr_string& rhs ) const + bool operator==(const Edge &rhs) const { - LastErrors_.push_back( rhs ); + return ((v0==rhs.v0)&&(v1==rhs.v1)); } - xr_string GetLastError() const + bool operator<(const Edge &rhs) const { - xr_string aString; + if (v0 0 ) + if (v0>rhs.v0) { - aString = LastErrors_.back(); + return false; } - return aString; + + return (v10) { - xr_string Name_; + aString = LastErrors_.back(); + } + return aString; + } - typedef xr_vector< int > IntVector; - IntVector intVector_; + struct VertexAttribute + { + xr_string Name_; + typedef xr_vector IntVector; + IntVector intVector_; - typedef xr_vector< float > FloatVector; - FloatVector floatVector_; - VertexAttribute& operator=( const VertexAttribute& rhs ) - { - Name_ = rhs.Name_; - intVector_ = rhs.intVector_; - floatVector_ = rhs.floatVector_; - return *this; - } + typedef xr_vector FloatVector; + FloatVector floatVector_; - VertexAttribute( const char* pName = "" ) : Name_(pName) {;} + VertexAttribute &operator=(const VertexAttribute &rhs) + { + Name_ = rhs.Name_; + intVector_ = rhs.intVector_; + floatVector_ = rhs.floatVector_; + return *this; + } - VertexAttribute( const VertexAttribute& rhs ) - { - *this = rhs; - } + VertexAttribute(const char *pName = "") : Name_(pName) + { + ; + } - bool operator==( const VertexAttribute& rhs ) - { - return ( Name_ == rhs.Name_ ); - } + VertexAttribute(const VertexAttribute &rhs) + { + *this = rhs; + } - bool operator<( const VertexAttribute& rhs ) - { - return ( Name_ < rhs.Name_ ); - } + bool operator==(const VertexAttribute &rhs) + { + return (Name_==rhs.Name_); + } - }; - - typedef xr_vector< VertexAttribute > VAVector; - - enum Option - { - FixTangents, - DontFixTangents, - - FixCylindricalTexGen, - DontFixCylindricalTexGen, - - WeightNormalsByFaceSize, - DontWeightNormalsByFaceSize - }; - - bool NVMeshMender::Munge( const NVMeshMender::VAVector& input, - NVMeshMender::VAVector& output, - const float bSmoothCreaseAngleRadians = 3.141592654f / 3.0f, - const float* pTextureMatrix = 0, - const Option _FixTangents = FixTangents, - const Option _FixCylindricalTexGen = FixCylindricalTexGen, - const Option _WeightNormalsByFaceSize = WeightNormalsByFaceSize - ); - bool NVMeshMender::MungeD3DX( const NVMeshMender::VAVector& input, - NVMeshMender::VAVector& output, - const float bSmoothCreaseAngleRadians = 3.141592654f / 3.0f, - const float* pTextureMatrix = 0, - const Option _FixTangents = FixTangents, - const Option _FixCylindricalTexGen = FixCylindricalTexGen, - const Option _WeightNormalsByFaceSize = WeightNormalsByFaceSize - ); + bool operator<(const VertexAttribute &rhs) + { + return (Name_ VAVector; + + enum Option + { + FixTangents, + DontFixTangents, + + FixCylindricalTexGen, + DontFixCylindricalTexGen, + + WeightNormalsByFaceSize, + DontWeightNormalsByFaceSize + }; + + bool NVMeshMender::Munge(const NVMeshMender::VAVector &input, + NVMeshMender::VAVector &output, + const float bSmoothCreaseAngleRadians = 3.141592654f/3.0f, + const float *pTextureMatrix = 0, + const Option _FixTangents = FixTangents, + const Option _FixCylindricalTexGen = FixCylindricalTexGen, + const Option _WeightNormalsByFaceSize = WeightNormalsByFaceSize + ); + bool NVMeshMender::MungeD3DX(const NVMeshMender::VAVector &input, + NVMeshMender::VAVector &output, + const float bSmoothCreaseAngleRadians = 3.141592654f/3.0f, + const float *pTextureMatrix = 0, + const Option _FixTangents = FixTangents, + const Option _FixCylindricalTexGen = FixCylindricalTexGen, + const Option _WeightNormalsByFaceSize = WeightNormalsByFaceSize + ); }; -#endif //_NVMeshMender_H_ +#endif //_NVMeshMender_H_ + diff --git a/src/editors/ECore/Engine/Texture.h b/src/editors/ECore/Engine/Texture.h index 66e2b112d34..62f6c8cdd9c 100644 --- a/src/editors/ECore/Engine/Texture.h +++ b/src/editors/ECore/Engine/Texture.h @@ -7,6 +7,8 @@ #pragma once // Wizzard pack -extern ENGINE_API IDirect3DBaseTexture9* TWLoader2D (LPCSTR fname); +extern ENGINE_API IDirect3DBaseTexture9 *TWLoader2D(LPCSTR fname); #endif // !defined(AFX_TEXTURE_H__0E25CF47_FFEC_11D3_B4E3_4854E82A090D__INCLUDED_) + + diff --git a/src/editors/ECore/Engine/ai_sounds.cpp b/src/editors/ECore/Engine/ai_sounds.cpp index 5f60eeb15a4..40e4e32725b 100644 --- a/src/editors/ECore/Engine/ai_sounds.cpp +++ b/src/editors/ECore/Engine/ai_sounds.cpp @@ -3,27 +3,28 @@ #include "ai_sounds.h" -xr_token anomaly_type_token[]={ - { "undefined", sg_Undefined }, - { "Item picking up", SOUND_TYPE_ITEM_PICKING_UP }, - { "Item dropping", SOUND_TYPE_ITEM_DROPPING }, - { "Item taking", SOUND_TYPE_ITEM_TAKING }, - { "Item hiding", SOUND_TYPE_ITEM_HIDING }, - { "Item using", SOUND_TYPE_ITEM_USING }, - { "Weapon shooting", SOUND_TYPE_WEAPON_SHOOTING }, - { "Weapon empty clicking", SOUND_TYPE_WEAPON_EMPTY_CLICKING }, - { "Weapon bullet hit", SOUND_TYPE_WEAPON_BULLET_HIT }, - { "Weapon recharging", SOUND_TYPE_WEAPON_RECHARGING }, - { "NPC dying", SOUND_TYPE_MONSTER_DYING }, - { "NPC injuring", SOUND_TYPE_MONSTER_INJURING }, - { "NPC step", SOUND_TYPE_MONSTER_STEP }, - { "NPC talking", SOUND_TYPE_MONSTER_TALKING }, - { "NPC attacking", SOUND_TYPE_MONSTER_ATTACKING }, - { "NPC eating", SOUND_TYPE_MONSTER_EATING }, - { "Anomaly idle", SOUND_TYPE_ANOMALY_IDLE }, - { "Object breaking", SOUND_TYPE_WORLD_OBJECT_BREAKING }, - { "Object colliding", SOUND_TYPE_WORLD_OBJECT_COLLIDING }, - { "Object exploding", SOUND_TYPE_WORLD_OBJECT_EXPLODING }, - { "World ambient", SOUND_TYPE_WORLD_AMBIENT }, - { 0, 0} +xr_token anomaly_type_token[] = { + {"undefined", sg_Undefined}, + {"Item picking up", SOUND_TYPE_ITEM_PICKING_UP}, + {"Item dropping", SOUND_TYPE_ITEM_DROPPING}, + {"Item taking", SOUND_TYPE_ITEM_TAKING}, + {"Item hiding", SOUND_TYPE_ITEM_HIDING}, + {"Item using", SOUND_TYPE_ITEM_USING}, + {"Weapon shooting", SOUND_TYPE_WEAPON_SHOOTING}, + {"Weapon empty clicking", SOUND_TYPE_WEAPON_EMPTY_CLICKING}, + {"Weapon bullet hit", SOUND_TYPE_WEAPON_BULLET_HIT}, + {"Weapon recharging", SOUND_TYPE_WEAPON_RECHARGING}, + {"NPC dying", SOUND_TYPE_MONSTER_DYING}, + {"NPC injuring", SOUND_TYPE_MONSTER_INJURING}, + {"NPC step", SOUND_TYPE_MONSTER_STEP}, + {"NPC talking", SOUND_TYPE_MONSTER_TALKING}, + {"NPC attacking", SOUND_TYPE_MONSTER_ATTACKING}, + {"NPC eating", SOUND_TYPE_MONSTER_EATING}, + {"Anomaly idle", SOUND_TYPE_ANOMALY_IDLE}, + {"Object breaking", SOUND_TYPE_WORLD_OBJECT_BREAKING}, + {"Object colliding", SOUND_TYPE_WORLD_OBJECT_COLLIDING}, + {"Object exploding", SOUND_TYPE_WORLD_OBJECT_EXPLODING}, + {"World ambient", SOUND_TYPE_WORLD_AMBIENT}, + {0, 0} }; + diff --git a/src/editors/ECore/Engine/ai_sounds.h b/src/editors/ECore/Engine/ai_sounds.h index 66ef42b72d5..ff37c065e2d 100644 --- a/src/editors/ECore/Engine/ai_sounds.h +++ b/src/editors/ECore/Engine/ai_sounds.h @@ -9,72 +9,73 @@ #ifndef ai_soundsH #define ai_soundsH -enum ESoundTypes { - SOUND_TYPE_NO_SOUND = 0x00000000ui32, - - SOUND_TYPE_WEAPON = 0x80000000ui32, - SOUND_TYPE_ITEM = 0x40000000ui32, - SOUND_TYPE_MONSTER = 0x20000000ui32, - SOUND_TYPE_ANOMALY = 0x10000000ui32, - SOUND_TYPE_WORLD = 0x08000000ui32, - - SOUND_TYPE_PICKING_UP = 0x04000000ui32, - SOUND_TYPE_DROPPING = 0x02000000ui32, - SOUND_TYPE_HIDING = 0x01000000ui32, - SOUND_TYPE_TAKING = 0x00800000ui32, - SOUND_TYPE_USING = 0x00400000ui32, - - SOUND_TYPE_SHOOTING = 0x00200000ui32, - SOUND_TYPE_EMPTY_CLICKING = 0x00100000ui32, - SOUND_TYPE_BULLET_HIT = 0x00080000ui32, - SOUND_TYPE_RECHARGING = 0x00040000ui32, - - SOUND_TYPE_DYING = 0x00020000ui32, - SOUND_TYPE_INJURING = 0x00010000ui32, - SOUND_TYPE_STEP = 0x00008000ui32, - SOUND_TYPE_TALKING = 0x00004000ui32, - SOUND_TYPE_ATTACKING = 0x00002000ui32, - SOUND_TYPE_EATING = 0x00001000ui32, - - SOUND_TYPE_IDLE = 0x00000800ui32, - - SOUND_TYPE_OBJECT_BREAKING = 0x00000400ui32, - SOUND_TYPE_OBJECT_COLLIDING = 0x00000200ui32, - SOUND_TYPE_OBJECT_EXPLODING = 0x00000100ui32, - SOUND_TYPE_AMBIENT = 0x00000080ui32, - - SOUND_TYPE_ITEM_PICKING_UP = SOUND_TYPE_ITEM | SOUND_TYPE_PICKING_UP, - SOUND_TYPE_ITEM_DROPPING = SOUND_TYPE_ITEM | SOUND_TYPE_DROPPING, - SOUND_TYPE_ITEM_HIDING = SOUND_TYPE_ITEM | SOUND_TYPE_HIDING, - SOUND_TYPE_ITEM_TAKING = SOUND_TYPE_ITEM | SOUND_TYPE_TAKING, - SOUND_TYPE_ITEM_USING = SOUND_TYPE_ITEM | SOUND_TYPE_USING, - - SOUND_TYPE_WEAPON_SHOOTING = SOUND_TYPE_WEAPON | SOUND_TYPE_SHOOTING, - SOUND_TYPE_WEAPON_EMPTY_CLICKING = SOUND_TYPE_WEAPON | SOUND_TYPE_EMPTY_CLICKING, - SOUND_TYPE_WEAPON_BULLET_HIT = SOUND_TYPE_WEAPON | SOUND_TYPE_BULLET_HIT, - SOUND_TYPE_WEAPON_RECHARGING = SOUND_TYPE_WEAPON | SOUND_TYPE_RECHARGING, - - SOUND_TYPE_MONSTER_DYING = SOUND_TYPE_MONSTER | SOUND_TYPE_DYING, - SOUND_TYPE_MONSTER_INJURING = SOUND_TYPE_MONSTER | SOUND_TYPE_INJURING, - SOUND_TYPE_MONSTER_STEP = SOUND_TYPE_MONSTER | SOUND_TYPE_STEP, - SOUND_TYPE_MONSTER_TALKING = SOUND_TYPE_MONSTER | SOUND_TYPE_TALKING, - SOUND_TYPE_MONSTER_ATTACKING = SOUND_TYPE_MONSTER | SOUND_TYPE_ATTACKING, - SOUND_TYPE_MONSTER_EATING = SOUND_TYPE_MONSTER | SOUND_TYPE_EATING, - - SOUND_TYPE_ANOMALY_IDLE = SOUND_TYPE_ANOMALY | SOUND_TYPE_IDLE, - - SOUND_TYPE_WORLD_OBJECT_BREAKING = SOUND_TYPE_WORLD | SOUND_TYPE_OBJECT_BREAKING, - SOUND_TYPE_WORLD_OBJECT_COLLIDING = SOUND_TYPE_WORLD | SOUND_TYPE_OBJECT_COLLIDING, - SOUND_TYPE_WORLD_OBJECT_EXPLODING = SOUND_TYPE_WORLD | SOUND_TYPE_OBJECT_EXPLODING, - SOUND_TYPE_WORLD_AMBIENT = SOUND_TYPE_WORLD | SOUND_TYPE_AMBIENT, - - SOUND_TYPE_WEAPON_PISTOL = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_GUN = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_SUBMACHINEGUN = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_MACHINEGUN = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_SNIPERRIFLE = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_GRENADELAUNCHER = SOUND_TYPE_WEAPON, - SOUND_TYPE_WEAPON_ROCKETLAUNCHER = SOUND_TYPE_WEAPON, +enum ESoundTypes +{ + SOUND_TYPE_NO_SOUND = 0x00000000ui32, + + SOUND_TYPE_WEAPON = 0x80000000ui32, + SOUND_TYPE_ITEM = 0x40000000ui32, + SOUND_TYPE_MONSTER = 0x20000000ui32, + SOUND_TYPE_ANOMALY = 0x10000000ui32, + SOUND_TYPE_WORLD = 0x08000000ui32, + + SOUND_TYPE_PICKING_UP = 0x04000000ui32, + SOUND_TYPE_DROPPING = 0x02000000ui32, + SOUND_TYPE_HIDING = 0x01000000ui32, + SOUND_TYPE_TAKING = 0x00800000ui32, + SOUND_TYPE_USING = 0x00400000ui32, + + SOUND_TYPE_SHOOTING = 0x00200000ui32, + SOUND_TYPE_EMPTY_CLICKING = 0x00100000ui32, + SOUND_TYPE_BULLET_HIT = 0x00080000ui32, + SOUND_TYPE_RECHARGING = 0x00040000ui32, + + SOUND_TYPE_DYING = 0x00020000ui32, + SOUND_TYPE_INJURING = 0x00010000ui32, + SOUND_TYPE_STEP = 0x00008000ui32, + SOUND_TYPE_TALKING = 0x00004000ui32, + SOUND_TYPE_ATTACKING = 0x00002000ui32, + SOUND_TYPE_EATING = 0x00001000ui32, + + SOUND_TYPE_IDLE = 0x00000800ui32, + + SOUND_TYPE_OBJECT_BREAKING = 0x00000400ui32, + SOUND_TYPE_OBJECT_COLLIDING = 0x00000200ui32, + SOUND_TYPE_OBJECT_EXPLODING = 0x00000100ui32, + SOUND_TYPE_AMBIENT = 0x00000080ui32, + + SOUND_TYPE_ITEM_PICKING_UP = SOUND_TYPE_ITEM|SOUND_TYPE_PICKING_UP, + SOUND_TYPE_ITEM_DROPPING = SOUND_TYPE_ITEM|SOUND_TYPE_DROPPING, + SOUND_TYPE_ITEM_HIDING = SOUND_TYPE_ITEM|SOUND_TYPE_HIDING, + SOUND_TYPE_ITEM_TAKING = SOUND_TYPE_ITEM|SOUND_TYPE_TAKING, + SOUND_TYPE_ITEM_USING = SOUND_TYPE_ITEM|SOUND_TYPE_USING, + + SOUND_TYPE_WEAPON_SHOOTING = SOUND_TYPE_WEAPON|SOUND_TYPE_SHOOTING, + SOUND_TYPE_WEAPON_EMPTY_CLICKING = SOUND_TYPE_WEAPON|SOUND_TYPE_EMPTY_CLICKING, + SOUND_TYPE_WEAPON_BULLET_HIT = SOUND_TYPE_WEAPON|SOUND_TYPE_BULLET_HIT, + SOUND_TYPE_WEAPON_RECHARGING = SOUND_TYPE_WEAPON|SOUND_TYPE_RECHARGING, + + SOUND_TYPE_MONSTER_DYING = SOUND_TYPE_MONSTER|SOUND_TYPE_DYING, + SOUND_TYPE_MONSTER_INJURING = SOUND_TYPE_MONSTER|SOUND_TYPE_INJURING, + SOUND_TYPE_MONSTER_STEP = SOUND_TYPE_MONSTER|SOUND_TYPE_STEP, + SOUND_TYPE_MONSTER_TALKING = SOUND_TYPE_MONSTER|SOUND_TYPE_TALKING, + SOUND_TYPE_MONSTER_ATTACKING = SOUND_TYPE_MONSTER|SOUND_TYPE_ATTACKING, + SOUND_TYPE_MONSTER_EATING = SOUND_TYPE_MONSTER|SOUND_TYPE_EATING, + + SOUND_TYPE_ANOMALY_IDLE = SOUND_TYPE_ANOMALY|SOUND_TYPE_IDLE, + + SOUND_TYPE_WORLD_OBJECT_BREAKING = SOUND_TYPE_WORLD|SOUND_TYPE_OBJECT_BREAKING, + SOUND_TYPE_WORLD_OBJECT_COLLIDING = SOUND_TYPE_WORLD|SOUND_TYPE_OBJECT_COLLIDING, + SOUND_TYPE_WORLD_OBJECT_EXPLODING = SOUND_TYPE_WORLD|SOUND_TYPE_OBJECT_EXPLODING, + SOUND_TYPE_WORLD_AMBIENT = SOUND_TYPE_WORLD|SOUND_TYPE_AMBIENT, + + SOUND_TYPE_WEAPON_PISTOL = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_GUN = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_SUBMACHINEGUN = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_MACHINEGUN = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_SNIPERRIFLE = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_GRENADELAUNCHER = SOUND_TYPE_WEAPON, + SOUND_TYPE_WEAPON_ROCKETLAUNCHER = SOUND_TYPE_WEAPON, }; #define CROUCH_SOUND_FACTOR .3f @@ -83,3 +84,4 @@ enum ESoundTypes { extern xr_token anomaly_type_token[]; #endif + diff --git a/src/editors/ECore/Engine/bone.cpp b/src/editors/ECore/Engine/bone.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Engine/bone.cpp @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Engine/cl_collector.cpp b/src/editors/ECore/Engine/cl_collector.cpp index 69966916e73..c448f94b574 100644 --- a/src/editors/ECore/Engine/cl_collector.cpp +++ b/src/editors/ECore/Engine/cl_collector.cpp @@ -10,3 +10,5 @@ ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// + + diff --git a/src/editors/ECore/Engine/cl_collector.h b/src/editors/ECore/Engine/cl_collector.h index 85b72fbac85..59b9094bd24 100644 --- a/src/editors/ECore/Engine/cl_collector.h +++ b/src/editors/ECore/Engine/cl_collector.h @@ -7,3 +7,5 @@ #pragma once #endif // !defined(AFX_CL_COLLECTOR_H__F107ABA0_E877_4C5A_8EFF_DAB3A86ABDB6__INCLUDED_) + + diff --git a/src/editors/ECore/Engine/cl_intersect.h b/src/editors/ECore/Engine/cl_intersect.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/editors/ECore/Engine/cl_intersect.h @@ -0,0 +1 @@ + diff --git a/src/editors/ECore/Engine/guid_generator.cpp b/src/editors/ECore/Engine/guid_generator.cpp index b34dd1871c8..a1c874a270e 100644 --- a/src/editors/ECore/Engine/guid_generator.cpp +++ b/src/editors/ECore/Engine/guid_generator.cpp @@ -18,7 +18,7 @@ xrGUID generate_guid() { - xrGUID result; + xrGUID result; #ifdef WINVER STATIC_CHECK (sizeof(xrGUID) == sizeof(GUID),Different_GUID_types); GUID _result; @@ -31,9 +31,10 @@ xrGUID generate_guid() default : break; } #endif - STATIC_CHECK (sizeof(result) >= sizeof(u64),GUID_must_have_size_greater_or_equal_to_the_long_long); - ZeroMemory (&result,sizeof(result)); - u64 temp = CPU::GetCLK(); - Memory.mem_copy (&result,&temp,sizeof(temp)); - return (result); + STATIC_CHECK(sizeof(result)>=sizeof(u64), GUID_must_have_size_greater_or_equal_to_the_long_long); + ZeroMemory(&result, sizeof(result)); + u64 temp = CPU::GetCLK(); + Memory.mem_copy(&result, &temp, sizeof(temp)); + return (result); } + diff --git a/src/editors/ECore/Engine/guid_generator.h b/src/editors/ECore/Engine/guid_generator.h index fdeb24f0171..a02eb660eaa 100644 --- a/src/editors/ECore/Engine/guid_generator.h +++ b/src/editors/ECore/Engine/guid_generator.h @@ -15,3 +15,5 @@ ENGINE_API extern xrGUID generate_guid(); #endif //guid_generatorH + + diff --git a/src/editors/ECore/Engine/nv_algebra.cpp b/src/editors/ECore/Engine/nv_algebra.cpp index 0e254e6a1d6..55c857c2c43 100644 --- a/src/editors/ECore/Engine/nv_algebra.cpp +++ b/src/editors/ECore/Engine/nv_algebra.cpp @@ -24,96 +24,92 @@ from the use or inability to use this file or items derived from it. #define _finite finite #endif -mat3::mat3() -{ -} +mat3::mat3() {} -mat3::mat3(const nv_scalar* array) +mat3::mat3(const nv_scalar *array) { - Memory.mem_copy(mat_array, array, sizeof(nv_scalar) * 9); + Memory.mem_copy(mat_array, array, sizeof(nv_scalar)*9); } -mat3::mat3(const mat3 & M) +mat3::mat3(const mat3 &M) { - Memory.mem_copy(mat_array, M.mat_array, sizeof(nv_scalar) * 9); + Memory.mem_copy(mat_array, M.mat_array, sizeof(nv_scalar)*9); } -mat4::mat4() -{ -} +mat4::mat4() {} -mat4::mat4(const nv_scalar* array) +mat4::mat4(const nv_scalar *array) { - Memory.mem_copy(mat_array, array, sizeof(nv_scalar) * 16); + Memory.mem_copy(mat_array, array, sizeof(nv_scalar)*16); } -mat4::mat4(const mat4& M) +mat4::mat4(const mat4 &M) { - Memory.mem_copy(mat_array, M.mat_array, sizeof(nv_scalar) * 16); + Memory.mem_copy(mat_array, M.mat_array, sizeof(nv_scalar)*16); } -vec3 & cross(vec3 & u, const vec3 & v, const vec3 & w) +vec3 &cross(vec3 &u, const vec3 &v, const vec3 &w) { - u.x = v.y*w.z - v.z*w.y; - u.y = v.z*w.x - v.x*w.z; - u.z = v.x*w.y - v.y*w.x; + u.x = v.y*w.z-v.z*w.y; + u.y = v.z*w.x-v.x*w.z; + u.z = v.x*w.y-v.y*w.x; return u; } -nv_scalar & dot(nv_scalar& u, const vec3& v, const vec3& w) +nv_scalar &dot(nv_scalar &u, const vec3 &v, const vec3 &w) { - u = v.x*w.x + v.y*w.y + v.z*w.z; + u = v.x*w.x+v.y*w.y+v.z*w.z; return u; } -nv_scalar dot(const vec3& v, const vec3& w) +nv_scalar dot(const vec3 &v, const vec3 &w) { - return v.x*w.x + v.y*w.y + v.z*w.z; + return v.x*w.x+v.y*w.y+v.z*w.z; } -nv_scalar & dot(nv_scalar& u, const vec4& v, const vec4& w) +nv_scalar &dot(nv_scalar &u, const vec4 &v, const vec4 &w) { - u = v.x*w.x + v.y*w.y + v.z*w.z + v.w*w.w; + u = v.x*w.x+v.y*w.y+v.z*w.z+v.w*w.w; return u; } -nv_scalar dot(const vec4& v, const vec4& w) +nv_scalar dot(const vec4 &v, const vec4 &w) { - return v.x*w.x + v.y*w.y + v.z*w.z + v.w*w.w; + return v.x*w.x+v.y*w.y+v.z*w.z+v.w*w.w; } -nv_scalar & dot(nv_scalar& u, const vec3& v, const vec4& w) +nv_scalar &dot(nv_scalar &u, const vec3 &v, const vec4 &w) { - u = v.x*w.x + v.y*w.y + v.z*w.z; + u = v.x*w.x+v.y*w.y+v.z*w.z; return u; } -nv_scalar dot(const vec3& v, const vec4& w) +nv_scalar dot(const vec3 &v, const vec4 &w) { - return v.x*w.x + v.y*w.y + v.z*w.z; + return v.x*w.x+v.y*w.y+v.z*w.z; } -nv_scalar & dot(nv_scalar& u, const vec4& v, const vec3& w) +nv_scalar &dot(nv_scalar &u, const vec4 &v, const vec3 &w) { - u = v.x*w.x + v.y*w.y + v.z*w.z; + u = v.x*w.x+v.y*w.y+v.z*w.z; return u; } -nv_scalar dot(const vec4& v, const vec3& w) +nv_scalar dot(const vec4 &v, const vec3 &w) { - return v.x*w.x + v.y*w.y + v.z*w.z; + return v.x*w.x+v.y*w.y+v.z*w.z; } -vec3 & reflect(vec3& r, const vec3& n, const vec3& l) +vec3 &reflect(vec3 &r, const vec3 &n, const vec3 &l) { nv_scalar n_dot_l; - n_dot_l = nv_two * dot(n_dot_l,n,l); - mult(r,l,-nv_one); - madd(r,n,n_dot_l); + n_dot_l = nv_two*dot(n_dot_l, n, l); + mult(r, l, -nv_one); + madd(r, n, n_dot_l); return r; } -vec3 & madd(vec3 & u, const vec3& v, const nv_scalar& lambda) +vec3 &madd(vec3 &u, const vec3 &v, const nv_scalar &lambda) { u.x += v.x*lambda; u.y += v.y*lambda; @@ -121,7 +117,7 @@ vec3 & madd(vec3 & u, const vec3& v, const nv_scalar& lambda) return u; } -vec3 & mult(vec3 & u, const vec3& v, const nv_scalar& lambda) +vec3 &mult(vec3 &u, const vec3 &v, const nv_scalar &lambda) { u.x = v.x*lambda; u.y = v.y*lambda; @@ -129,7 +125,7 @@ vec3 & mult(vec3 & u, const vec3& v, const nv_scalar& lambda) return u; } -vec3 & mult(vec3 & u, const vec3& v, const vec3& w) +vec3 &mult(vec3 &u, const vec3 &v, const vec3 &w) { u.x = v.x*w.x; u.y = v.y*w.y; @@ -137,23 +133,23 @@ vec3 & mult(vec3 & u, const vec3& v, const vec3& w) return u; } -vec3 & sub(vec3 & u, const vec3& v, const vec3& w) +vec3 &sub(vec3 &u, const vec3 &v, const vec3 &w) { - u.x = v.x - w.x; - u.y = v.y - w.y; - u.z = v.z - w.z; + u.x = v.x-w.x; + u.y = v.y-w.y; + u.z = v.z-w.z; return u; } -vec3 & add(vec3 & u, const vec3& v, const vec3& w) +vec3 &add(vec3 &u, const vec3 &v, const vec3 &w) { - u.x = v.x + w.x; - u.y = v.y + w.y; - u.z = v.z + w.z; + u.x = v.x+w.x; + u.y = v.y+w.y; + u.z = v.z+w.z; return u; } -vec3 & scale(vec3& u, const nv_scalar s) +vec3 &scale(vec3 &u, const nv_scalar s) { u.x *= s; u.y *= s; @@ -161,7 +157,7 @@ vec3 & scale(vec3& u, const nv_scalar s) return u; } -vec4 & scale(vec4& u, const nv_scalar s) +vec4 &scale(vec4 &u, const nv_scalar s) { u.x *= s; u.y *= s; @@ -170,129 +166,129 @@ vec4 & scale(vec4& u, const nv_scalar s) return u; } -vec3 & mult(vec3& u, const mat3& M, const vec3& v) +vec3 &mult(vec3 &u, const mat3 &M, const vec3 &v) { - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z; return u; } -vec3 & mult(vec3& u, const vec3& v, const mat3& M) +vec3 &mult(vec3 &u, const vec3 &v, const mat3 &M) { - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z; return u; } -const vec3 operator*(const mat3& M, const vec3& v) +const vec3 operator*(const mat3 &M, const vec3 &v) { - vec3 u; - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z; + vec3 u; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z; return u; } -const vec3 operator*(const vec3& v, const mat3& M) +const vec3 operator*(const vec3 &v, const mat3 &M) { - vec3 u; - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z; + vec3 u; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z; return u; } -vec4 & mult(vec4& u, const mat4& M, const vec4& v) +vec4 &mult(vec4 &u, const mat4 &M, const vec4 &v) { - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z + M.a03 * v.w; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z + M.a13 * v.w; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z + M.a23 * v.w; - u.w = M.a30 * v.x + M.a31 * v.y + M.a32 * v.z + M.a33 * v.w; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z+M.a03*v.w; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z+M.a13*v.w; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z+M.a23*v.w; + u.w = M.a30*v.x+M.a31*v.y+M.a32*v.z+M.a33*v.w; return u; } -vec4 & mult(vec4& u, const vec4& v, const mat4& M) +vec4 &mult(vec4 &u, const vec4 &v, const mat4 &M) { - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z + M.a30 * v.w; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z + M.a31 * v.w; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z + M.a32 * v.w; - u.w = M.a03 * v.x + M.a13 * v.y + M.a23 * v.z + M.a33 * v.w; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z+M.a30*v.w; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z+M.a31*v.w; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z+M.a32*v.w; + u.w = M.a03*v.x+M.a13*v.y+M.a23*v.z+M.a33*v.w; return u; } -const vec4 operator*(const mat4& M, const vec4& v) +const vec4 operator*(const mat4 &M, const vec4 &v) { - vec4 u; - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z + M.a03 * v.w; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z + M.a13 * v.w; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z + M.a23 * v.w; - u.w = M.a30 * v.x + M.a31 * v.y + M.a32 * v.z + M.a33 * v.w; + vec4 u; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z+M.a03*v.w; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z+M.a13*v.w; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z+M.a23*v.w; + u.w = M.a30*v.x+M.a31*v.y+M.a32*v.z+M.a33*v.w; return u; } -const vec4 operator*(const vec4& v, const mat4& M) +const vec4 operator*(const vec4 &v, const mat4 &M) { - vec4 u; - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z + M.a30 * v.w; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z + M.a31 * v.w; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z + M.a32 * v.w; - u.w = M.a03 * v.x + M.a13 * v.y + M.a23 * v.z + M.a33 * v.w; + vec4 u; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z+M.a30*v.w; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z+M.a31*v.w; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z+M.a32*v.w; + u.w = M.a03*v.x+M.a13*v.y+M.a23*v.z+M.a33*v.w; return u; } -vec3 & mult_pos(vec3& u, const mat4& M, const vec3& v) +vec3 &mult_pos(vec3 &u, const mat4 &M, const vec3 &v) { - nv_scalar oow = nv_one / (v.x * M.a30 + v.y * M.a31 + v.z * M.a32 + M.a33); - u.x = (M.a00 * v.x + M.a01 * v.y + M.a02 * v.z + M.a03) * oow; - u.y = (M.a10 * v.x + M.a11 * v.y + M.a12 * v.z + M.a13) * oow; - u.z = (M.a20 * v.x + M.a21 * v.y + M.a22 * v.z + M.a23) * oow; + nv_scalar oow = nv_one/(v.x*M.a30+v.y*M.a31+v.z*M.a32+M.a33); + u.x = (M.a00*v.x+M.a01*v.y+M.a02*v.z+M.a03)*oow; + u.y = (M.a10*v.x+M.a11*v.y+M.a12*v.z+M.a13)*oow; + u.z = (M.a20*v.x+M.a21*v.y+M.a22*v.z+M.a23)*oow; return u; } -vec3 & mult_pos(vec3& u, const vec3& v, const mat4& M) +vec3 &mult_pos(vec3 &u, const vec3 &v, const mat4 &M) { - nv_scalar oow = nv_one / (v.x * M.a03 + v.y * M.a13 + v.z * M.a23 + M.a33); - u.x = (M.a00 * v.x + M.a10 * v.y + M.a20 * v.z + M.a30) * oow; - u.y = (M.a01 * v.x + M.a11 * v.y + M.a21 * v.z + M.a31) * oow; - u.z = (M.a02 * v.x + M.a12 * v.y + M.a22 * v.z + M.a32) * oow; + nv_scalar oow = nv_one/(v.x*M.a03+v.y*M.a13+v.z*M.a23+M.a33); + u.x = (M.a00*v.x+M.a10*v.y+M.a20*v.z+M.a30)*oow; + u.y = (M.a01*v.x+M.a11*v.y+M.a21*v.z+M.a31)*oow; + u.z = (M.a02*v.x+M.a12*v.y+M.a22*v.z+M.a32)*oow; return u; } -vec3 & mult_dir(vec3& u, const mat4& M, const vec3& v) +vec3 &mult_dir(vec3 &u, const mat4 &M, const vec3 &v) { - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z; return u; } -vec3 & mult_dir(vec3& u, const vec3& v, const mat4& M) +vec3 &mult_dir(vec3 &u, const vec3 &v, const mat4 &M) { - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z; return u; } -vec3 & mult(vec3& u, const mat4& M, const vec3& v) +vec3 &mult(vec3 &u, const mat4 &M, const vec3 &v) { - u.x = M.a00 * v.x + M.a01 * v.y + M.a02 * v.z + M.a03; - u.y = M.a10 * v.x + M.a11 * v.y + M.a12 * v.z + M.a13; - u.z = M.a20 * v.x + M.a21 * v.y + M.a22 * v.z + M.a23; + u.x = M.a00*v.x+M.a01*v.y+M.a02*v.z+M.a03; + u.y = M.a10*v.x+M.a11*v.y+M.a12*v.z+M.a13; + u.z = M.a20*v.x+M.a21*v.y+M.a22*v.z+M.a23; return u; } -vec3 & mult(vec3& u, const vec3& v, const mat4& M) +vec3 &mult(vec3 &u, const vec3 &v, const mat4 &M) { - u.x = M.a00 * v.x + M.a10 * v.y + M.a20 * v.z + M.a30; - u.y = M.a01 * v.x + M.a11 * v.y + M.a21 * v.z + M.a31; - u.z = M.a02 * v.x + M.a12 * v.y + M.a22 * v.z + M.a32; + u.x = M.a00*v.x+M.a10*v.y+M.a20*v.z+M.a30; + u.y = M.a01*v.x+M.a11*v.y+M.a21*v.z+M.a31; + u.z = M.a02*v.x+M.a12*v.y+M.a22*v.z+M.a32; return u; } -mat4 & add(mat4& A, const mat4& B) +mat4 &add(mat4 &A, const mat4 &B) { A.a00 += B.a00; A.a10 += B.a10; @@ -313,7 +309,7 @@ mat4 & add(mat4& A, const mat4& B) return A; } -mat3 & add(mat3& A, const mat3& B) +mat3 &add(mat3 &A, const mat3 &B) { A.a00 += B.a00; A.a10 += B.a10; @@ -337,46 +333,46 @@ mat3 & add(mat3& A, const mat3& B) // // C.a30 C.a31 C.a32 C.a33 = A.a30 A.a31 A.a32 A.a33 * B.a30 B.a31 B.a32 B.a33 -mat4 & mult(mat4& C, const mat4& A, const mat4& B) -{ - C.a00 = A.a00 * B.a00 + A.a01 * B.a10 + A.a02 * B.a20 + A.a03 * B.a30; - C.a10 = A.a10 * B.a00 + A.a11 * B.a10 + A.a12 * B.a20 + A.a13 * B.a30; - C.a20 = A.a20 * B.a00 + A.a21 * B.a10 + A.a22 * B.a20 + A.a23 * B.a30; - C.a30 = A.a30 * B.a00 + A.a31 * B.a10 + A.a32 * B.a20 + A.a33 * B.a30; - C.a01 = A.a00 * B.a01 + A.a01 * B.a11 + A.a02 * B.a21 + A.a03 * B.a31; - C.a11 = A.a10 * B.a01 + A.a11 * B.a11 + A.a12 * B.a21 + A.a13 * B.a31; - C.a21 = A.a20 * B.a01 + A.a21 * B.a11 + A.a22 * B.a21 + A.a23 * B.a31; - C.a31 = A.a30 * B.a01 + A.a31 * B.a11 + A.a32 * B.a21 + A.a33 * B.a31; - C.a02 = A.a00 * B.a02 + A.a01 * B.a12 + A.a02 * B.a22 + A.a03 * B.a32; - C.a12 = A.a10 * B.a02 + A.a11 * B.a12 + A.a12 * B.a22 + A.a13 * B.a32; - C.a22 = A.a20 * B.a02 + A.a21 * B.a12 + A.a22 * B.a22 + A.a23 * B.a32; - C.a32 = A.a30 * B.a02 + A.a31 * B.a12 + A.a32 * B.a22 + A.a33 * B.a32; - C.a03 = A.a00 * B.a03 + A.a01 * B.a13 + A.a02 * B.a23 + A.a03 * B.a33; - C.a13 = A.a10 * B.a03 + A.a11 * B.a13 + A.a12 * B.a23 + A.a13 * B.a33; - C.a23 = A.a20 * B.a03 + A.a21 * B.a13 + A.a22 * B.a23 + A.a23 * B.a33; - C.a33 = A.a30 * B.a03 + A.a31 * B.a13 + A.a32 * B.a23 + A.a33 * B.a33; +mat4 &mult(mat4 &C, const mat4 &A, const mat4 &B) +{ + C.a00 = A.a00*B.a00+A.a01*B.a10+A.a02*B.a20+A.a03*B.a30; + C.a10 = A.a10*B.a00+A.a11*B.a10+A.a12*B.a20+A.a13*B.a30; + C.a20 = A.a20*B.a00+A.a21*B.a10+A.a22*B.a20+A.a23*B.a30; + C.a30 = A.a30*B.a00+A.a31*B.a10+A.a32*B.a20+A.a33*B.a30; + C.a01 = A.a00*B.a01+A.a01*B.a11+A.a02*B.a21+A.a03*B.a31; + C.a11 = A.a10*B.a01+A.a11*B.a11+A.a12*B.a21+A.a13*B.a31; + C.a21 = A.a20*B.a01+A.a21*B.a11+A.a22*B.a21+A.a23*B.a31; + C.a31 = A.a30*B.a01+A.a31*B.a11+A.a32*B.a21+A.a33*B.a31; + C.a02 = A.a00*B.a02+A.a01*B.a12+A.a02*B.a22+A.a03*B.a32; + C.a12 = A.a10*B.a02+A.a11*B.a12+A.a12*B.a22+A.a13*B.a32; + C.a22 = A.a20*B.a02+A.a21*B.a12+A.a22*B.a22+A.a23*B.a32; + C.a32 = A.a30*B.a02+A.a31*B.a12+A.a32*B.a22+A.a33*B.a32; + C.a03 = A.a00*B.a03+A.a01*B.a13+A.a02*B.a23+A.a03*B.a33; + C.a13 = A.a10*B.a03+A.a11*B.a13+A.a12*B.a23+A.a13*B.a33; + C.a23 = A.a20*B.a03+A.a21*B.a13+A.a22*B.a23+A.a23*B.a33; + C.a33 = A.a30*B.a03+A.a31*B.a13+A.a32*B.a23+A.a33*B.a33; return C; } -mat4 mat4::operator*(const mat4& B) const +mat4 mat4::operator*(const mat4 &B) const { mat4 C; - C.a00 = a00 * B.a00 + a01 * B.a10 + a02 * B.a20 + a03 * B.a30; - C.a10 = a10 * B.a00 + a11 * B.a10 + a12 * B.a20 + a13 * B.a30; - C.a20 = a20 * B.a00 + a21 * B.a10 + a22 * B.a20 + a23 * B.a30; - C.a30 = a30 * B.a00 + a31 * B.a10 + a32 * B.a20 + a33 * B.a30; - C.a01 = a00 * B.a01 + a01 * B.a11 + a02 * B.a21 + a03 * B.a31; - C.a11 = a10 * B.a01 + a11 * B.a11 + a12 * B.a21 + a13 * B.a31; - C.a21 = a20 * B.a01 + a21 * B.a11 + a22 * B.a21 + a23 * B.a31; - C.a31 = a30 * B.a01 + a31 * B.a11 + a32 * B.a21 + a33 * B.a31; - C.a02 = a00 * B.a02 + a01 * B.a12 + a02 * B.a22 + a03 * B.a32; - C.a12 = a10 * B.a02 + a11 * B.a12 + a12 * B.a22 + a13 * B.a32; - C.a22 = a20 * B.a02 + a21 * B.a12 + a22 * B.a22 + a23 * B.a32; - C.a32 = a30 * B.a02 + a31 * B.a12 + a32 * B.a22 + a33 * B.a32; - C.a03 = a00 * B.a03 + a01 * B.a13 + a02 * B.a23 + a03 * B.a33; - C.a13 = a10 * B.a03 + a11 * B.a13 + a12 * B.a23 + a13 * B.a33; - C.a23 = a20 * B.a03 + a21 * B.a13 + a22 * B.a23 + a23 * B.a33; - C.a33 = a30 * B.a03 + a31 * B.a13 + a32 * B.a23 + a33 * B.a33; + C.a00 = a00*B.a00+a01*B.a10+a02*B.a20+a03*B.a30; + C.a10 = a10*B.a00+a11*B.a10+a12*B.a20+a13*B.a30; + C.a20 = a20*B.a00+a21*B.a10+a22*B.a20+a23*B.a30; + C.a30 = a30*B.a00+a31*B.a10+a32*B.a20+a33*B.a30; + C.a01 = a00*B.a01+a01*B.a11+a02*B.a21+a03*B.a31; + C.a11 = a10*B.a01+a11*B.a11+a12*B.a21+a13*B.a31; + C.a21 = a20*B.a01+a21*B.a11+a22*B.a21+a23*B.a31; + C.a31 = a30*B.a01+a31*B.a11+a32*B.a21+a33*B.a31; + C.a02 = a00*B.a02+a01*B.a12+a02*B.a22+a03*B.a32; + C.a12 = a10*B.a02+a11*B.a12+a12*B.a22+a13*B.a32; + C.a22 = a20*B.a02+a21*B.a12+a22*B.a22+a23*B.a32; + C.a32 = a30*B.a02+a31*B.a12+a32*B.a22+a33*B.a32; + C.a03 = a00*B.a03+a01*B.a13+a02*B.a23+a03*B.a33; + C.a13 = a10*B.a03+a11*B.a13+a12*B.a23+a13*B.a33; + C.a23 = a20*B.a03+a21*B.a13+a22*B.a23+a23*B.a33; + C.a33 = a30*B.a03+a31*B.a13+a32*B.a23+a33*B.a33; return C; } @@ -388,22 +384,22 @@ mat4 mat4::operator*(const mat4& B) const // // C.a20 C.a21 C.a22 = A.a20 A.a21 A.a22 * B.a20 B.a21 B.a22 -mat3 & mult(mat3& C, const mat3& A, const mat3& B) -{ - C.a00 = A.a00 * B.a00 + A.a01 * B.a10 + A.a02 * B.a20; - C.a10 = A.a10 * B.a00 + A.a11 * B.a10 + A.a12 * B.a20; - C.a20 = A.a20 * B.a00 + A.a21 * B.a10 + A.a22 * B.a20; - C.a01 = A.a00 * B.a01 + A.a01 * B.a11 + A.a02 * B.a21; - C.a11 = A.a10 * B.a01 + A.a11 * B.a11 + A.a12 * B.a21; - C.a21 = A.a20 * B.a01 + A.a21 * B.a11 + A.a22 * B.a21; - C.a02 = A.a00 * B.a02 + A.a01 * B.a12 + A.a02 * B.a22; - C.a12 = A.a10 * B.a02 + A.a11 * B.a12 + A.a12 * B.a22; - C.a22 = A.a20 * B.a02 + A.a21 * B.a12 + A.a22 * B.a22; +mat3 &mult(mat3 &C, const mat3 &A, const mat3 &B) +{ + C.a00 = A.a00*B.a00+A.a01*B.a10+A.a02*B.a20; + C.a10 = A.a10*B.a00+A.a11*B.a10+A.a12*B.a20; + C.a20 = A.a20*B.a00+A.a21*B.a10+A.a22*B.a20; + C.a01 = A.a00*B.a01+A.a01*B.a11+A.a02*B.a21; + C.a11 = A.a10*B.a01+A.a11*B.a11+A.a12*B.a21; + C.a21 = A.a20*B.a01+A.a21*B.a11+A.a22*B.a21; + C.a02 = A.a00*B.a02+A.a01*B.a12+A.a02*B.a22; + C.a12 = A.a10*B.a02+A.a11*B.a12+A.a12*B.a22; + C.a22 = A.a20*B.a02+A.a21*B.a12+A.a22*B.a22; return C; } -mat3 & transpose(mat3& A) +mat3 &transpose(mat3 &A) { nv_scalar tmp; tmp = A.a01; @@ -420,7 +416,7 @@ mat3 & transpose(mat3& A) return A; } -mat4 & transpose(mat4& A) +mat4 &transpose(mat4 &A) { nv_scalar tmp; tmp = A.a01; @@ -449,7 +445,7 @@ mat4 & transpose(mat4& A) return A; } -mat4 & transpose(mat4& B, const mat4& A) +mat4 &transpose(mat4 &B, const mat4 &A) { B.a00 = A.a00; B.a01 = A.a10; @@ -470,7 +466,7 @@ mat4 & transpose(mat4& B, const mat4& A) return B; } -mat3 & transpose(mat3& B, const mat3& A) +mat3 &transpose(mat3 &B, const mat3 &A) { B.a00 = A.a00; B.a01 = A.a10; @@ -493,7 +489,7 @@ mat3 & transpose(mat3& B, const mat3& A) */ nv_scalar det2x2(nv_scalar a1, nv_scalar a2, nv_scalar b1, nv_scalar b2) { - return a1 * b2 - b1 * a2; + return a1*b2-b1*a2; } /* @@ -504,40 +500,40 @@ nv_scalar det2x2(nv_scalar a1, nv_scalar a2, nv_scalar b1, nv_scalar b2) | c1 c2 c3 | */ -nv_scalar det3x3(nv_scalar a1, nv_scalar a2, nv_scalar a3, - nv_scalar b1, nv_scalar b2, nv_scalar b3, - nv_scalar c1, nv_scalar c2, nv_scalar c3) +nv_scalar det3x3(nv_scalar a1, nv_scalar a2, nv_scalar a3, + nv_scalar b1, nv_scalar b2, nv_scalar b3, + nv_scalar c1, nv_scalar c2, nv_scalar c3) { - return a1 * det2x2(b2, b3, c2, c3) - b1 * det2x2(a2, a3, c2, c3) + c1 * det2x2(a2, a3, b2, b3); + return a1*det2x2(b2, b3, c2, c3)-b1*det2x2(a2, a3, c2, c3)+c1*det2x2(a2, a3, b2, b3); } -mat4 & invert(mat4& B, const mat4& A) +mat4 &invert(mat4 &B, const mat4 &A) { - nv_scalar det,oodet; + nv_scalar det, oodet; - B.a00 = det3x3(A.a11, A.a21, A.a31, A.a12, A.a22, A.a32, A.a13, A.a23, A.a33); + B.a00 = det3x3(A.a11, A.a21, A.a31, A.a12, A.a22, A.a32, A.a13, A.a23, A.a33); B.a10 = -det3x3(A.a10, A.a20, A.a30, A.a12, A.a22, A.a32, A.a13, A.a23, A.a33); - B.a20 = det3x3(A.a10, A.a20, A.a30, A.a11, A.a21, A.a31, A.a13, A.a23, A.a33); + B.a20 = det3x3(A.a10, A.a20, A.a30, A.a11, A.a21, A.a31, A.a13, A.a23, A.a33); B.a30 = -det3x3(A.a10, A.a20, A.a30, A.a11, A.a21, A.a31, A.a12, A.a22, A.a32); B.a01 = -det3x3(A.a01, A.a21, A.a31, A.a02, A.a22, A.a32, A.a03, A.a23, A.a33); - B.a11 = det3x3(A.a00, A.a20, A.a30, A.a02, A.a22, A.a32, A.a03, A.a23, A.a33); + B.a11 = det3x3(A.a00, A.a20, A.a30, A.a02, A.a22, A.a32, A.a03, A.a23, A.a33); B.a21 = -det3x3(A.a00, A.a20, A.a30, A.a01, A.a21, A.a31, A.a03, A.a23, A.a33); - B.a31 = det3x3(A.a00, A.a20, A.a30, A.a01, A.a21, A.a31, A.a02, A.a22, A.a32); + B.a31 = det3x3(A.a00, A.a20, A.a30, A.a01, A.a21, A.a31, A.a02, A.a22, A.a32); - B.a02 = det3x3(A.a01, A.a11, A.a31, A.a02, A.a12, A.a32, A.a03, A.a13, A.a33); + B.a02 = det3x3(A.a01, A.a11, A.a31, A.a02, A.a12, A.a32, A.a03, A.a13, A.a33); B.a12 = -det3x3(A.a00, A.a10, A.a30, A.a02, A.a12, A.a32, A.a03, A.a13, A.a33); - B.a22 = det3x3(A.a00, A.a10, A.a30, A.a01, A.a11, A.a31, A.a03, A.a13, A.a33); + B.a22 = det3x3(A.a00, A.a10, A.a30, A.a01, A.a11, A.a31, A.a03, A.a13, A.a33); B.a32 = -det3x3(A.a00, A.a10, A.a30, A.a01, A.a11, A.a31, A.a02, A.a12, A.a32); B.a03 = -det3x3(A.a01, A.a11, A.a21, A.a02, A.a12, A.a22, A.a03, A.a13, A.a23); - B.a13 = det3x3(A.a00, A.a10, A.a20, A.a02, A.a12, A.a22, A.a03, A.a13, A.a23); + B.a13 = det3x3(A.a00, A.a10, A.a20, A.a02, A.a12, A.a22, A.a03, A.a13, A.a23); B.a23 = -det3x3(A.a00, A.a10, A.a20, A.a01, A.a11, A.a21, A.a03, A.a13, A.a23); - B.a33 = det3x3(A.a00, A.a10, A.a20, A.a01, A.a11, A.a21, A.a02, A.a12, A.a22); + B.a33 = det3x3(A.a00, A.a10, A.a20, A.a01, A.a11, A.a21, A.a02, A.a12, A.a22); - det = (A.a00 * B.a00) + (A.a01 * B.a10) + (A.a02 * B.a20) + (A.a03 * B.a30); + det = (A.a00*B.a00)+(A.a01*B.a10)+(A.a02*B.a20)+(A.a03*B.a30); - oodet = nv_one / det; + oodet = nv_one/det; B.a00 *= oodet; B.a10 *= oodet; @@ -562,7 +558,7 @@ mat4 & invert(mat4& B, const mat4& A) return B; } -mat4 & invert_rot_trans(mat4& B, const mat4& A) +mat4 &invert_rot_trans(mat4 &B, const mat4 &A) { B.a00 = A.a00; B.a10 = A.a01; @@ -576,88 +572,94 @@ mat4 & invert_rot_trans(mat4& B, const mat4& A) B.a12 = A.a21; B.a22 = A.a22; B.a32 = A.a32; - B.a03 = - (A.a00 * A.a03 + A.a10 * A.a13 + A.a20 * A.a23); - B.a13 = - (A.a01 * A.a03 + A.a11 * A.a13 + A.a21 * A.a23); - B.a23 = - (A.a02 * A.a03 + A.a12 * A.a13 + A.a22 * A.a23); + B.a03 = - (A.a00*A.a03+A.a10*A.a13+A.a20*A.a23); + B.a13 = - (A.a01*A.a03+A.a11*A.a13+A.a21*A.a23); + B.a23 = - (A.a02*A.a03+A.a12*A.a13+A.a22*A.a23); B.a33 = A.a33; return B; } -nv_scalar det(const mat3& A) +nv_scalar det(const mat3 &A) { - return det3x3(A.a00, A.a01, A.a02, - A.a10, A.a11, A.a12, - A.a20, A.a21, A.a22); + return det3x3(A.a00, A.a01, A.a02, + A.a10, A.a11, A.a12, + A.a20, A.a21, A.a22); } -mat3 & invert(mat3& B, const mat3& A) +mat3 &invert(mat3 &B, const mat3 &A) { - nv_scalar det,oodet; + nv_scalar det, oodet; - B.a00 = (A.a11 * A.a22 - A.a21 * A.a12); - B.a10 = -(A.a10 * A.a22 - A.a20 * A.a12); - B.a20 = (A.a10 * A.a21 - A.a20 * A.a11); - B.a01 = -(A.a01 * A.a22 - A.a21 * A.a02); - B.a11 = (A.a00 * A.a22 - A.a20 * A.a02); - B.a21 = -(A.a00 * A.a21 - A.a20 * A.a01); - B.a02 = (A.a01 * A.a12 - A.a11 * A.a02); - B.a12 = -(A.a00 * A.a12 - A.a10 * A.a02); - B.a22 = (A.a00 * A.a11 - A.a10 * A.a01); + B.a00 = (A.a11*A.a22-A.a21*A.a12); + B.a10 = -(A.a10*A.a22-A.a20*A.a12); + B.a20 = (A.a10*A.a21-A.a20*A.a11); + B.a01 = -(A.a01*A.a22-A.a21*A.a02); + B.a11 = (A.a00*A.a22-A.a20*A.a02); + B.a21 = -(A.a00*A.a21-A.a20*A.a01); + B.a02 = (A.a01*A.a12-A.a11*A.a02); + B.a12 = -(A.a00*A.a12-A.a10*A.a02); + B.a22 = (A.a00*A.a11-A.a10*A.a01); - det = (A.a00 * B.a00) + (A.a01 * B.a10) + (A.a02 * B.a20); - - oodet = nv_one / det; + det = (A.a00*B.a00)+(A.a01*B.a10)+(A.a02*B.a20); - B.a00 *= oodet; B.a01 *= oodet; B.a02 *= oodet; - B.a10 *= oodet; B.a11 *= oodet; B.a12 *= oodet; - B.a20 *= oodet; B.a21 *= oodet; B.a22 *= oodet; + oodet = nv_one/det; + + B.a00 *= oodet; + B.a01 *= oodet; + B.a02 *= oodet; + B.a10 *= oodet; + B.a11 *= oodet; + B.a12 *= oodet; + B.a20 *= oodet; + B.a21 *= oodet; + B.a22 *= oodet; return B; } -vec3 & normalize(vec3& u) +vec3 &normalize(vec3 &u) { - nv_scalar norm = _sqrt(u.x * u.x + u.y * u.y + u.z * u.z); - if (norm > nv_eps) - norm = nv_one / norm; + nv_scalar norm = _sqrt(u.x*u.x+u.y*u.y+u.z*u.z); + if (norm>nv_eps) + norm = nv_one/norm; else norm = nv_zero; - return scale(u,norm); + return scale(u, norm); } -vec4 & normalize(vec4& u) +vec4 &normalize(vec4 &u) { - nv_scalar norm = _sqrt(u.x * u.x + u.y * u.y + u.z * u.z + u.w * u.w); - if (norm > nv_eps) - norm = nv_one / norm; + nv_scalar norm = _sqrt(u.x*u.x+u.y*u.y+u.z*u.z+u.w*u.w); + if (norm>nv_eps) + norm = nv_one/norm; else norm = nv_zero; - return scale(u,norm); + return scale(u, norm); } -quat & normalize(quat & p) +quat &normalize(quat &p) { - nv_scalar norm = _sqrt(p.x * p.x + p.y * p.y + p.z * p.z + p.w * p.w); - if (norm > nv_eps) - norm = nv_one / norm; + nv_scalar norm = _sqrt(p.x*p.x+p.y*p.y+p.z*p.z+p.w*p.w); + if (norm>nv_eps) + norm = nv_one/norm; else norm = nv_zero; p.x *= norm; p.y *= norm; p.z *= norm; p.w *= norm; - return p; + return p; } -mat4 & look_at(mat4& M, const vec3& eye, const vec3& center, const vec3& up) +mat4 &look_at(mat4 &M, const vec3 &eye, const vec3 ¢er, const vec3 &up) { vec3 x, y, z; // make rotation matrix // Z vector - z.x = eye.x - center.x; - z.y = eye.y - center.y; - z.z = eye.z - center.z; + z.x = eye.x-center.x; + z.y = eye.y-center.y; + z.z = eye.z-center.z; normalize(z); // Y vector @@ -666,228 +668,242 @@ mat4 & look_at(mat4& M, const vec3& eye, const vec3& center, const vec3& up) y.z = up.z; // X vector = Y cross Z - cross(x,y,z); + cross(x, y, z); // Recompute Y = Z cross X - cross(y,z,x); + cross(y, z, x); // cross product gives area of parallelogram, which is < 1.0 for // non-perpendicular unit-length vectors; so normalize x, y here normalize(x); normalize(y); - M.a00 = x.x; M.a01 = x.y; M.a02 = x.z; M.a03 = -x.x * eye.x - x.y * eye.y - x.z*eye.z; - M.a10 = y.x; M.a11 = y.y; M.a12 = y.z; M.a13 = -y.x * eye.x - y.y * eye.y - y.z*eye.z; - M.a20 = z.x; M.a21 = z.y; M.a22 = z.z; M.a23 = -z.x * eye.x - z.y * eye.y - z.z*eye.z; - M.a30 = nv_zero; M.a31 = nv_zero; M.a32 = nv_zero; M.a33 = nv_one; + M.a00 = x.x; + M.a01 = x.y; + M.a02 = x.z; + M.a03 = -x.x*eye.x-x.y*eye.y-x.z*eye.z; + M.a10 = y.x; + M.a11 = y.y; + M.a12 = y.z; + M.a13 = -y.x*eye.x-y.y*eye.y-y.z*eye.z; + M.a20 = z.x; + M.a21 = z.y; + M.a22 = z.z; + M.a23 = -z.x*eye.x-z.y*eye.y-z.z*eye.z; + M.a30 = nv_zero; + M.a31 = nv_zero; + M.a32 = nv_zero; + M.a33 = nv_one; return M; } -mat4 & frustum(mat4& M, const nv_scalar l, const nv_scalar r, const nv_scalar b, - const nv_scalar t, const nv_scalar n, const nv_scalar f) +mat4 &frustum(mat4 &M, const nv_scalar l, const nv_scalar r, const nv_scalar b, + const nv_scalar t, const nv_scalar n, const nv_scalar f) { - M.a00 = (nv_two*n) / (r-l); + M.a00 = (nv_two*n)/(r-l); M.a10 = 0.0; M.a20 = 0.0; M.a30 = 0.0; M.a01 = 0.0; - M.a11 = (nv_two*n) / (t-b); + M.a11 = (nv_two*n)/(t-b); M.a21 = 0.0; M.a31 = 0.0; - M.a02 = (r+l) / (r-l); - M.a12 = (t+b) / (t-b); - M.a22 = -(f+n) / (f-n); + M.a02 = (r+l)/(r-l); + M.a12 = (t+b)/(t-b); + M.a22 = -(f+n)/(f-n); M.a32 = -nv_one; M.a03 = 0.0; M.a13 = 0.0; - M.a23 = -(nv_two*f*n) / (f-n); + M.a23 = -(nv_two*f*n)/(f-n); M.a33 = 0.0; return M; } -mat4 & perspective(mat4& M, const nv_scalar fovy, const nv_scalar aspect, const nv_scalar n, const nv_scalar f) +mat4 &perspective(mat4 &M, const nv_scalar fovy, const nv_scalar aspect, const nv_scalar n, const nv_scalar f) { nv_scalar xmin, xmax, ymin, ymax; - ymax = n * tan(fovy * nv_to_rad * nv_zero_5); + ymax = n*tan(fovy*nv_to_rad*nv_zero_5); ymin = -ymax; - xmin = ymin * aspect; - xmax = ymax * aspect; + xmin = ymin*aspect; + xmax = ymax*aspect; return frustum(M, xmin, xmax, ymin, ymax, n, f); } const quat quat::Identity(0, 0, 0, 1); -quat::quat(nv_scalar x, nv_scalar y, nv_scalar z, nv_scalar w) : x(x), y(y), z(z), w(w) -{ -} +quat::quat(nv_scalar x, nv_scalar y, nv_scalar z, nv_scalar w) : x(x), y(y), z(z), w(w) {} -quat::quat(const quat& quat) +quat::quat(const quat &quat) { - x = quat.x; - y = quat.y; - z = quat.z; - w = quat.w; + x = quat.x; + y = quat.y; + z = quat.z; + w = quat.w; } -quat::quat(const vec3& axis, nv_scalar angle) +quat::quat(const vec3 &axis, nv_scalar angle) { - nv_scalar len = axis.norm(); - if (len) { - nv_scalar invLen = 1 / len; - nv_scalar angle2 = angle / 2; - nv_scalar scale = _sin(angle2) * invLen; - x = scale * axis[0]; - y = scale * axis[1]; - z = scale * axis[2]; - w = _cos(angle2); - } + nv_scalar len = axis.norm(); + if (len) + { + nv_scalar invLen = 1/len; + nv_scalar angle2 = angle/2; + nv_scalar scale = _sin(angle2)*invLen; + x = scale*axis[0]; + y = scale*axis[1]; + z = scale*axis[2]; + w = _cos(angle2); + } } -quat::quat(const mat3& rot) +quat::quat(const mat3 &rot) { - FromMatrix(rot); + FromMatrix(rot); } -quat& quat::operator=(const quat& quat) +quat &quat::operator=(const quat &quat) { - x = quat.x; - y = quat.y; - z = quat.z; - w = quat.w; - return *this; + x = quat.x; + y = quat.y; + z = quat.z; + w = quat.w; + return *this; } quat quat::Inverse() { - return quat(- x, - y, - z, w); + return quat(- x, - y, - z, w); } void quat::Normalize() { - nv_scalar len = _sqrt(x * x + y * y + z * z + w * w); - if (len > 0) { - nv_scalar invLen = 1 / len; - x *= invLen; - y *= invLen; - z *= invLen; - w *= invLen; - } -} - -void quat::FromMatrix(const mat3& mat) -{ - nv_scalar trace = mat(0, 0) + mat(1, 1) + mat(2, 2); - if (trace > 0) { - nv_scalar scale = _sqrt(trace + 1.0f); - w = 0.5f * scale; - scale = 0.5f / scale; - x = scale * (mat(2, 1) - mat(1, 2)); - y = scale * (mat(0, 2) - mat(2, 0)); - z = scale * (mat(1, 0) - mat(0, 1)); - } - else { - static int next[] = { 1, 2, 0 }; - int i = 0; - if (mat(1, 1) > mat(0, 0)) - i = 1; - if (mat(2, 2) > mat(i, i)) - i = 2; - int j = next[i]; - int k = next[j]; - nv_scalar scale = _sqrt(mat(i, i) - mat(j, j) - mat(k, k) + 1); - nv_scalar* q[] = { &x, &y, &z }; - *q[i] = 0.5f * scale; - scale = 0.5f / scale; - w = scale * (mat(k, j) - mat(j, k)); - *q[j] = scale * (mat(j, i) + mat(i, j)); - *q[k] = scale * (mat(k, i) + mat(i, k)); - } -} - -void quat::ToMatrix(mat3& mat) const -{ - nv_scalar x2 = x * 2; - nv_scalar y2 = y * 2; - nv_scalar z2 = z * 2; - nv_scalar wx = x2 * w; - nv_scalar wy = y2 * w; - nv_scalar wz = z2 * w; - nv_scalar xx = x2 * x; - nv_scalar xy = y2 * x; - nv_scalar xz = z2 * x; - nv_scalar yy = y2 * y; - nv_scalar yz = z2 * y; - nv_scalar zz = z2 * z; - mat(0, 0) = 1 - (yy + zz); - mat(0, 1) = xy - wz; - mat(0, 2) = xz + wy; - mat(1, 0) = xy + wz; - mat(1, 1) = 1 - (xx + zz); - mat(1, 2) = yz - wx; - mat(2, 0) = xz - wy; - mat(2, 1) = yz + wx; - mat(2, 2) = 1 - (xx + yy); -} - -const quat operator*(const quat& p, const quat& q) -{ - return quat( - p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y, - p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z, - p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x, - p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z - ); -} - -quat& quat::operator*=(const quat& quat) -{ - *this = *this * quat; - return *this; -} - -mat3 & quat_2_mat(mat3& M, const quat& q) -{ - q.ToMatrix(M); + nv_scalar len = _sqrt(x*x+y*y+z*z+w*w); + if (len>0) + { + nv_scalar invLen = 1/len; + x *= invLen; + y *= invLen; + z *= invLen; + w *= invLen; + } +} + +void quat::FromMatrix(const mat3 &mat) +{ + nv_scalar trace = mat(0, 0)+mat(1, 1)+mat(2, 2); + if (trace>0) + { + nv_scalar scale = _sqrt(trace+1.0f); + w = 0.5f*scale; + scale = 0.5f/scale; + x = scale*(mat(2, 1)-mat(1, 2)); + y = scale*(mat(0, 2)-mat(2, 0)); + z = scale*(mat(1, 0)-mat(0, 1)); + } + else + { + static int next[] = {1, 2, 0}; + int i = 0; + if (mat(1, 1)>mat(0, 0)) + i = 1; + if (mat(2, 2)>mat(i, i)) + i = 2; + int j = next[i]; + int k = next[j]; + nv_scalar scale = _sqrt(mat(i, i)-mat(j, j)-mat(k, k)+1); + nv_scalar *q[] = {&x, &y, &z}; + *q[i] = 0.5f*scale; + scale = 0.5f/scale; + w = scale*(mat(k, j)-mat(j, k)); + *q[j] = scale*(mat(j, i)+mat(i, j)); + *q[k] = scale*(mat(k, i)+mat(i, k)); + } +} + +void quat::ToMatrix(mat3 &mat) const +{ + nv_scalar x2 = x*2; + nv_scalar y2 = y*2; + nv_scalar z2 = z*2; + nv_scalar wx = x2*w; + nv_scalar wy = y2*w; + nv_scalar wz = z2*w; + nv_scalar xx = x2*x; + nv_scalar xy = y2*x; + nv_scalar xz = z2*x; + nv_scalar yy = y2*y; + nv_scalar yz = z2*y; + nv_scalar zz = z2*z; + mat(0, 0) = 1-(yy+zz); + mat(0, 1) = xy-wz; + mat(0, 2) = xz+wy; + mat(1, 0) = xy+wz; + mat(1, 1) = 1-(xx+zz); + mat(1, 2) = yz-wx; + mat(2, 0) = xz-wy; + mat(2, 1) = yz+wx; + mat(2, 2) = 1-(xx+yy); +} + +const quat operator*(const quat &p, const quat &q) +{ + return quat( + p.w*q.x+p.x*q.w+p.y*q.z-p.z*q.y, + p.w*q.y+p.y*q.w+p.z*q.x-p.x*q.z, + p.w*q.z+p.z*q.w+p.x*q.y-p.y*q.x, + p.w*q.w-p.x*q.x-p.y*q.y-p.z*q.z + ); +} + +quat &quat::operator*=(const quat &quat) +{ + *this = *this*quat; + return *this; +} + +mat3 &quat_2_mat(mat3 &M, const quat &q) +{ + q.ToMatrix(M); return M; } -quat & mat_2_quat(quat& q, const mat3& M) +quat &mat_2_quat(quat &q, const mat3 &M) { - q.FromMatrix(M); + q.FromMatrix(M); return q; -} +} -quat & mat_2_quat(quat& q, const mat4& M) +quat &mat_2_quat(quat &q, const mat4 &M) { - mat3 m; - M.get_rot(m); - q.FromMatrix(m); + mat3 m; + M.get_rot(m); + q.FromMatrix(m); return q; -} +} /* Given an axis and angle, compute quaternion. */ -quat & axis_to_quat(quat& q, const vec3& a, const nv_scalar phi) +quat &axis_to_quat(quat &q, const vec3 &a, const nv_scalar phi) { vec3 tmp(a.x, a.y, a.z); normalize(tmp); - nv_scalar s = _sin(phi/nv_two); - q.x = s * tmp.x; - q.y = s * tmp.y; - q.z = s * tmp.z; + nv_scalar s = _sin(phi/nv_two); + q.x = s*tmp.x; + q.y = s*tmp.y; + q.z = s*tmp.z; q.w = _cos(phi/nv_two); return q; } -quat & conj(quat & p) +quat &conj(quat &p) { p.x = -p.x; p.y = -p.y; @@ -895,7 +911,7 @@ quat & conj(quat & p) return p; } - quat & conj(quat& p, const quat& q) +quat &conj(quat &p, const quat &q) { p.x = -q.x; p.y = -q.y; @@ -904,7 +920,7 @@ quat & conj(quat & p) return p; } - quat & add_quats(quat& p, const quat& q1, const quat& q2) +quat &add_quats(quat &p, const quat &q1, const quat &q2) { quat t1, t2; @@ -918,200 +934,207 @@ quat & conj(quat & p) t2.y *= q1.w; t2.z *= q1.w; - p.x = (q2.y * q1.z) - (q2.z * q1.y) + t1.x + t2.x; - p.y = (q2.z * q1.x) - (q2.x * q1.z) + t1.y + t2.y; - p.z = (q2.x * q1.y) - (q2.y * q1.x) + t1.z + t2.z; - p.w = q1.w * q2.w - (q1.x * q2.x + q1.y * q2.y + q1.z * q2.z); + p.x = (q2.y*q1.z)-(q2.z*q1.y)+t1.x+t2.x; + p.y = (q2.z*q1.x)-(q2.x*q1.z)+t1.y+t2.y; + p.z = (q2.x*q1.y)-(q2.y*q1.x)+t1.z+t2.z; + p.w = q1.w*q2.w-(q1.x*q2.x+q1.y*q2.y+q1.z*q2.z); return p; } -nv_scalar & dot(nv_scalar& s, const quat& q1, const quat& q2) +nv_scalar &dot(nv_scalar &s, const quat &q1, const quat &q2) { - s = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; + s = q1.x*q2.x+q1.y*q2.y+q1.z*q2.z+q1.w*q2.w; return s; } -nv_scalar dot(const quat& q1, const quat& q2) +nv_scalar dot(const quat &q1, const quat &q2) { - return q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; + return q1.x*q2.x+q1.y*q2.y+q1.z*q2.z+q1.w*q2.w; } #ifndef acosf #define acosf acos #endif -quat & slerp_quats(quat & p, nv_scalar s, const quat & q1, const quat & q2) +quat &slerp_quats(quat &p, nv_scalar s, const quat &q1, const quat &q2) { nv_scalar cosine = dot(q1, q2); - if (cosine < -1) - cosine = -1; - else if (cosine > 1) - cosine = 1; + if (cosine<-1) + cosine = -1; + else if (cosine>1) + cosine = 1; nv_scalar angle = (nv_scalar)acosf(cosine); - if (_abs(angle) < nv_eps) { - p = q1; + if (_abs(angle) nv_eps) - h = (nv_one - phi) / lambda; + cross(w, u, v); + dot(phi, u, v); + dot(lambda, w, w); + if (lambda>nv_eps) + h = (nv_one-phi)/lambda; else h = lambda; - - nv_scalar hxy = w.x * w.y * h; - nv_scalar hxz = w.x * w.z * h; - nv_scalar hyz = w.y * w.z * h; - a00 = phi + w.x * w.x * h; - a01 = hxy - w.z; - a02 = hxz + w.y; + nv_scalar hxy = w.x*w.y*h; + nv_scalar hxz = w.x*w.z*h; + nv_scalar hyz = w.y*w.z*h; + + a00 = phi+w.x*w.x*h; + a01 = hxy-w.z; + a02 = hxz+w.y; - a10 = hxy + w.z; - a11 = phi + w.y * w.y * h; - a12 = hyz - w.x; + a10 = hxy+w.z; + a11 = phi+w.y*w.y*h; + a12 = hyz-w.x; - a20 = hxz - w.y; - a21 = hyz + w.x; - a22 = phi + w.z * w.z * h; + a20 = hxz-w.y; + a21 = hyz+w.x; + a22 = phi+w.z*w.z*h; } -void mat4::set_rot(const quat& q) +void mat4::set_rot(const quat &q) { - mat3 m; - q.ToMatrix(m); - set_rot(m); + mat3 m; + q.ToMatrix(m); + set_rot(m); } // v is normalized // theta in radians -void mat4::set_rot(const nv_scalar& theta, const vec3& v) +void mat4::set_rot(const nv_scalar &theta, const vec3 &v) { nv_scalar ct = nv_scalar(_cos(theta)); nv_scalar st = nv_scalar(_sin(theta)); - nv_scalar xx = v.x * v.x; - nv_scalar yy = v.y * v.y; - nv_scalar zz = v.z * v.z; - nv_scalar xy = v.x * v.y; - nv_scalar xz = v.x * v.z; - nv_scalar yz = v.y * v.z; + nv_scalar xx = v.x*v.x; + nv_scalar yy = v.y*v.y; + nv_scalar zz = v.z*v.z; + nv_scalar xy = v.x*v.y; + nv_scalar xz = v.x*v.z; + nv_scalar yz = v.y*v.z; - a00 = xx + ct*(1-xx); - a01 = xy + ct*(-xy) + st*-v.z; - a02 = xz + ct*(-xz) + st*v.y; + a00 = xx+ct*(1-xx); + a01 = xy+ct*(-xy)+st*-v.z; + a02 = xz+ct*(-xz)+st*v.y; - a10 = xy + ct*(-xy) + st*v.z; - a11 = yy + ct*(1-yy); - a12 = yz + ct*(-yz) + st*-v.x; + a10 = xy+ct*(-xy)+st*v.z; + a11 = yy+ct*(1-yy); + a12 = yz+ct*(-yz)+st*-v.x; - a20 = xz + ct*(-xz) + st*-v.y; - a21 = yz + ct*(-yz) + st*v.x; - a22 = zz + ct*(1-zz); + a20 = xz+ct*(-xz)+st*-v.y; + a21 = yz+ct*(-yz)+st*v.x; + a22 = zz+ct*(1-zz); } -void mat4::set_rot(const vec3& u, const vec3& v) +void mat4::set_rot(const vec3 &u, const vec3 &v) { nv_scalar phi; nv_scalar h; nv_scalar lambda; vec3 w; - cross(w,u,v); - dot(phi,u,v); - dot(lambda,w,w); - if (lambda > nv_eps) - h = (nv_one - phi) / lambda; + cross(w, u, v); + dot(phi, u, v); + dot(lambda, w, w); + if (lambda>nv_eps) + h = (nv_one-phi)/lambda; else h = lambda; - - nv_scalar hxy = w.x * w.y * h; - nv_scalar hxz = w.x * w.z * h; - nv_scalar hyz = w.y * w.z * h; - a00 = phi + w.x * w.x * h; - a01 = hxy - w.z; - a02 = hxz + w.y; + nv_scalar hxy = w.x*w.y*h; + nv_scalar hxz = w.x*w.z*h; + nv_scalar hyz = w.y*w.z*h; - a10 = hxy + w.z; - a11 = phi + w.y * w.y * h; - a12 = hyz - w.x; + a00 = phi+w.x*w.x*h; + a01 = hxy-w.z; + a02 = hxz+w.y; - a20 = hxz - w.y; - a21 = hyz + w.x; - a22 = phi + w.z * w.z * h; + a10 = hxy+w.z; + a11 = phi+w.y*w.y*h; + a12 = hyz-w.x; + + a20 = hxz-w.y; + a21 = hyz+w.x; + a22 = phi+w.z*w.z*h; } -void mat4::set_rot(const mat3& M) +void mat4::set_rot(const mat3 &M) { // copy the 3x3 rotation block - a00 = M.a00; a10 = M.a10; a20 = M.a20; - a01 = M.a01; a11 = M.a11; a21 = M.a21; - a02 = M.a02; a12 = M.a12; a22 = M.a22; + a00 = M.a00; + a10 = M.a10; + a20 = M.a20; + a01 = M.a01; + a11 = M.a11; + a21 = M.a21; + a02 = M.a02; + a12 = M.a12; + a22 = M.a22; } -void mat4::set_translation(const vec3& t) +void mat4::set_translation(const vec3 &t) { a03 = t.x; a13 = t.y; a23 = t.z; } -vec3 & mat4::get_translation(vec3& t) const +vec3 &mat4::get_translation(vec3 &t) const { t.x = a03; t.y = a13; @@ -1119,75 +1142,81 @@ vec3 & mat4::get_translation(vec3& t) const return t; } -mat3 & mat4::get_rot(mat3& M) const +mat3 &mat4::get_rot(mat3 &M) const { // assign the 3x3 rotation block - M.a00 = a00; M.a10 = a10; M.a20 = a20; - M.a01 = a01; M.a11 = a11; M.a21 = a21; - M.a02 = a02; M.a12 = a12; M.a22 = a22; + M.a00 = a00; + M.a10 = a10; + M.a20 = a20; + M.a01 = a01; + M.a11 = a11; + M.a21 = a21; + M.a02 = a02; + M.a12 = a12; + M.a22 = a22; return M; } -quat & mat4::get_rot(quat& q) const +quat &mat4::get_rot(quat &q) const { - mat3 m; - get_rot(m); - q.FromMatrix(m); + mat3 m; + get_rot(m); + q.FromMatrix(m); return q; } -mat3& tangent_basis(mat3& basis, const vec3& v0, const vec3& v1, const vec3& v2, const vec2& t0, const vec2& t1, const vec2& t2, const vec3 & n) +mat3 &tangent_basis(mat3 &basis, const vec3 &v0, const vec3 &v1, const vec3 &v2, const vec2 &t0, const vec2 &t1, const vec2 &t2, const vec3 &n) { vec3 cp; - vec3 e0(v1.x - v0.x, t1.s - t0.s, t1.t - t0.t); - vec3 e1(v2.x - v0.x, t2.s - t0.s, t2.t - t0.t); + vec3 e0(v1.x-v0.x, t1.s-t0.s, t1.t-t0.t); + vec3 e1(v2.x-v0.x, t2.s-t0.s, t2.t-t0.t); - cross(cp,e0,e1); - if ( _abs(cp.x) > nv_eps) + cross(cp, e0, e1); + if (_abs(cp.x)>nv_eps) { - basis.a00 = -cp.y / cp.x; - basis.a10 = -cp.z / cp.x; + basis.a00 = -cp.y/cp.x; + basis.a10 = -cp.z/cp.x; } - e0.x = v1.y - v0.y; - e1.x = v2.y - v0.y; + e0.x = v1.y-v0.y; + e1.x = v2.y-v0.y; - cross(cp,e0,e1); - if ( _abs(cp.x) > nv_eps) + cross(cp, e0, e1); + if (_abs(cp.x)>nv_eps) { - basis.a01 = -cp.y / cp.x; - basis.a11 = -cp.z / cp.x; + basis.a01 = -cp.y/cp.x; + basis.a11 = -cp.z/cp.x; } - e0.x = v1.z - v0.z; - e1.x = v2.z - v0.z; + e0.x = v1.z-v0.z; + e1.x = v2.z-v0.z; - cross(cp,e0,e1); - if ( _abs(cp.x) > nv_eps) + cross(cp, e0, e1); + if (_abs(cp.x)>nv_eps) { - basis.a02 = -cp.y / cp.x; - basis.a12 = -cp.z / cp.x; + basis.a02 = -cp.y/cp.x; + basis.a12 = -cp.z/cp.x; } // tangent... - nv_scalar oonorm = nv_one / _sqrt(basis.a00 * basis.a00 + basis.a01 * basis.a01 + basis.a02 * basis.a02); + nv_scalar oonorm = nv_one/_sqrt(basis.a00*basis.a00+basis.a01*basis.a01+basis.a02*basis.a02); basis.a00 *= oonorm; basis.a01 *= oonorm; basis.a02 *= oonorm; // binormal... - oonorm = nv_one / _sqrt(basis.a10 * basis.a10 + basis.a11 * basis.a11 + basis.a12 * basis.a12); + oonorm = nv_one/_sqrt(basis.a10*basis.a10+basis.a11*basis.a11+basis.a12*basis.a12); basis.a10 *= oonorm; basis.a11 *= oonorm; basis.a12 *= oonorm; // normal... // compute the cross product TxB - basis.a20 = basis.a01*basis.a12 - basis.a02*basis.a11; - basis.a21 = basis.a02*basis.a10 - basis.a00*basis.a12; - basis.a22 = basis.a00*basis.a11 - basis.a01*basis.a10; + basis.a20 = basis.a01*basis.a12-basis.a02*basis.a11; + basis.a21 = basis.a02*basis.a10-basis.a00*basis.a12; + basis.a22 = basis.a00*basis.a11-basis.a01*basis.a10; - oonorm = nv_one / _sqrt(basis.a20 * basis.a20 + basis.a21 * basis.a21 + basis.a22 * basis.a22); + oonorm = nv_one/_sqrt(basis.a20*basis.a20+basis.a21*basis.a21+basis.a22*basis.a22); basis.a20 *= oonorm; basis.a21 *= oonorm; basis.a22 *= oonorm; @@ -1195,11 +1224,11 @@ mat3& tangent_basis(mat3& basis, const vec3& v0, const vec3& v1, const vec3& v2, // Gram-Schmidt orthogonalization process for B // compute the cross product B=NxT to obtain // an orthogonal basis - basis.a10 = basis.a21*basis.a02 - basis.a22*basis.a01; - basis.a11 = basis.a22*basis.a00 - basis.a20*basis.a02; - basis.a12 = basis.a20*basis.a01 - basis.a21*basis.a00; + basis.a10 = basis.a21*basis.a02-basis.a22*basis.a01; + basis.a11 = basis.a22*basis.a00-basis.a20*basis.a02; + basis.a12 = basis.a20*basis.a01-basis.a21*basis.a00; - if (basis.a20 * n.x + basis.a21 * n.y + basis.a22 * n.z < nv_zero) + if (basis.a20*n.x+basis.a21*n.y+basis.a22*n.z nv_one) + if (t>nv_one) t = nv_one; - if (t < -nv_one) + if (t<-nv_one) t = -nv_one; - phi = nv_two * nv_scalar(asin(t)); - axis_to_quat(q,a,phi); + phi = nv_two*nv_scalar(asin(t)); + axis_to_quat(q, a, phi); return q; } -vec3& cube_map_normal(int i, int x, int y, int cubesize, vec3& v) +vec3 &cube_map_normal(int i, int x, int y, int cubesize, vec3 &v) { nv_scalar s, t, sc, tc; - s = (nv_scalar(x) + nv_zero_5) / nv_scalar(cubesize); - t = (nv_scalar(y) + nv_zero_5) / nv_scalar(cubesize); - sc = s * nv_two - nv_one; - tc = t * nv_two - nv_one; + s = (nv_scalar(x)+nv_zero_5)/nv_scalar(cubesize); + t = (nv_scalar(y)+nv_zero_5)/nv_scalar(cubesize); + sc = s*nv_two-nv_one; + tc = t*nv_two-nv_one; - switch (i) + switch (i) { case 0: v.x = nv_one; @@ -1323,18 +1355,18 @@ vec3& cube_map_normal(int i, int x, int y, int cubesize, vec3& v) } // computes the area of a triangle -nv_scalar nv_area(const vec3& v1, const vec3& v2, const vec3& v3) +nv_scalar nv_area(const vec3 &v1, const vec3 &v2, const vec3 &v3) { vec3 cp_sum; vec3 cp; cross(cp_sum, v1, v2); cp_sum += cross(cp, v2, v3); cp_sum += cross(cp, v3, v1); - return nv_norm(cp_sum) * nv_zero_5; + return nv_norm(cp_sum)*nv_zero_5; } // computes the perimeter of a triangle -nv_scalar nv_perimeter(const vec3& v1, const vec3& v2, const vec3& v3) +nv_scalar nv_perimeter(const vec3 &v1, const vec3 &v2, const vec3 &v3) { nv_scalar perim; vec3 diff; @@ -1348,17 +1380,17 @@ nv_scalar nv_perimeter(const vec3& v1, const vec3& v2, const vec3& v3) } // compute the center and radius of the inscribed circle defined by the three vertices -nv_scalar nv_find_in_circle(vec3& center, const vec3& v1, const vec3& v2, const vec3& v3) +nv_scalar nv_find_in_circle(vec3 ¢er, const vec3 &v1, const vec3 &v2, const vec3 &v3) { nv_scalar area = nv_area(v1, v2, v3); // if the area is null - if (area < nv_eps) + if (area&); - bool operator==(const vec2 & u) const + vec2(const nv_scalar *xy) : x(xy[0]), y(xy[1]) { } + + vec2(const vec2 &u) : x(u.x), y(u.y) { } + + vec2(const vec3t &); + + bool operator==(const vec2 &u) const { - return (u.x == x && u.y == y) ? true : false; + return (u.x==x&&u.y==y) ? true : false; } - bool operator!=(const vec2 & u) const + bool operator!=(const vec2 &u) const { - return !(*this == u ); + return !(*this==u); } - vec2 & operator*=(const nv_scalar & lambda) + vec2 &operator*=(const nv_scalar &lambda) { - x*= lambda; - y*= lambda; + x *= lambda; + y *= lambda; return *this; } - vec2 & operator-=(const vec2 & u) + vec2 &operator-=(const vec2 &u) { - x-= u.x; - y-= u.y; + x -= u.x; + y -= u.y; return *this; } - vec2 & operator+=(const vec2 & u) + vec2 &operator+=(const vec2 &u) { - x+= u.x; - y+= u.y; + x += u.x; + y += u.y; return *this; } - nv_scalar & operator[](int i) + nv_scalar &operator[](int i) { return vec_array[i]; } @@ -65,194 +69,256 @@ struct DECLSPEC_NV_MATH vec2 return vec_array[i]; } - union { - struct { - nv_scalar x,y; // standard names for components + union + { + struct + { + nv_scalar x, y; // standard names for components }; - struct { - nv_scalar s,t; // standard names for components + + struct + { + nv_scalar s, t; // standard names for components }; - nv_scalar vec_array[2]; // array access + + nv_scalar vec_array[2]; // array access }; }; -inline const vec2 operator+(const vec2& u, const vec2& v) +inline const vec2 operator+(const vec2 &u, const vec2 &v) { - return vec2(u.x + v.x, u.y + v.y); + return vec2(u.x+v.x, u.y+v.y); } -inline const vec2 operator-(const vec2& u, const vec2& v) +inline const vec2 operator-(const vec2 &u, const vec2 &v) { - return vec2(u.x - v.x, u.y - v.y); + return vec2(u.x-v.x, u.y-v.y); } -inline const vec2 operator*(const nv_scalar s, const vec2& u) +inline const vec2 operator*(const nv_scalar s, const vec2 &u) { - return vec2(s * u.x, s * u.y); + return vec2(s*u.x, s*u.y); } -inline const vec2 operator/(const vec2& u, const nv_scalar s) +inline const vec2 operator/(const vec2 &u, const nv_scalar s) { - return vec2(u.x / s, u.y / s); + return vec2(u.x/s, u.y/s); } -inline const vec2 operator*(const vec2&u, const vec2&v) +inline const vec2 operator*(const vec2 &u, const vec2 &v) { - return vec2(u.x * v.x, u.y * v.y); + return vec2(u.x*v.x, u.y*v.y); } template struct vec3t { - vec3t() { } - vec3t(_T x, _T y, _T z) : x(x), y(y), z(z) { } - vec3t(const _T* xyz) : x(xyz[0]), y(xyz[1]), z(xyz[2]) { } - vec3t(const vec2& u) : x(u.x), y(u.y), z(1.0f) { } - vec3t(const vec3t& u) : x(_T(u.x)), y(_T(u.y)), z(_T(u.z)) { } - vec3t(const vec3t& u) : x(_T(u.x)), y(_T(u.y)), z(_T(u.z)) { } - vec3t(const vec4&); + vec3t() { } + + vec3t(_T x, _T y, _T z) : x(x), y(y), z(z) { } - bool operator==(const vec3t<_T> & u) const { - return (u.x == x && u.y == y && u.z == z) ? true : false; + vec3t(const _T *xyz) : x(xyz[0]), y(xyz[1]), z(xyz[2]) { } + + vec3t(const vec2 &u) : x(u.x), y(u.y), z(1.0f) { } + + vec3t(const vec3t &u) : x(_T(u.x)), y(_T(u.y)), z(_T(u.z)) { } + + vec3t(const vec3t &u) : x(_T(u.x)), y(_T(u.y)), z(_T(u.z)) { } + + vec3t(const vec4 &); + + bool operator==(const vec3t<_T> &u) const + { + return (u.x==x&&u.y==y&&u.z==z) ? true : false; } - bool operator!=( const vec3t<_T>& rhs ) const { - return !(*this == rhs ); + + bool operator!=(const vec3t<_T> &rhs) const + { + return !(*this==rhs); } - vec3t<_T> & operator*=(const _T & lambda) { - x*= lambda; - y*= lambda; - z*= lambda; + + vec3t<_T> &operator*=(const _T &lambda) + { + x *= lambda; + y *= lambda; + z *= lambda; return *this; } - vec3t<_T> operator - () const { - return vec3t<_T>(-x, -y, -z); - } - vec3t<_T> & operator-=(const vec3t<_T> & u) { - x-= u.x; - y-= u.y; - z-= u.z; + + vec3t<_T> operator -() const + { + return vec3t<_T>(-x, -y, -z); + } + + vec3t<_T> &operator-=(const vec3t<_T> &u) + { + x -= u.x; + y -= u.y; + z -= u.z; return *this; } - vec3t<_T> & operator+=(const vec3t<_T> & u) { - x+= u.x; - y+= u.y; - z+= u.z; + + vec3t<_T> &operator+=(const vec3t<_T> &u) + { + x += u.x; + y += u.y; + z += u.z; return *this; } - _T sq_norm() const { return x * x + y * y + z * z; } - _T norm() const { return _sqrt(sq_norm()); } - _T normalize () { - _T _norm = norm(); - if (_norm > nv_eps) _norm = nv_one / _norm; - else _norm = nv_zero; - x *= _norm; - y *= _norm; - z *= _norm; - return _norm; - } - - _T & operator[](int i) { + + _T sq_norm() const + { + return x*x+y*y+z*z; + } + + _T norm() const + { + return _sqrt(sq_norm()); + } + + _T normalize() + { + _T _norm = norm(); + if (_norm>nv_eps) + _norm = nv_one/_norm; + else + _norm = nv_zero; + x *= _norm; + y *= _norm; + z *= _norm; + return _norm; + } + + _T &operator[](int i) + { return vec_array[i]; } - union { - struct { - _T x,y,z; // standard names for components + union + { + struct + { + _T x, y, z; // standard names for components }; - struct { - _T s,t,r; // standard names for components + + struct + { + _T s, t, r; // standard names for components }; - _T vec_array[3]; // array access + + _T vec_array[3]; // array access }; - const _T operator[](int i) const { + const _T operator[](int i) const + { return vec_array[i]; } }; -template inline const vec3t<_T> operator+(const vec3t<_T>& u, const vec3t<_T>& v) { - return vec3t<_T>(u.x + v.x, u.y + v.y, u.z + v.z); +template +inline const vec3t<_T> operator+(const vec3t<_T> &u, const vec3t<_T> &v) +{ + return vec3t<_T>(u.x+v.x, u.y+v.y, u.z+v.z); } -template inline const vec3t<_T> operator-(const vec3t<_T>& u, const vec3t<_T>& v) { - return vec3t<_T>(u.x - v.x, u.y - v.y, u.z - v.z); + +template +inline const vec3t<_T> operator-(const vec3t<_T> &u, const vec3t<_T> &v) +{ + return vec3t<_T>(u.x-v.x, u.y-v.y, u.z-v.z); } -template inline const vec3t<_T> operator^(const vec3t<_T>& u, const vec3t<_T>& v) { - return vec3t<_T>(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x); + +template +inline const vec3t<_T> operator^(const vec3t<_T> &u, const vec3t<_T> &v) +{ + return vec3t<_T>(u.y*v.z-u.z*v.y, u.z*v.x-u.x*v.z, u.x*v.y-u.y*v.x); } -template inline const vec3t<_T> operator*(const _T s, const vec3t<_T>& u) { - return vec3t<_T>(s * u.x, s * u.y, s * u.z); + +template +inline const vec3t<_T> operator*(const _T s, const vec3t<_T> &u) +{ + return vec3t<_T>(s*u.x, s*u.y, s*u.z); } -template inline const vec3t<_T> operator/(const vec3t<_T>& u, const _T s) { - return vec3t<_T>(u.x / s, u.y / s, u.z / s); + +template +inline const vec3t<_T> operator/(const vec3t<_T> &u, const _T s) +{ + return vec3t<_T>(u.x/s, u.y/s, u.z/s); } -template inline const vec3t<_T> operator*(const vec3t<_T>& u, const vec3t<_T>& v) { - return vec3t<_T>(u.x * v.x, u.y * v.y, u.z * v.z); + +template +inline const vec3t<_T> operator*(const vec3t<_T> &u, const vec3t<_T> &v) +{ + return vec3t<_T>(u.x*v.x, u.y*v.y, u.z*v.z); } // -typedef vec3t vec3; -typedef vec3t vec3f; -typedef vec3t vec3d; +typedef vec3t vec3; +typedef vec3t vec3f; +typedef vec3t vec3d; -inline vec2::vec2(const vec3& u) +inline vec2::vec2(const vec3 &u) { - nv_scalar k = 1 / u.z; - x = k * u.x; - y = k * u.y; + nv_scalar k = 1/u.z; + x = k*u.x; + y = k*u.y; } struct DECLSPEC_NV_MATH vec4 { - vec4() { } + vec4() { } + vec4(nv_scalar x, nv_scalar y, nv_scalar z, nv_scalar w) : x(x), y(y), z(z), w(w) { } - vec4(const nv_scalar* xyzw) : x(xyzw[0]), y(xyzw[1]), z(xyzw[2]), w(xyzw[3]) { } - vec4(const vec3& u) : x(u.x), y(u.y), z(u.z), w(1.0f) { } - vec4(const vec4& u) : x(u.x), y(u.y), z(u.z), w(u.w) { } - bool operator==(const vec4 & u) const + vec4(const nv_scalar *xyzw) : x(xyzw[0]), y(xyzw[1]), z(xyzw[2]), w(xyzw[3]) { } + + vec4(const vec3 &u) : x(u.x), y(u.y), z(u.z), w(1.0f) { } + + vec4(const vec4 &u) : x(u.x), y(u.y), z(u.z), w(u.w) { } + + bool operator==(const vec4 &u) const { - return (u.x == x && u.y == y && u.z == z && u.w == w) ? true : false; + return (u.x==x&&u.y==y&&u.z==z&&u.w==w) ? true : false; } - bool operator!=( const vec4& rhs ) const + bool operator!=(const vec4 &rhs) const { - return !(*this == rhs ); + return !(*this==rhs); } - vec4 & operator*=(const nv_scalar & lambda) + vec4 &operator*=(const nv_scalar &lambda) { - x*= lambda; - y*= lambda; - z*= lambda; - w*= lambda; + x *= lambda; + y *= lambda; + z *= lambda; + w *= lambda; return *this; } - vec4 & operator-=(const vec4 & u) + vec4 &operator-=(const vec4 &u) { - x-= u.x; - y-= u.y; - z-= u.z; - w-= u.w; + x -= u.x; + y -= u.y; + z -= u.z; + w -= u.w; return *this; } - vec4 & operator+=(const vec4 & u) + vec4 &operator+=(const vec4 &u) { - x+= u.x; - y+= u.y; - z+= u.z; - w+= u.w; + x += u.x; + y += u.y; + z += u.z; + w += u.w; return *this; } - vec4 operator - () const - { - return vec4(-x, -y, -z, -w); - } + vec4 operator -() const + { + return vec4(-x, -y, -z, -w); + } - nv_scalar & operator[](int i) + nv_scalar &operator[](int i) { return vec_array[i]; } @@ -262,50 +328,57 @@ struct DECLSPEC_NV_MATH vec4 return vec_array[i]; } - union { - struct { - nv_scalar x,y,z,w; // standard names for components + union + { + struct + { + nv_scalar x, y, z, w; // standard names for components }; - struct { - nv_scalar s,t,r,q; // standard names for components + + struct + { + nv_scalar s, t, r, q; // standard names for components }; - nv_scalar vec_array[4]; // array access + + nv_scalar vec_array[4]; // array access }; }; -inline const vec4 operator+(const vec4& u, const vec4& v) +inline const vec4 operator+(const vec4 &u, const vec4 &v) { - return vec4(u.x + v.x, u.y + v.y, u.z + v.z, u.w + v.w); + return vec4(u.x+v.x, u.y+v.y, u.z+v.z, u.w+v.w); } -inline const vec4 operator-(const vec4& u, const vec4& v) +inline const vec4 operator-(const vec4 &u, const vec4 &v) { - return vec4(u.x - v.x, u.y - v.y, u.z - v.z, u.w - v.w); + return vec4(u.x-v.x, u.y-v.y, u.z-v.z, u.w-v.w); } -inline const vec4 operator*(const nv_scalar s, const vec4& u) +inline const vec4 operator*(const nv_scalar s, const vec4 &u) { - return vec4(s * u.x, s * u.y, s * u.z, s * u.w); + return vec4(s*u.x, s*u.y, s*u.z, s*u.w); } -inline const vec4 operator/(const vec4& u, const nv_scalar s) +inline const vec4 operator/(const vec4 &u, const nv_scalar s) { - return vec4(u.x / s, u.y / s, u.z / s, u.w / s); + return vec4(u.x/s, u.y/s, u.z/s, u.w/s); } -inline const vec4 operator*(const vec4& u, const vec4& v) +inline const vec4 operator*(const vec4 &u, const vec4 &v) { - return vec4(u.x * v.x, u.y * v.y, u.z * v.z, u.w * v.w); + return vec4(u.x*v.x, u.y*v.y, u.z*v.z, u.w*v.w); } -template inline vec3t<_T>::vec3t(const vec4& u) { - x = u.x; - y = u.y; - z = u.z; +template +inline vec3t<_T>::vec3t(const vec4 &u) +{ + x = u.x; + y = u.y; + z = u.z; } // quaternion -struct quat; +struct quat; /* for all the matrices...a indicates the element at row x, col y @@ -317,271 +390,307 @@ struct quat; struct DECLSPEC_NV_MATH mat3 { mat3(); - mat3(const nv_scalar * array); - mat3(const mat3 & M); - mat3( const nv_scalar& f0, const nv_scalar& f1, const nv_scalar& f2, - const nv_scalar& f3, const nv_scalar& f4, const nv_scalar& f5, - const nv_scalar& f6, const nv_scalar& f7, const nv_scalar& f8 ) - : a00( f0 ), a10( f1 ), a20( f2 ), - a01( f3 ), a11( f4 ), a21( f5 ), - a02( f6 ), a12( f7 ), a22( f8) { } + mat3(const nv_scalar *array); + mat3(const mat3 &M); + + mat3(const nv_scalar &f0, const nv_scalar &f1, const nv_scalar &f2, + const nv_scalar &f3, const nv_scalar &f4, const nv_scalar &f5, + const nv_scalar &f6, const nv_scalar &f7, const nv_scalar &f8) + : a00(f0), a10(f1), a20(f2), + a01(f3), a11(f4), a21(f5), + a02(f6), a12(f7), a22(f8) { } const vec3 col(const int i) const { - return vec3(&mat_array[i * 3]); + return vec3(&mat_array[i*3]); } const vec3 operator[](int i) const { - return vec3(mat_array[i], mat_array[i + 3], mat_array[i + 6]); + return vec3(mat_array[i], mat_array[i+3], mat_array[i+6]); } - const nv_scalar& operator()(const int& i, const int& j) const + const nv_scalar &operator()(const int &i, const int &j) const { - return mat_array[ j * 3 + i ]; + return mat_array[j*3+i]; } - nv_scalar& operator()(const int& i, const int& j) + nv_scalar &operator()(const int &i, const int &j) { - return mat_array[ j * 3 + i ]; + return mat_array[j*3+i]; } - void set_row(int i, const vec3 & v) + void set_row(int i, const vec3 &v) { mat_array[i] = v.x; - mat_array[i + 3] = v.y; - mat_array[i + 6] = v.z; + mat_array[i+3] = v.y; + mat_array[i+6] = v.z; } - void set_col(int i, const vec3 & v) - { - mat_array[i * 3] = v.x; - mat_array[i * 3 + 1] = v.y; - mat_array[i * 3 + 2] = v.z; - } + void set_col(int i, const vec3 &v) + { + mat_array[i*3] = v.x; + mat_array[i*3+1] = v.y; + mat_array[i*3+2] = v.z; + } - void set_rot(const nv_scalar & theta, const vec3 & v); - void set_rot(const vec3 & u, const vec3 & v); + void set_rot(const nv_scalar &theta, const vec3 &v); + void set_rot(const vec3 &u, const vec3 &v); - union { - struct { - nv_scalar a00, a10, a20; // standard names for components - nv_scalar a01, a11, a21; // standard names for components - nv_scalar a02, a12, a22; // standard names for components + union + { + struct + { + nv_scalar a00, a10, a20; // standard names for components + nv_scalar a01, a11, a21; // standard names for components + nv_scalar a02, a12, a22; // standard names for components }; - nv_scalar mat_array[9]; // array access + + nv_scalar mat_array[9]; // array access }; }; -const vec3 operator*(const mat3&, const vec3&); -const vec3 operator*(const vec3&, const mat3&); +const vec3 operator*(const mat3 &, const vec3 &); +const vec3 operator*(const vec3 &, const mat3 &); struct DECLSPEC_NV_MATH mat4 { mat4(); - mat4(const nv_scalar * array); - mat4(const mat4 & M); - - mat4( const nv_scalar& f0, const nv_scalar& f1, const nv_scalar& f2, const nv_scalar& f3, - const nv_scalar& f4, const nv_scalar& f5, const nv_scalar& f6, const nv_scalar& f7, - const nv_scalar& f8, const nv_scalar& f9, const nv_scalar& f10, const nv_scalar& f11, - const nv_scalar& f12, const nv_scalar& f13, const nv_scalar& f14, const nv_scalar& f15 ) - : a00( f0 ), a10( f1 ), a20( f2 ), a30( f3 ), - a01( f4 ), a11( f5 ), a21( f6 ), a31( f7 ), - a02( f8 ), a12( f9 ), a22( f10), a32( f11), - a03( f12), a13( f13), a23( f14), a33( f15) { } - + mat4(const nv_scalar *array); + mat4(const mat4 &M); + + mat4(const nv_scalar &f0, const nv_scalar &f1, const nv_scalar &f2, const nv_scalar &f3, + const nv_scalar &f4, const nv_scalar &f5, const nv_scalar &f6, const nv_scalar &f7, + const nv_scalar &f8, const nv_scalar &f9, const nv_scalar &f10, const nv_scalar &f11, + const nv_scalar &f12, const nv_scalar &f13, const nv_scalar &f14, const nv_scalar &f15) + : a00(f0), a10(f1), a20(f2), a30(f3), + a01(f4), a11(f5), a21(f6), a31(f7), + a02(f8), a12(f9), a22(f10), a32(f11), + a03(f12), a13(f13), a23(f14), a33(f15) { } + const vec4 col(const int i) const { - return vec4(&mat_array[i * 4]); + return vec4(&mat_array[i*4]); } - - const vec4 operator[](const int& i) const + + const vec4 operator[](const int &i) const { - return vec4(mat_array[i], mat_array[i + 4], mat_array[i + 8], mat_array[i + 12]); + return vec4(mat_array[i], mat_array[i+4], mat_array[i+8], mat_array[i+12]); } - - const nv_scalar& operator()(const int& i, const int& j) const + + const nv_scalar &operator()(const int &i, const int &j) const { - return mat_array[ j * 4 + i ]; + return mat_array[j*4+i]; } - nv_scalar& operator()(const int& i, const int& j) + nv_scalar &operator()(const int &i, const int &j) { - return mat_array[ j * 4 + i ]; + return mat_array[j*4+i]; } - void set_col(int i, const vec4 & v) + void set_col(int i, const vec4 &v) { - mat_array[i * 4] = v.x; - mat_array[i * 4 + 1] = v.y; - mat_array[i * 4 + 2] = v.z; - mat_array[i * 4 + 3] = v.w; + mat_array[i*4] = v.x; + mat_array[i*4+1] = v.y; + mat_array[i*4+2] = v.z; + mat_array[i*4+3] = v.w; } - void set_row(int i, const vec4 & v) + void set_row(int i, const vec4 &v) { mat_array[i] = v.x; - mat_array[i + 4] = v.y; - mat_array[i + 8] = v.z; - mat_array[i + 12] = v.w; + mat_array[i+4] = v.y; + mat_array[i+8] = v.z; + mat_array[i+12] = v.w; } - mat3 & get_rot(mat3 & M) const; - quat & get_rot(quat & q) const; - void set_rot(const quat & q); - void set_rot(const mat3 & M); - void set_rot(const nv_scalar & theta, const vec3 & v); - void set_rot(const vec3 & u, const vec3 & v); + mat3 &get_rot(mat3 &M) const; + quat &get_rot(quat &q) const; + void set_rot(const quat &q); + void set_rot(const mat3 &M); + void set_rot(const nv_scalar &theta, const vec3 &v); + void set_rot(const vec3 &u, const vec3 &v); - void set_translation(const vec3 & t); - vec3 & get_translation(vec3 & t) const; + void set_translation(const vec3 &t); + vec3 &get_translation(vec3 &t) const; - mat4 operator*(const mat4&) const; + mat4 operator*(const mat4 &) const; - union { - struct { - nv_scalar a00, a10, a20, a30; // standard names for components - nv_scalar a01, a11, a21, a31; // standard names for components - nv_scalar a02, a12, a22, a32; // standard names for components - nv_scalar a03, a13, a23, a33; // standard names for components + union + { + struct + { + nv_scalar a00, a10, a20, a30; // standard names for components + nv_scalar a01, a11, a21, a31; // standard names for components + nv_scalar a02, a12, a22, a32; // standard names for components + nv_scalar a03, a13, a23, a33; // standard names for components }; - struct { - nv_scalar _11, _12, _13, _14; // standard names for components - nv_scalar _21, _22, _23, _24; // standard names for components - nv_scalar _31, _32, _33, _34; // standard names for components - nv_scalar _41, _42, _43, _44; // standard names for components + + struct + { + nv_scalar _11, _12, _13, _14; // standard names for components + nv_scalar _21, _22, _23, _24; // standard names for components + nv_scalar _31, _32, _33, _34; // standard names for components + nv_scalar _41, _42, _43, _44; // standard names for components }; - union { - struct { + + union + { + struct + { nv_scalar b00, b10, b20, p; // standard names for components nv_scalar b01, b11, b21, q; // standard names for components nv_scalar b02, b12, b22, r; // standard names for components - nv_scalar x, y, z, w; // standard names for components + nv_scalar x, y, z, w; // standard names for components }; }; - nv_scalar mat_array[16]; // array access + + nv_scalar mat_array[16]; // array access }; }; -const vec4 operator*(const mat4&, const vec4&); -const vec4 operator*(const vec4&, const mat4&); +const vec4 operator*(const mat4 &, const vec4 &); +const vec4 operator*(const vec4 &, const mat4 &); // quaternion -struct DECLSPEC_NV_MATH quat { +struct DECLSPEC_NV_MATH quat +{ public: - quat(nv_scalar x = 0, nv_scalar y = 0, nv_scalar z = 0, nv_scalar w = 1); - quat(const quat& quat); - quat(const vec3& axis, nv_scalar angle); - quat(const mat3& rot); - quat& operator=(const quat& quat); - quat operator-() - { - return quat(-x, -y, -z, -w); - } - quat Inverse(); - void Normalize(); - void FromMatrix(const mat3& mat); - void ToMatrix(mat3& mat) const; - quat& operator*=(const quat& quat); - static const quat Identity; - nv_scalar& operator[](int i) { return comp[i]; } - const nv_scalar operator[](int i) const { return comp[i]; } - union { - struct { - nv_scalar x, y, z, w; - }; - nv_scalar comp[4]; - }; + quat(nv_scalar x = 0, nv_scalar y = 0, nv_scalar z = 0, nv_scalar w = 1); + quat(const quat &quat); + quat(const vec3 &axis, nv_scalar angle); + quat(const mat3 &rot); + quat &operator=(const quat &quat); + + quat operator-() + { + return quat(-x, -y, -z, -w); + } + + quat Inverse(); + void Normalize(); + void FromMatrix(const mat3 &mat); + void ToMatrix(mat3 &mat) const; + quat &operator*=(const quat &quat); + static const quat Identity; + + nv_scalar &operator[](int i) + { + return comp[i]; + } + + const nv_scalar operator[](int i) const + { + return comp[i]; + } + + union + { + struct + { + nv_scalar x, y, z, w; + }; + + nv_scalar comp[4]; + }; }; -const quat operator*(const quat&, const quat&); -extern quat & conj(quat & p, const quat & q); -extern quat & add_quats(quat & p, const quat & q1, const quat & q2); -extern nv_scalar dot(const quat & p, const quat & q); -extern quat & dot(nv_scalar s, const quat & p, const quat & q); -extern quat & slerp_quats(quat & p, nv_scalar s, const quat & q1, const quat & q2); -extern quat & axis_to_quat(quat & q, const vec3 & a, const nv_scalar phi); -extern mat3 & quat_2_mat(mat3 &M, const quat &q ); -extern quat & mat_2_quat(quat &q,const mat3 &M); + +const quat operator*(const quat &, const quat &); +extern quat &conj(quat &p, const quat &q); +extern quat &add_quats(quat &p, const quat &q1, const quat &q2); +extern nv_scalar dot(const quat &p, const quat &q); +extern quat &dot(nv_scalar s, const quat &p, const quat &q); +extern quat &slerp_quats(quat &p, nv_scalar s, const quat &q1, const quat &q2); +extern quat &axis_to_quat(quat &q, const vec3 &a, const nv_scalar phi); +extern mat3 &quat_2_mat(mat3 &M, const quat &q); +extern quat &mat_2_quat(quat &q, const mat3 &M); // constant algebraic values -const nv_scalar array16_id[] = { nv_one, nv_zero, nv_zero, nv_zero, - nv_zero, nv_one, nv_zero, nv_zero, - nv_zero, nv_zero, nv_one, nv_zero, - nv_zero, nv_zero, nv_zero, nv_one}; - -const nv_scalar array16_null[] = { nv_zero, nv_zero, nv_zero, nv_zero, - nv_zero, nv_zero, nv_zero, nv_zero, - nv_zero, nv_zero, nv_zero, nv_zero, - nv_zero, nv_zero, nv_zero, nv_zero}; - -const nv_scalar array16_scale_bias[] = { nv_zero_5, nv_zero, nv_zero, nv_zero, - nv_zero, nv_zero_5, nv_zero, nv_zero, - nv_zero, nv_zero, nv_zero_5, nv_zero, - nv_zero_5, nv_zero_5, nv_zero_5, nv_one}; - -const nv_scalar array9_id[] = { nv_one, nv_zero, nv_zero, - nv_zero, nv_one, nv_zero, - nv_zero, nv_zero, nv_one}; - - -const vec2 vec2_null(nv_zero,nv_zero); -const vec4 vec4_one(nv_one,nv_one,nv_one,nv_one); -const vec3 vec3_one(nv_one,nv_one,nv_one); -const vec3 vec3_null(nv_zero,nv_zero,nv_zero); -const vec3 vec3_x(nv_one,nv_zero,nv_zero); -const vec3 vec3_y(nv_zero,nv_one,nv_zero); -const vec3 vec3_z(nv_zero,nv_zero,nv_one); -const vec3 vec3_neg_x(-nv_one,nv_zero,nv_zero); -const vec3 vec3_neg_y(nv_zero,-nv_one,nv_zero); -const vec3 vec3_neg_z(nv_zero,nv_zero,-nv_one); -const vec4 vec4_null(nv_zero,nv_zero,nv_zero,nv_zero); -const vec4 vec4_x(nv_one,nv_zero,nv_zero,nv_zero); -const vec4 vec4_neg_x(-nv_one,nv_zero,nv_zero,nv_zero); -const vec4 vec4_y(nv_zero,nv_one,nv_zero,nv_zero); -const vec4 vec4_neg_y(nv_zero,-nv_one,nv_zero,nv_zero); -const vec4 vec4_z(nv_zero,nv_zero,nv_one,nv_zero); -const vec4 vec4_neg_z(nv_zero,nv_zero,-nv_one,nv_zero); -const vec4 vec4_w(nv_zero,nv_zero,nv_zero,nv_one); -const vec4 vec4_neg_w(nv_zero,nv_zero,nv_zero,-nv_one); -const quat quat_id(nv_zero,nv_zero,nv_zero,nv_one); -const mat4 mat4_id(array16_id); -const mat3 mat3_id(array9_id); -const mat4 mat4_null(array16_null); -const mat4 mat4_scale_bias(array16_scale_bias); +const nv_scalar array16_id[] = {nv_one, nv_zero, nv_zero, nv_zero, + nv_zero, nv_one, nv_zero, nv_zero, + nv_zero, nv_zero, nv_one, nv_zero, + nv_zero, nv_zero, nv_zero, nv_one}; + +const nv_scalar array16_null[] = {nv_zero, nv_zero, nv_zero, nv_zero, + nv_zero, nv_zero, nv_zero, nv_zero, + nv_zero, nv_zero, nv_zero, nv_zero, + nv_zero, nv_zero, nv_zero, nv_zero}; + +const nv_scalar array16_scale_bias[] = {nv_zero_5, nv_zero, nv_zero, nv_zero, + nv_zero, nv_zero_5, nv_zero, nv_zero, + nv_zero, nv_zero, nv_zero_5, nv_zero, + nv_zero_5, nv_zero_5, nv_zero_5, nv_one}; + +const nv_scalar array9_id[] = {nv_one, nv_zero, nv_zero, + nv_zero, nv_one, nv_zero, + nv_zero, nv_zero, nv_one}; + + +const vec2 vec2_null(nv_zero,nv_zero); +const vec4 vec4_one(nv_one,nv_one,nv_one,nv_one); +const vec3 vec3_one(nv_one,nv_one,nv_one); +const vec3 vec3_null(nv_zero,nv_zero,nv_zero); +const vec3 vec3_x(nv_one,nv_zero,nv_zero); +const vec3 vec3_y(nv_zero,nv_one,nv_zero); +const vec3 vec3_z(nv_zero,nv_zero,nv_one); +const vec3 vec3_neg_x(-nv_one,nv_zero,nv_zero); +const vec3 vec3_neg_y(nv_zero, -nv_one,nv_zero); +const vec3 vec3_neg_z(nv_zero,nv_zero, -nv_one); +const vec4 vec4_null(nv_zero,nv_zero,nv_zero,nv_zero); +const vec4 vec4_x(nv_one,nv_zero,nv_zero,nv_zero); +const vec4 vec4_neg_x(-nv_one,nv_zero,nv_zero,nv_zero); +const vec4 vec4_y(nv_zero,nv_one,nv_zero,nv_zero); +const vec4 vec4_neg_y(nv_zero, -nv_one,nv_zero,nv_zero); +const vec4 vec4_z(nv_zero,nv_zero,nv_one,nv_zero); +const vec4 vec4_neg_z(nv_zero,nv_zero, -nv_one,nv_zero); +const vec4 vec4_w(nv_zero,nv_zero,nv_zero,nv_one); +const vec4 vec4_neg_w(nv_zero,nv_zero,nv_zero, -nv_one); +const quat quat_id(nv_zero,nv_zero,nv_zero,nv_one); +const mat4 mat4_id(array16_id); +const mat3 mat3_id(array9_id); +const mat4 mat4_null(array16_null); +const mat4 mat4_scale_bias(array16_scale_bias); // normalizes a vector and return a reference of itself -extern vec3 & normalize(vec3 & u); -extern vec4 & normalize(vec4 & u); +extern vec3 &normalize(vec3 &u); +extern vec4 &normalize(vec4 &u); // Computes the squared magnitude -inline nv_scalar nv_sq_norm(const vec3 & n) -{ return n.x * n.x + n.y * n.y + n.z * n.z; } +inline nv_scalar nv_sq_norm(const vec3 &n) +{ + return n.x*n.x+n.y*n.y+n.z*n.z; +} -inline nv_scalar nv_sq_norm(const vec4 & n) -{ return n.x * n.x + n.y * n.y + n.z * n.z + n.w * n.w; } +inline nv_scalar nv_sq_norm(const vec4 &n) +{ + return n.x*n.x+n.y*n.y+n.z*n.z+n.w*n.w; +} // Computes the magnitude -inline nv_scalar nv_norm(const vec3 & n) -{ return _sqrt(nv_sq_norm(n)); } +inline nv_scalar nv_norm(const vec3 &n) +{ + return _sqrt(nv_sq_norm(n)); +} -inline nv_scalar nv_norm(const vec4 & n) -{ return _sqrt(nv_sq_norm(n)); } +inline nv_scalar nv_norm(const vec4 &n) +{ + return _sqrt(nv_sq_norm(n)); +} // computes the cross product ( v cross w) and stores the result in u // i.e. u = v cross w -extern vec3 & cross(vec3 & u, const vec3 & v, const vec3 & w); +extern vec3 &cross(vec3 &u, const vec3 &v, const vec3 &w); // computes the dot product ( v dot w) and stores the result in u // i.e. u = v dot w -extern nv_scalar & dot(nv_scalar & u, const vec3 & v, const vec3 & w); -extern nv_scalar dot(const vec3 & v, const vec3 & w); -extern nv_scalar & dot(nv_scalar & u, const vec4 & v, const vec4 & w); -extern nv_scalar dot(const vec4 & v, const vec4 & w); -extern nv_scalar & dot(nv_scalar & u, const vec3 & v, const vec4 & w); -extern nv_scalar dot(const vec3 & v, const vec4 & w); -extern nv_scalar & dot(nv_scalar & u, const vec4 & v, const vec3 & w); -extern nv_scalar dot(const vec4 & v, const vec3 & w); +extern nv_scalar &dot(nv_scalar &u, const vec3 &v, const vec3 &w); +extern nv_scalar dot(const vec3 &v, const vec3 &w); +extern nv_scalar &dot(nv_scalar &u, const vec4 &v, const vec4 &w); +extern nv_scalar dot(const vec4 &v, const vec4 &w); +extern nv_scalar &dot(nv_scalar &u, const vec3 &v, const vec4 &w); +extern nv_scalar dot(const vec3 &v, const vec4 &w); +extern nv_scalar &dot(nv_scalar &u, const vec4 &v, const vec3 &w); +extern nv_scalar dot(const vec4 &v, const vec3 &w); // compute the reflected vector R of L w.r.t N - vectors need to be // normalized @@ -593,134 +702,151 @@ extern nv_scalar dot(const vec4 & v, const vec3 & w); // \ | / // \|/ // + -extern vec3 & reflect(vec3 & r, const vec3 & n, const vec3 & l); +extern vec3 &reflect(vec3 &r, const vec3 &n, const vec3 &l); // Computes u = v * lambda + u -extern vec3 & madd(vec3 & u, const vec3 & v, const nv_scalar & lambda); +extern vec3 &madd(vec3 &u, const vec3 &v, const nv_scalar &lambda); // Computes u = v * lambda -extern vec3 & mult(vec3 & u, const vec3 & v, const nv_scalar & lambda); +extern vec3 &mult(vec3 &u, const vec3 &v, const nv_scalar &lambda); // Computes u = v * w -extern vec3 & mult(vec3 & u, const vec3 & v, const vec3 & w); +extern vec3 &mult(vec3 &u, const vec3 &v, const vec3 &w); // Computes u = v + w -extern vec3 & add(vec3 & u, const vec3 & v, const vec3 & w); +extern vec3 &add(vec3 &u, const vec3 &v, const vec3 &w); // Computes u = v - w -extern vec3 & sub(vec3 & u, const vec3 & v, const vec3 & w); +extern vec3 &sub(vec3 &u, const vec3 &v, const vec3 &w); // Computes u = u * s -extern vec3 & scale(vec3 & u, const nv_scalar s); -extern vec4 & scale(vec4 & u, const nv_scalar s); +extern vec3 &scale(vec3 &u, const nv_scalar s); +extern vec4 &scale(vec4 &u, const nv_scalar s); // Computes u = M * v -extern vec3 & mult(vec3 & u, const mat3 & M, const vec3 & v); -extern vec4 & mult(vec4 & u, const mat4 & M, const vec4 & v); +extern vec3 &mult(vec3 &u, const mat3 &M, const vec3 &v); +extern vec4 &mult(vec4 &u, const mat4 &M, const vec4 &v); // Computes u = v * M -extern vec3 & mult(vec3 & u, const vec3 & v, const mat3 & M); -extern vec4 & mult(vec4 & u, const vec4 & v, const mat4 & M); +extern vec3 &mult(vec3 &u, const vec3 &v, const mat3 &M); +extern vec4 &mult(vec4 &u, const vec4 &v, const mat4 &M); // Computes u = M(4x4) * v and divides by w -extern vec3 & mult_pos(vec3 & u, const mat4 & M, const vec3 & v); +extern vec3 &mult_pos(vec3 &u, const mat4 &M, const vec3 &v); // Computes u = M(4x4) * v -extern vec3 & mult_dir(vec3 & u, const mat4 & M, const vec3 & v); +extern vec3 &mult_dir(vec3 &u, const mat4 &M, const vec3 &v); // Computes u = M(4x4) * v and does not divide by w (assumed to be 1) -extern vec3 & mult(vec3& u, const mat4& M, const vec3& v); +extern vec3 &mult(vec3 &u, const mat4 &M, const vec3 &v); // Computes u = v * M(4x4) and divides by w -extern vec3 & mult_pos(vec3 & u, const vec3 & v, const mat4 & M); +extern vec3 &mult_pos(vec3 &u, const vec3 &v, const mat4 &M); // Computes u = v * M(4x4) -extern vec3 & mult_dir(vec3 & u, const vec3 & v, const mat4 & M); +extern vec3 &mult_dir(vec3 &u, const vec3 &v, const mat4 &M); // Computes u = v * M(4x4) and does not divide by w (assumed to be 1) -extern vec3 & mult(vec3& u, const vec3& v, const mat4& M); +extern vec3 &mult(vec3 &u, const vec3 &v, const mat4 &M); // Computes A += B -extern mat4 & add(mat4 & A, const mat4 & B); -extern mat3 & add(mat3 & A, const mat3 & B); +extern mat4 &add(mat4 &A, const mat4 &B); +extern mat3 &add(mat3 &A, const mat3 &B); // Computes C = A * B -extern mat4 & mult(mat4 & C, const mat4 & A, const mat4 & B); -extern mat3 & mult(mat3 & C, const mat3 & A, const mat3 & B); +extern mat4 &mult(mat4 &C, const mat4 &A, const mat4 &B); +extern mat3 &mult(mat3 &C, const mat3 &A, const mat3 &B); // Computes B = Transpose(A) // T // B = A -extern mat3 & transpose(mat3 & B, const mat3 & A); -extern mat4 & transpose(mat4 & B, const mat4 & A); -extern mat3 & transpose(mat3 & B); -extern mat4 & transpose(mat4 & B); +extern mat3 &transpose(mat3 &B, const mat3 &A); +extern mat4 &transpose(mat4 &B, const mat4 &A); +extern mat3 &transpose(mat3 &B); +extern mat4 &transpose(mat4 &B); // Computes B = inverse(A) // -1 // B = A -extern mat4 & invert(mat4 & B, const mat4 & A); -extern mat3 & invert(mat3 & B, const mat3 & A); +extern mat4 &invert(mat4 &B, const mat4 &A); +extern mat3 &invert(mat3 &B, const mat3 &A); // Computes B = inverse(A) // T T // (R t) (R -R t) // assuming that A = (0 1) so that B = (0 1) // B = A -extern mat4 & invert_rot_trans(mat4 & B, const mat4 & A); +extern mat4 &invert_rot_trans(mat4 &B, const mat4 &A); -extern mat4 & look_at(mat4 & M, const vec3 & eye, const vec3 & center, const vec3 & up); -extern mat4 & frustum(mat4 & M, const nv_scalar l, const nv_scalar r, const nv_scalar b, - const nv_scalar t, const nv_scalar n, const nv_scalar f); +extern mat4 &look_at(mat4 &M, const vec3 &eye, const vec3 ¢er, const vec3 &up); +extern mat4 &frustum(mat4 &M, const nv_scalar l, const nv_scalar r, const nv_scalar b, + const nv_scalar t, const nv_scalar n, const nv_scalar f); -extern mat4 & perspective(mat4 & M, const nv_scalar fovy, const nv_scalar aspect, const nv_scalar n, const nv_scalar f); +extern mat4 &perspective(mat4 &M, const nv_scalar fovy, const nv_scalar aspect, const nv_scalar n, const nv_scalar f); // quaternion -extern quat & normalize(quat & p); -extern quat & conj(quat & p); -extern quat & conj(quat & p, const quat & q); -extern quat & add_quats(quat & p, const quat & q1, const quat & q2); -extern quat & axis_to_quat(quat & q, const vec3 & a, const nv_scalar phi); -extern mat3 & quat_2_mat(mat3 &M, const quat &q ); -extern quat & mat_2_quat(quat &q,const mat3 &M); -extern quat & mat_2_quat(quat &q,const mat4 &M); +extern quat &normalize(quat &p); +extern quat &conj(quat &p); +extern quat &conj(quat &p, const quat &q); +extern quat &add_quats(quat &p, const quat &q1, const quat &q2); +extern quat &axis_to_quat(quat &q, const vec3 &a, const nv_scalar phi); +extern mat3 &quat_2_mat(mat3 &M, const quat &q); +extern quat &mat_2_quat(quat &q, const mat3 &M); +extern quat &mat_2_quat(quat &q, const mat4 &M); // surface properties -extern mat3 & tangent_basis(mat3 & basis,const vec3 & v0,const vec3 & v1,const vec3 & v2,const vec2 & t0,const vec2 & t1,const vec2 & t2, const vec3 & n); +extern mat3 &tangent_basis(mat3 &basis, const vec3 &v0, const vec3 &v1, const vec3 &v2, const vec2 &t0, const vec2 &t1, const vec2 &t2, const vec3 &n); // linear interpolation inline nv_scalar lerp(nv_scalar t, nv_scalar a, nv_scalar b) -{ return a * (nv_one - t) + t * b; } +{ + return a*(nv_one-t)+t*b; +} -inline vec3 & lerp(vec3 & w, const nv_scalar & t, const vec3 & u, const vec3 & v) -{ w.x = lerp(t, u.x, v.x); w.y = lerp(t, u.y, v.y); w.z = lerp(t, u.z, v.z); return w; } +inline vec3 &lerp(vec3 &w, const nv_scalar &t, const vec3 &u, const vec3 &v) +{ + w.x = lerp(t, u.x, v.x); + w.y = lerp(t, u.y, v.y); + w.z = lerp(t, u.z, v.z); + return w; +} // utilities -inline nv_scalar nv_min(const nv_scalar & lambda, const nv_scalar & n) -{ return (lambda < n ) ? lambda : n; } +inline nv_scalar nv_min(const nv_scalar &lambda, const nv_scalar &n) +{ + return (lambda n ) ? lambda : n; } +inline nv_scalar nv_max(const nv_scalar &lambda, const nv_scalar &n) +{ + return (lambda>n) ? lambda : n; +} inline nv_scalar nv_clamp(nv_scalar u, const nv_scalar min, const nv_scalar max) -{ u = (u < min) ? min : u; u = (u > max) ? max : u; return u; } +{ + u = (umax) ? max : u; + return u; +} extern nv_scalar nv_random(); -extern quat & trackball(quat & q, vec2 & pt1, vec2 & pt2, nv_scalar trackballsize); +extern quat &trackball(quat &q, vec2 &pt1, vec2 &pt2, nv_scalar trackballsize); -extern vec3 & cube_map_normal(int i, int x, int y, int cubesize, vec3 & v); +extern vec3 &cube_map_normal(int i, int x, int y, int cubesize, vec3 &v); // geometry // computes the area of a triangle -extern nv_scalar nv_area(const vec3 & v1, const vec3 & v2, const vec3 &v3); +extern nv_scalar nv_area(const vec3 &v1, const vec3 &v2, const vec3 &v3); // computes the perimeter of a triangle -extern nv_scalar nv_perimeter(const vec3 & v1, const vec3 & v2, const vec3 &v3); +extern nv_scalar nv_perimeter(const vec3 &v1, const vec3 &v2, const vec3 &v3); // find the inscribed circle -extern nv_scalar nv_find_in_circle( vec3 & center, const vec3 & v1, const vec3 & v2, const vec3 &v3); +extern nv_scalar nv_find_in_circle(vec3 ¢er, const vec3 &v1, const vec3 &v2, const vec3 &v3); // find the circumscribed circle -extern nv_scalar nv_find_circ_circle( vec3 & center, const vec3 & v1, const vec3 & v2, const vec3 &v3); +extern nv_scalar nv_find_circ_circle(vec3 ¢er, const vec3 &v1, const vec3 &v2, const vec3 &v3); // fast cosine functions extern nv_scalar fast_cos(const nv_scalar x); extern nv_scalar ffast_cos(const nv_scalar x); // determinant -nv_scalar det(const mat3 & A); +nv_scalar det(const mat3 &A); -extern void nv_is_valid(const vec3& v); +extern void nv_is_valid(const vec3 &v); extern void nv_is_valid(nv_scalar lambda); #endif //nv_algebraH + + diff --git a/src/editors/ECore/Engine/nv_math.h b/src/editors/ECore/Engine/nv_math.h index 014a87ca986..7f6f297f8c8 100644 --- a/src/editors/ECore/Engine/nv_math.h +++ b/src/editors/ECore/Engine/nv_math.h @@ -19,9 +19,10 @@ from the use or inability to use this file or items derived from it. #include "nv_mathdecl.h" #endif // _nv_mathdecl_h_ + #include -typedef f32 nv_scalar; +typedef f32 nv_scalar; #define nv_zero nv_scalar(0) #define nv_zero_5 nv_scalar(0.5) @@ -42,7 +43,8 @@ typedef f32 nv_scalar; #define nv_big_eps nv_scalar(10e-6) #define nv_small_eps nv_scalar(10e-2) -template struct vec3t; +template +struct vec3t; struct vec2; struct vec4; @@ -50,4 +52,7 @@ struct vec4; #include "nv_algebra.h" #endif // _nv_algebra_h_ + #endif //_nv_math_h_ + + diff --git a/src/editors/ECore/Engine/nv_mathdecl.h b/src/editors/ECore/Engine/nv_mathdecl.h index 0587cb4b945..ef1ee3fc965 100644 --- a/src/editors/ECore/Engine/nv_mathdecl.h +++ b/src/editors/ECore/Engine/nv_mathdecl.h @@ -17,15 +17,17 @@ from the use or inability to use this file or items derived from it. #define _nv_mathdecl_h_ #ifdef NV_MATH_DLL - - #ifdef NV_MATH_EXPORTS - #define DECLSPEC_NV_MATH __declspec(dllexport) - #else - #define DECLSPEC_NV_MATH __declspec(dllimport) - #endif +#include "xrCore/Platform.h" +#ifdef NV_MATH_EXPORTS + #define DECLSPEC_NV_MATH XR_EXPORT +#else + #define DECLSPEC_NV_MATH XR_IMPORT +#endif #else - #define DECLSPEC_NV_MATH +#define DECLSPEC_NV_MATH #endif -#endif // _nv_mathdecl_h_ +#endif // _nv_mathdecl_h_ + + diff --git a/src/editors/ECore/stdafx.h b/src/editors/ECore/stdafx.h index f04d86f87fb..da8af0b2f15 100644 --- a/src/editors/ECore/stdafx.h +++ b/src/editors/ECore/stdafx.h @@ -17,9 +17,9 @@ #define DIRECTINPUT_VERSION 0x0800 -#define R_R1 1 -#define R_R2 2 -#define RENDER R_R1 +#define R_R1 1 +#define R_R2 2 +#define RENDER R_R1 // Std C++ headers #include @@ -34,11 +34,11 @@ #ifdef _eof #undef _eof #endif -__inline int _eof (int _a) { return ::eof(_a); } +__inline int _eof(int _a) { return ::eof(_a); } #ifdef _access #undef _access #endif -__inline int _access(const char *_a, int _b) { return ::access(_a,_b); } +__inline int _access(const char *_a, int _b) { return ::access(_a, _b); } #ifdef _lseek #undef _lseek #endif @@ -47,34 +47,37 @@ __inline long _lseek(int handle, long offset, int fromwhere){ return ::lseek(han #undef _dup #endif #define fmodf fmod -__inline int _dup (int handle) { return ::dup(handle);} -__inline float modff(float a, float *b){ - double x,y; - y = modf(double(a),&x); - *b = x; - return float(y); +__inline int _dup (int handle) { return ::dup(handle); } +__inline float modff(float a, float *b) +{ + double x, y; + + y = modf(double(a), &x); + *b = x; + return float(y); } -__inline float expf (float val) { return ::exp(val);} +__inline float expf (float val) { return ::exp(val);} +#include "xrCore/Platform.h" -#ifdef _ECOREB - #define ECORE_API __declspec(dllexport) - #define ENGINE_API __declspec(dllexport) +#ifdef _ECOREB +#define ECORE_API XR_EXPORT +#define ENGINE_API XR_EXPORT #else - #define ECORE_API __declspec(dllimport) - #define ENGINE_API __declspec(dllimport) +#define ECORE_API XR_IMPORT +#define ENGINE_API XR_IMPORT #endif -#define DLL_API __declspec(dllimport) -#define PropertyGP(a,b) __declspec( property( get=a, put=b ) ) -#define THROW FATAL("THROW"); -#define THROW2(a) FATAL(a); +#define DLL_API XR_IMPORT +#define PropertyGP(a,b) __declspec( property( get=a, put=b ) ) +#define THROW FATAL("THROW"); +#define THROW2(a) FATAL(a); #define NO_XRC_STATS -#define clMsg Msg +#define clMsg Msg // core -#include +#include #ifdef _EDITOR class PropValue; @@ -85,59 +88,59 @@ __inline float expf (float val) { return ::exp(val);} DEFINE_VECTOR(ListItem*,ListItemsVec,ListItemsIt); #endif -#include "..\..\xrCDB\xrCDB.h" -#include "..\..\xrSound\Sound.h" -#include "..\..\xrEngine\PSystem.h" +#include "xrCDB/xrCDB.h" +#include "xrSound/Sound.h" +#include "xrEngine/PSystem.h" // DirectX headers #include #include -#include "..\..\Layers\xrRender\xrD3dDefs.h" +#include "Layers/xrRender/xrD3dDefs.h" #include //#include // some user components -#include "..\..\xrEngine\fmesh.h" -#include "..\..\xrEngine\_d3d_extensions.h" +#include "xrCore/FMesh.hpp" +#include "Common/_d3d_extensions.h" #include "D3DX_Wrapper.h" -DEFINE_VECTOR (AnsiString,AStringVec,AStringIt); -DEFINE_VECTOR (AnsiString*,LPAStringVec,LPAStringIt); +DEFINE_VECTOR (AnsiString, AStringVec, AStringIt); +DEFINE_VECTOR (AnsiString*, LPAStringVec, LPAStringIt); -#include "..\..\..\xrServerEntities\xrEProps.h" -#include "..\..\xrCore\Log.h" -#include "editor\engine.h" -#include "..\..\xrEngine\defines.h" +#include "xrServerEntities\xrEProps.h" +#include "xrCore/Log.h" +#include "Editor/engine.h" +#include "xrEngine/defines.h" -#include "../../xrphysics/xrphysics.h" +#include "xrPhysics/xrPhysics.h" struct str_pred : public std::binary_function { IC bool operator()(LPCSTR x, LPCSTR y) const - { return strcmp(x,y)<0; } + { return strcmp(x, y)<0; } }; struct astr_pred : public std::binary_function { IC bool operator()(const AnsiString& x, const AnsiString& y) const - { return xEditorName(),".ini").c_str());} @@ -163,8 +166,7 @@ struct astr_pred : public std::binary_function