32 const auto* vertices =
33 (_deformVertices !=
nullptr && _display == _meshDisplay) ? _deformVertices->verticesData :
nullptr;
35 if (_displayIndex < 0 || _display == nullptr || texture == nullptr || texture->
textureId == 0)
return;
38 const auto& region = texture->region;
39 const auto* page = texture->parent;
41 if (vertices !=
nullptr) {
42 const auto* data = vertices->data;
43 const auto* intArray = data->intArray;
44 const auto* floatArray = data->floatArray;
45 const unsigned vertexCount = intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshVertexCount)];
46 const unsigned triangleCount =
47 intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshTriangleCount)];
48 int vertexOffset = intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshFloatOffset)];
51 if (vertexOffset < 0) vertexOffset += 65536;
52 const unsigned uvOffset =
static_cast<unsigned>(vertexOffset) + vertexCount * 2;
55 uvs.resize(vertexCount * 2);
56 for (
unsigned i = 0; i < vertexCount * 2; i += 2) {
57 positions[i] = floatArray[vertexOffset + i];
58 positions[i + 1] = floatArray[vertexOffset + i + 1];
60 const float u = floatArray[uvOffset + i];
61 const float v = floatArray[uvOffset + i + 1];
64 float su = texture->rotated ? region.x + (1.0f - v) * region.width : region.x + u * region.width;
65 float sv = texture->rotated ? region.y + u * region.height : region.y + v * region.height;
66 normalize(su, sv, page);
71 indices.resize(triangleCount * 3);
72 for (
unsigned i = 0; i < triangleCount * 3; ++i) {
73 indices[i] =
static_cast<std::uint16_t
>(
74 intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshVertexIndices) + i]);
85 const float scale = texture->parent->scale * _armature->_armatureData->scale;
86 const float w = std::abs(region.width) * scale;
87 const float h = std::abs(region.height) * scale;
89 positions = {0.0f, 0.0f, 0.0f, h, w, h, w, 0.0f};
90 float u0 = region.x, v0 = region.y;
91 float u1 = region.x + region.width, v1 = region.y + region.height;
92 normalize(u0, v0, page);
93 normalize(u1, v1, page);
94 uvs = {u0, v0, u0, v1, u1, v1, u1, v0};
99 if (_deformVertices ==
nullptr)
return;
100 const auto* vertices = _deformVertices->verticesData;
101 if (vertices ==
nullptr)
return;
103 const float scale = _armature->_armatureData->scale;
104 const auto& deform = _deformVertices->vertices;
105 const auto& bones = _deformVertices->bones;
106 const auto* weight = vertices->weight;
107 const bool hasDeform = !deform.empty();
109 const auto* data = vertices->data;
110 const auto* intArray = data->intArray;
111 const auto* floatArray = data->floatArray;
112 const auto vertexCount =
113 static_cast<std::size_t
>(intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshVertexCount)]);
116 if (weight !=
nullptr) {
117 int weightFloatOffset = intArray[weight->offset +
static_cast<unsigned>(BinaryOffset::WeigthFloatOffset)];
118 if (weightFloatOffset < 0) weightFloatOffset += 65536;
122 std::size_t iB = weight->offset +
static_cast<unsigned>(BinaryOffset::WeigthBoneIndices) + bones.size();
123 std::size_t iV =
static_cast<std::size_t
>(weightFloatOffset);
126 for (std::size_t i = 0; i < vertexCount; ++i) {
127 const auto boneCount =
static_cast<std::size_t
>(intArray[iB++]);
128 float xG = 0.0f, yG = 0.0f;
129 for (std::size_t j = 0; j < boneCount; ++j) {
130 const auto boneIndex =
static_cast<unsigned>(intArray[iB++]);
131 const auto* bone = bones[boneIndex];
132 if (bone ==
nullptr)
continue;
134 const auto& matrix = bone->globalTransformMatrix;
135 const float w = floatArray[iV++];
136 float xL = floatArray[iV++] * scale;
137 float yL = floatArray[iV++] * scale;
142 xG += (matrix.a * xL + matrix.c * yL + matrix.tx) * w;
143 yG += (matrix.b * xL + matrix.d * yL + matrix.ty) * w;
151 if (!hasDeform)
return;
153 int vertexOffset = intArray[vertices->offset +
static_cast<unsigned>(BinaryOffset::MeshFloatOffset)];
154 if (vertexOffset < 0) vertexOffset += 65536;
155 for (std::size_t i = 0; i < vertexCount; ++i) {
156 positions[i * 2] = floatArray[vertexOffset + i * 2] * scale + deform[i * 2];
157 positions[i * 2 + 1] = floatArray[vertexOffset + i * 2 + 1] * scale + deform[i * 2 + 1];
164 const std::size_t vertexCount =
positions.size() / 2;
165 std::vector<float> world(
positions.size());
170 const auto& m = globalTransformMatrix;
171 for (std::size_t i = 0; i < vertexCount; ++i) {
174 const float x =
positions[i * 2] - _pivotX;
175 const float y =
positions[i * 2 + 1] - _pivotY;
176 world[i * 2] = m.a * x + m.c * y + m.tx;
177 world[i * 2 + 1] = m.b * x + m.d * y + m.ty;
188 for (std::size_t i = 0; i < vertexCount; ++i) {
189 world[i * 2 + 1] = -world[i * 2 + 1];
195 const float rgba[4] = {
196 _colorTransform.redMultiplier * tint[0],
197 _colorTransform.greenMultiplier * tint[1],
198 _colorTransform.blueMultiplier * tint[2],
199 _colorTransform.alphaMultiplier * tint[3],
201 sink.emit(world.data(),
uvs.data(),
static_cast<int>(vertexCount),
indices.data(),
202 static_cast<int>(
indices.size()),
textureId,
static_cast<int>(_blendMode), rgba);
One atlas page: the texture the host bound to it, and its pixel size.