editor view buffer

main
cosmonaut 2021-09-24 16:42:24 -07:00
parent eee31fa5e9
commit 95c89d3ce1
2 changed files with 197 additions and 1 deletions

View File

@ -1087,7 +1087,200 @@ double Silkworm_ClothFillTriangleBuffer(double clothId, double leftUV, double wi
}
}
return (double)triangleCount;
return (double)triangleCount * 3;
}
/* in bytes */
double Silkworm_GetEditorBufferRequiredSize()
{
return 72 * context->nodeCount + 72 * context->linkCount;
}
/* position, color */
double Silkworm_FillEditorBuffer()
{
uint32_t i, triangleCount;
uint8_t* bufferAddress = context->currentBufferAddress;
Silkworm_Vector2 position;
position.x = 0;
position.y = 0;
Silkworm_Color color;
color.r = 0;
color.g = 0;
color.b = 255;
color.a = 255;
triangleCount = 0;
/* draw links */
for (i = 0; i < context->linkCount; i += 1)
{
Silkworm_Link* link = context->links[i];
if (link != NULL)
{
/* top left triangle */
float left, right, top, bottom;
if (link->a->position.y < link->b->position.y)
{
top = link->a->position.y;
bottom = link->b->position.y;
}
else
{
top = link->b->position.y;
bottom = link->a->position.y;
}
if (link->a->position.x < link->b->position.x)
{
left = link->a->position.x;
right = link->b->position.x;
}
else
{
left = link->b->position.x;
right = link->a->position.x;
}
/* upper left triangle */
position.x = left;
position.y = top;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = right;
position.y = top;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = left;
position.y = bottom;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
triangleCount += 1;
/* bottom right triangle */
position.x = left;
position.y = bottom;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = right;
position.y = top;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = right;
position.y = bottom;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
triangleCount += 1;
}
}
color.r = 255;
color.b = 0;
/* draw nodes */
for (i = 0; i < context->nodeCount; i += 1)
{
Silkworm_Node* node = context->nodes[i];
if (node != NULL)
{
/* top left triangle */
position.x = node->position.x - node->radius;
position.y = node->position.y - node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = node->position.x + node->radius;
position.y = node->position.y - node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = node->position.x - node->radius;
position.y = node->position.y + node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
triangleCount += 1;
/* bottom right triangle */
position.x = node->position.x - node->radius;
position.y = node->position.y + node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = node->position.x + node->radius;
position.y = node->position.y - node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
position.x = node->position.x + node->radius;
position.y = node->position.y + node->radius;
memcpy(bufferAddress, &position, sizeof(Silkworm_Vector2));
bufferAddress += sizeof(Silkworm_Vector2);
memcpy(bufferAddress, &color, sizeof(Silkworm_Color));
bufferAddress += sizeof(Silkworm_Color);
triangleCount += 1;
}
}
return (double)triangleCount * 3;
}
void Silkworm_PushNodesInRadius(double x, double y, double radius, double xDirection, double yDirection)

View File

@ -75,6 +75,9 @@ SILKWORMAPI void Silkworm_DestroyCloth(double clothId);
SILKWORMAPI void Silkworm_SetTriangleBuffer(const char* bufferId);
SILKWORMAPI double Silkworm_ClothFillTriangleBuffer(double clothId, double leftUV, double widthUV, double topUV, double heightUV);
SILKWORMAPI double Silkworm_GetEditorBufferRequiredSize();
SILKWORMAPI double Silkworm_FillEditorBuffer();
SILKWORMAPI void Silkworm_DestroyNode(double nodeId);
SILKWORMAPI void Silkworm_PushNodesInRadius(double x, double y, double radius, double xDirection, double yDirection);