修改了tile mesh的数据但是低级别的瓦片显示没有变化高级别的瓦片可以看到变化请问一下怎么回事]
Translation:
The data of the tile mesh has been modified, but the low-level tiles show no change, and the high-level tiles can see the changes, please tell me what’s going on]
You’ll have to give us more details and explain what you mean. When you say the “data of the tile mesh has been modified”, do you mean the original data was modified, or the tileset itself was modified?
3D Tiles works as follows: each tile is a section of the data at some level of detail, and tiles are loaded based on the level of detail desired for the position of the camera. If you modify one tile, then you’re just modifying that tile. You aren’t going to cause any of the other tiles to change, because they have their own models that you did not modify.
It’s better to make the modification to the original data source, if possible, and then create a new 3D Tileset from the modified data.
在 3Dtileset.app 里的 prepareInMainThread 函数里面 获取到了tile的mesh数据并修改了数据 进行还原回去 从而想达到在地球上挖坑的效果
Then you will have to share how you’re modifying the data.
virtual void* prepareInMainThread(
Cesium3DTilesSelection::Tile& tile,
void* pLoadThreadResult) override {
const Cesium3DTilesSelection::TileContent& content = tile.getContent();
if (content.isRenderContent()) {
TUniquePtrUCesiumGltfComponent::HalfConstructed pHalf(
reinterpret_castUCesiumGltfComponent::HalfConstructed*(
pLoadThreadResult));
const Cesium3DTilesSelection::TileRenderContent& renderContent =
*content.getRenderContent();
CesiumGltf::Model getedModel = renderContent.getModel();
int levelh = tile.getTileID()._Storage()._Tail._Head.level;
std::vector<double> minv = getedModel.accessors[0].min;
std::vector<double> maxv = getedModel.accessors[0].max;
const Ellipsoid& ellipsoid = Ellipsoid::WGS84;
bool haschange = false;
//bool tag = tile.getTileID()._Storage()._Tail._Head.x == 413309;
/*tile.getNonZeroGeometricError();
tile.setGeometricError();*/
if (levelh > 15) {
UE_LOG(
LogTemp,
Warning,
TEXT("dangqian level: %d %d %d"),
tile.getTileID()._Storage()._Tail._Head.level,
tile.getTileID()._Storage()._Tail._Head.x,
tile.getTileID()._Storage()._Tail._Head.y);
std::byte* tagbuffer = &getedModel.buffers[bufferindex].cesium.data[0];
double* mindz = &getedModel.accessors[0].min[0];
double* maxdz = &getedModel.accessors[0].max[0];
glm::mat4x4 mat = glm::mat4x4(
(float)getedModel.nodes[0].matrix[0],
(float)getedModel.nodes[0].matrix[1],
(float)getedModel.nodes[0].matrix[2],
(float)getedModel.nodes[0].matrix[3],
(float)getedModel.nodes[0].matrix[4],
(float)getedModel.nodes[0].matrix[5],
(float)getedModel.nodes[0].matrix[6],
(float)getedModel.nodes[0].matrix[7],
(float)getedModel.nodes[0].matrix[8],
(float)getedModel.nodes[0].matrix[9],
(float)getedModel.nodes[0].matrix[10],
(float)getedModel.nodes[0].matrix[11],
(float)getedModel.nodes[0].matrix[12],
(float)getedModel.nodes[0].matrix[13],
(float)getedModel.nodes[0].matrix[14],
(float)getedModel.nodes[0].matrix[15]);
glm::mat4x4 matinv = glm::inverse(mat);
int pointlength =
getedModel.bufferViews[bufferindex].byteLength / byteStride;
int kk = 0;
for (int i = 0; i < pointlength; i++) {
float x = *reinterpret_cast<float*>(tagbuffer + i * byteStride);
float y = *reinterpret_cast<float*>(tagbuffer + i * byteStride + 4);
float z = *reinterpret_cast<float*>(tagbuffer + i * byteStride + 8);
glm::vec4 p(x, y, z, 1);
p = mat * p;
std::optional<Cartographic> sss =
ellipsoid.cartesianToCartographic(glm::dvec3(p.x, -p.z, p.y));
Cartographic value = sss.value();
value.longitude = (value.longitude / PI * 180);
value.latitude = value.latitude / PI * 180;
value.height = value.height;
bool h = false;
//判断是否在范围内
if (ispengzhuang(value.longitude, value.latitude)) {
haschange = true;
value.height -= 10;
getedModel.asset.copyright = "hh";
} else {
continue;
}
value.longitude = (value.longitude) / 180 * PI;
value.latitude = value.latitude / 180 * PI;
glm::dvec3 position = ellipsoid.cartographicToCartesian(value);
position = glm::vec3(
matinv * glm::vec4(position.x, position.z, -position.y, 1));
float endX = (float)position.x;
float endY = (float)position.y;
float endZ = (float)position.z;
minv[0] = fmin(minv[0], endX);
minv[1] = fmin(minv[1], endY);
minv[2] = fmin(minv[2], endZ);
maxv[0] = fmax(maxv[0], endX);
maxv[1] = fmax(maxv[1], endY);
maxv[2] = fmax(maxv[2], endZ);
std::memcpy(tagbuffer + i * byteStride, &endX, 4);
std::memcpy(tagbuffer + i * byteStride + 4, &endY, 4);
std::memcpy(tagbuffer + i * byteStride + 8, &endZ, 4);
if (haschange) {
getedModel.accessors[0].min = minv;
getedModel.accessors[0].max = maxv;
std::memcpy(mindz, &minv, 24);
std::memcpy(maxdz, &maxv, 24);
const Cesium3DTilesSelection::BoundingVolume& tileBoundingVolume =
tile.getBoundingVolume();
float* tilebdv = (float*)&tileBoundingVolume;
double minheight = 900;
double maxheight = 1500;
std::memcpy(tilebdv + 8, &minheight, 8);
std::memcpy(tilebdv + 10, &maxheight, 8);
tile.setBoundingVolume(tileBoundingVolume);
tile.getContent().getRenderContent()->setModel(getedModel);
}
}
auto usedModel = renderContent.getModel();
if (haschange) {
UE_LOG(
LogTemp,
Warning,
TEXT("xiu gai de level: %d %d %d"),
tile.getTileID()._Storage()._Tail._Head.level,
tile.getTileID()._Storage()._Tail._Head.x,
tile.getTileID()._Storage()._Tail._Head.y);
if (usedModel.asset.copyright.has_value()) {
std::string mess = usedModel.asset.copyright.value();
UE_LOG(LogTemp, Warning, TEXT("has Modify is: %s"), mess.c_str());
} else {
UE_LOG(LogTemp, Warning, TEXT("Not Modify"));
}
}
}
return UCesiumGltfComponent::CreateOnGameThread(
tile.getContent().getRenderContent()->getModel(),
this->_pActor,
std::move(pHalf),
_pActor->GetCesiumTilesetToUnrealRelativeWorldTransform(),
this->_pActor->GetMaterial(),
this->_pActor->GetTranslucentMaterial(),
this->_pActor->GetWaterMaterial(),
this->_pActor->GetCustomDepthParameters(),
tile.getContentBoundingVolume().value_or(tile.getBoundingVolume()));
}
// UE_LOG(LogCesium, VeryVerbose, TEXT("No content for tile"));
return nullptr;
}
这就是修改数据的完整代码
You’re choosing which tiles to modify based on this if statement, right?
if (levelh > 15)
which relies on this variable:
int levelh = tile.getTileID()._Storage()._Tail._Head.level;
From a glance, it seems that this only modifies tiles at a certain threshold of detail. So you are modifying the tiles in a specified range, but not any of the tiles that are larger and less-detailed than those target tiles. That’s what I’m trying to communicate – modifying the geometry of smaller, higher-detail tiles will not have any effect on the larger, lower-detail tiles.
没有这个 if (levelh > 15) 判断还是一样的结果
低体系的level还是没有受到影响
而且这个地球 有19层level 现在的情况是只有到了19层level 它才会显示 模型的修改
So let me make sure I understand how you’re modifying the tile. You’re testing if the vertex position in the model is in a certain longitude and latitude range, and then modifying the position so it is vertically offset, as if it was dug into the ground. And finally, you’re overwriting the resources using std::memcpy
.
That’s seem fine from a glance. In the Unreal editor, can you enable the debug wireframe mode, then screenshot the different levels of detail? It would help to clarify what’s happening.
请教一下老师 怎么才能实现挖坑功能呢