1#include "TextureMesh.h"
5 TextureMesh::TextureMesh()
10 TextureMesh::~TextureMesh()
15 template<typename Vec3f>
16 __global__ void mergeVec3f(
23 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
24 if (pId >= target.size()) return;
27 target[pId] = v0[pId];
29 target[pId] = v1[pId - sizeV0];
32 template<typename Vec2f>
33 __global__ void mergeVec2f(
40 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
41 if (pId >= target.size()) return;
44 target[pId] = v0[pId];
46 target[pId] = v1[pId - sizeV0];
49 __global__ void mergeUint(
56 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
57 if (pId >= target.size()) return;
60 target[pId] = v0[pId];
62 target[pId] = v1[pId - sizeV0];
65 __global__ void mergeShapeId(
73 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
74 if (pId >= target.size()) return;
77 target[pId] = v0[pId];
79 target[pId] = v1[pId - sizeV0] + shapeSize;
82 template<typename Triangle>
83 __global__ void updateVertexIndex(
85 DArray<Triangle> target,
89 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
90 if (pId >= target.size()) return;
92 target[pId] = Triangle(v[pId][0] + offset, v[pId][1] + offset, v[pId][2] + offset);
95 void TextureMesh::merge(const std::shared_ptr<TextureMesh>& texMesh01, const std::shared_ptr<TextureMesh>& texMesh02)
97 auto vertices01 = texMesh01->vertices();
98 auto vertices02 = texMesh02->vertices();
100 this->vertices().resize(vertices01.size() + vertices02.size());
102 cuExecute(this->vertices().size(),
110 auto normals01 = texMesh01->normals();
111 auto normals02 = texMesh02->normals();
112 this->normals().resize(normals01.size() + normals02.size());
114 cuExecute(this->normals().size(),
122 auto texCoords01 = texMesh01->texCoords();
123 auto texCoords02 = texMesh02->texCoords();
124 this->texCoords().resize(texCoords01.size() + texCoords02.size());
126 cuExecute(this->texCoords().size(),
134 auto shapeIds01 = texMesh01->shapeIds();
135 auto shapeIds02 = texMesh02->shapeIds();
136 this->shapeIds().resize(shapeIds01.size() + shapeIds02.size());
138 cuExecute(this->texCoords().size(),
144 texMesh01->shapes().size()
148 auto material01 = texMesh01->materials();
149 auto material02 = texMesh02->materials();
151 auto outMaterials = this->materials();
152 outMaterials.clear();
154 for (auto it : material01)
155 outMaterials.push_back(it);
157 for (auto it : material02)
158 outMaterials.push_back(it);
161 auto shapes01 = texMesh01->shapes();
162 auto shapes02 = texMesh02->shapes();
164 std::vector<std::shared_ptr<Shape>> outShapes;
166 for (auto it : shapes01)
168 auto element = std::make_shared<Shape>();
169 element->vertexIndex.assign(it->vertexIndex);
170 element->normalIndex.assign(it->normalIndex);
171 element->texCoordIndex.assign(it->texCoordIndex);
172 element->boundingBox = it->boundingBox;
173 element->boundingTransform = it->boundingTransform;
174 element->material = it->material;
176 outShapes.push_back(element);
180 for (auto it : shapes02)
182 auto element = std::make_shared<Shape>();
183 element->vertexIndex.assign(it->vertexIndex);
184 element->normalIndex.assign(it->normalIndex);
185 element->texCoordIndex.assign(it->texCoordIndex);
186 element->boundingBox = it->boundingBox;
187 element->boundingTransform = it->boundingTransform;
188 element->material = it->material;
190 outShapes.push_back(element);
192 cuExecute(it->vertexIndex.size(),
195 element->vertexIndex,
199 cuExecute(it->normalIndex.size(),
202 element->normalIndex,
206 cuExecute(it->texCoordIndex.size(),
209 element->texCoordIndex,
215 this->shapes() = outShapes;
216 this->materials() = outMaterials;
219 void TextureMesh::clear()