revert: 删除 modeler filer 存 3D 缓存的全部代码(实测该 API 写读不能配对)
结论(用户实测):acdbModelerSaveEntityToDwgFiler 写出的数据, 用 acdbModelerRestoreEntityFromDwgFiler 读回来 CAD 直接报错、实体丢失。 这两个函数不是一对可逆读写,不能用来把绘制缓存塞进 DWG 再取回来。 本仓库自己的现象与之一致: - 单条静态数据时"读回 len=1 / setASMBody 成功 / 包围盒正确"只是巧合; - 一旦多条混排或与别的字段交错,读端就错位,表现为 "打开图形文件发现一个错误" + 实体变 ZOMBIEENTITY(造型.dwg 的 2D5 就是); - 之前加的读端防护(magic/count/尾标记/失败回退)只能保证不把文件写得更坏, 改变不了"写进去的字节读不回同一个几何"这个根本问题。 删除范围(对应之前几个 PR): - AecDbEntityCommon: Write3DBufferBlock / Read3DBufferBlock(#125) - AecDbEwFitting: 上述两个函数的调用点(#125) - AecDbX3dPartEntity: WriteX3dGeomBlock / ReadX3dGeomBlock 及调用点(#118) - AecDbX3dPart.h/.cpp: GetDwgCacheSolid / SetDwgCacheSolid(#118) - AecDbMultiPartEntity: 3D 缓存块,版本号回到 3(#131/#132) - cmakelists.txt: AEC_HAS_MODELER_FILER 能力宏 共 -612 行。 保留:AEC_PERF_COUNTER 计时(EwPipeBase::Draw3d / X3dPart::Rebuild / MultiPartEntity::Draw3d)。它们只回答"开图期画了多少、花了多久",与存盘格式无关, 以后评估"隐藏块里放真实 3DSOLID"或 SAT 通道时还用得上。 结论与后续方向写进 3d-cache-dwg-verdict.md §10。 验证:R230 Debug 编译通过(CoreCommand_BAL_REMOTE,零 error)。
This commit is contained in:
1 parent
bec6cb996d
commit
4523690cc5
8 files changed
+7
-608
No files matched your search
@@ -3,7 +3,6 @@
|
||||
#include "simpleproperty.h"
|
||||
#include "coretools.h"
|
||||
#include "SectionPerfCounter.h"
|
||||
#include "dbacis.h"
|
||||
|
||||
IMP_XDATA_KEY(AecDbMultiPartEntity,_ptOrg_);
|
||||
IMP_XDATA_KEY(AecDbMultiPartEntity,_vtX_);
|
||||
@@ -13,20 +12,7 @@ IMP_XDATA_KEY(AecDbMultiPartEntity,_vtZ_);
|
||||
extern void DLLIMPEXP OrthoProjected3DSolid(AcDb3dSolid* pSolidClone,const AcGePlane& plan,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
|
||||
extern void DLLIMPEXP OrthoProjected3DSubMesh(AcDbSubDMesh* pSubMesh,const AcGePlane& plan,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
|
||||
|
||||
// 版本号保持 4(与已有图纸一致)。缓存块用 magic 自描述:
|
||||
// - 老图纸(v3)/ 别人写的 v4(无 magic):读不到 magic 就当没有缓存,照旧重建;
|
||||
// - 本版本写的 v4(有 magic):直接用块里的 ASM 几何。
|
||||
// 代价:v3 的老版本插件打开 v4 图仍会走 eMakeMeProxy(这是升版本号本身带来的)。
|
||||
Adesk::UInt32 AecDbMultiPartEntity::kCurrentVersionNumber = 4;
|
||||
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
namespace
|
||||
{
|
||||
const Adesk::UInt32 kMp3dMagic = 0x50443341; // 'A3DP'
|
||||
const Adesk::UInt32 kMp3dEnd = 0x50443341 ^ 0xFFFFFFFF;
|
||||
const Adesk::UInt16 kMp3dBlkVer = 1;
|
||||
}
|
||||
#endif
|
||||
Adesk::UInt32 AecDbMultiPartEntity::kCurrentVersionNumber = 3;
|
||||
|
||||
ACRX_DXF_DEFINE_MEMBERS (AecDbMultiPartEntity, AecDbBDPipeBase,
|
||||
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||||
@@ -56,11 +42,10 @@ Acad::ErrorStatus AecDbMultiPartEntity::Draw3d(AcGiDraw &dc) const
|
||||
{
|
||||
assertReadEnabled();
|
||||
|
||||
//AEC_PERF_COUNTER=1 的 Debug 下计时:这类实体开图期画 3D 一共花多少(缓存收益的天花板)
|
||||
//AEC_PERF_COUNTER=1 的 Debug 下计时:这类实体开图期画 3D 一共花多少
|
||||
SectionPerf::Scope perfScope("MultiPartEntity::Draw3d");
|
||||
const bool bHadCache = Has3DBuffer();
|
||||
SectionPerf::Scope cacheScope(bHadCache ? "MultiPartEntity::Draw3d.cached"
|
||||
: "MultiPartEntity::Draw3d.build");
|
||||
SectionPerf::Scope cacheScope(Has3DBuffer() ? "MultiPartEntity::Draw3d.cached"
|
||||
: "MultiPartEntity::Draw3d.build");
|
||||
|
||||
AecDbBDPipeBase::Draw3d(dc);
|
||||
|
||||
@@ -352,55 +337,7 @@ Acad::ErrorStatus AecDbMultiPartEntity::dwgInFields (AcDbDwgFiler* pFiler)
|
||||
xMap.dwgInFields(pFiler);
|
||||
}
|
||||
|
||||
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
// ---- 3D 几何缓存块(modeler filer)----
|
||||
// 位置:本实体流的**末尾**(这个类在 version 之后不写任何自己的字段,
|
||||
// 所以老版本读到自己需要的字段就停,尾部多出来的字节会被忽略)。
|
||||
// 为什么不用升版本号:升了会让老版本 `version > kCurrentVersionNumber`
|
||||
// 直接 eMakeMeProxy —— 整批实体变代理对象(实测已出现过 ZOMBIEENTITY)。
|
||||
// 所以这里用 magic 自描述:读不到 magic 就当没有缓存,照旧重建。
|
||||
{
|
||||
Adesk::UInt32 nMagic = 0;
|
||||
if (pFiler->readUInt32(&nMagic) == Acad::eOk && nMagic == kMp3dMagic)
|
||||
{
|
||||
Adesk::UInt16 nBlkVer = 0;
|
||||
Adesk::Int32 nCount = 0;
|
||||
if (pFiler->readUInt16(&nBlkVer) == Acad::eOk && nBlkVer == kMp3dBlkVer &&
|
||||
pFiler->readInt32(&nCount) == Acad::eOk && nCount > 0 && nCount <= 64)
|
||||
{
|
||||
int nModelerVer = -1;
|
||||
int nOk = 0;
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
ENTITY* pAsm = NULL;
|
||||
if (acdbModelerRestoreEntityFromDwgFiler(pFiler, pAsm, &nModelerVer,
|
||||
kReadStrangerEntityDefault) != Acad::eOk || pAsm == NULL)
|
||||
break;
|
||||
|
||||
AcDb3dSolid* pSolid = new AcDb3dSolid();
|
||||
if (pSolid->setASMBody(pAsm) != Acad::eOk)
|
||||
{
|
||||
delete pSolid;
|
||||
break;
|
||||
}
|
||||
Add3DBuffer(pSolid);
|
||||
++nOk;
|
||||
}
|
||||
|
||||
Adesk::UInt32 nEnd = 0;
|
||||
const bool bEndOk = (pFiler->readUInt32(&nEnd) == Acad::eOk && nEnd == kMp3dEnd);
|
||||
if (nOk != (int)nCount || !bEndOk)
|
||||
{
|
||||
// 半成品块:整条丢弃,回退重建
|
||||
Clean3DBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Acad::eOk; // 探测缓存块时 readUInt32 在老图上会把状态置成 eEndOfFile,
|
||||
// 这里显式返回 eOk,否则整个实体会被判成读取失败
|
||||
return pFiler->filerStatus();
|
||||
}
|
||||
|
||||
Acad::ErrorStatus AecDbMultiPartEntity::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||||
@@ -416,51 +353,6 @@ Acad::ErrorStatus AecDbMultiPartEntity::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||||
if ( (es =pFiler->writeUInt32 (AecDbMultiPartEntity::kCurrentVersionNumber)) != Acad::eOk )
|
||||
return (es) ;
|
||||
|
||||
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
// ---- 3D 几何缓存块:只存 brep(AcDb3dSolid),且**count 按实际写入数**记 ----
|
||||
// 不能写 Get3DBuffer().length():缓存里可能有中心线/网格等非 brep,
|
||||
// 那些会被跳过,count 与实际 payload 数不一致 → 读端多吃数据、实体流损坏。
|
||||
{
|
||||
// 先一次性锁住、收集 body,写入期间不放锁 —— 这样 count 一定等于实际写出的条数
|
||||
AcArray<AcDb3dSolid*> arSolids;
|
||||
AcArray<ENTITY*> arAsm;
|
||||
const AcDbVoidPtrArray& arBuf = Get3DBuffer();
|
||||
for (int i = 0; i < arBuf.length(); ++i)
|
||||
{
|
||||
AcDb3dSolid* pSolid = AcDb3dSolid::cast((AcDbEntity*)arBuf[i]);
|
||||
if (pSolid == NULL)
|
||||
continue;
|
||||
ENTITY* pAsm = (ENTITY*)pSolid->getLockedASMBody();
|
||||
if (pAsm == NULL)
|
||||
continue;
|
||||
arSolids.append(pSolid);
|
||||
arAsm.append(pAsm);
|
||||
}
|
||||
|
||||
if (!arSolids.isEmpty())
|
||||
{
|
||||
AcDbDatabase* pDb = GetMe()->database();
|
||||
if (pDb == NULL)
|
||||
pDb = acdbHostApplicationServices()->workingDatabase();
|
||||
|
||||
pFiler->writeUInt32(kMp3dMagic);
|
||||
pFiler->writeUInt16(kMp3dBlkVer);
|
||||
pFiler->writeInt32((Adesk::Int32)arSolids.length());
|
||||
|
||||
for (int i = 0; i < arSolids.length(); ++i)
|
||||
{
|
||||
const Acad::ErrorStatus esSave = acdbModelerSaveEntityToDwgFiler(pFiler, arAsm[i], pDb, -1);
|
||||
arSolids[i]->unlockASMBody();
|
||||
if (esSave != Acad::eOk)
|
||||
break;
|
||||
}
|
||||
|
||||
pFiler->writeUInt32(kMp3dEnd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return pFiler->filerStatus();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user