gpt4 book ai didi

ios - 组合两个或多个 SCNGeometries

转载 作者:可可西里 更新时间:2023-11-01 05:28:22 24 4
gpt4 key购买 nike

我制作了这个方法来抓取 UIImage 并将其转换为 3D 模型。然而,这意味着我添加了很多节点。我在想也许可以通过将所有几何图形添加到单个节点中来优化它。有办法实现吗?

这是代码

static inline SCNNode* S2NNode(const UIImage* sprite) {
SCNNode *spriteNode = [SCNNode node];
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(sprite.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
for (int x = 0; x < sprite.size.width; x++)
{
for (int y = 0; y < sprite.size.height; y++)
{
int pixelInfo = ((sprite.size.width * y) + x) * 4;
UInt8 alpha = data[pixelInfo + 3];
if (alpha > 3)
{
UInt8 red = data[pixelInfo];
UInt8 green = data[pixelInfo + 1];
UInt8 blue = data[pixelInfo + 2];
UIColor *color = [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];
SCNNode *pixel = [SCNNode node];
pixel.geometry = [SCNBox boxWithWidth:1.001 height:1.001 length:1.001 chamferRadius:0];
pixel.geometry.firstMaterial.diffuse.contents = color;
pixel.position = SCNVector3Make(x - sprite.size.width / 2.0,
y - sprite.size.height / 2.0,
0);
[spriteNode addChildNode:pixel];
}
}
}
CFRelease(pixelData);
//The image is upside down and I have no idea why.
spriteNode.rotation = SCNVector4Make(1, 0, 0, M_PI);
return spriteNode;
}

最佳答案

这个答案解决了最初提出的问题——如何合并几何图形。然而,合并几何体似乎并不能解决您的实际问题——如何获得具有一定厚度和良好性能的像素化“ Sprite ”。参见 my other answer为此。


SCNNode 方法 flattenedClone会将节点子节点的所有几何图形组合成具有单个几何图形的单个节点。这将减少场景处理开销并在单个 OpenGL 绘制调用中渲染……但它也会使立方体不能独立移动并且都共享相同的 Material ,因此它们不会有不同的颜色。此外,根据您希望立方体的排列方式,您可能会将比需要更多的顶点数据推送到 GPU,这仍然会损害您的性能。

根据您想要的效果类型,可能有更好的解决方案。

关于ios - 组合两个或多个 SCNGeometries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com