目前我在SceneKit中使用多个模型时遇到问题。我有一个1MB的3d目标文件,它是.dae格式。当我尝试使用大量这些(让我们说1000个型号)时,应用程序的内存会上升并且应用程序崩溃。我甚至使用场景工具包内置函数RecordViewFooter().microphoneButton.addTarget(self, action: "microphoneButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
func microphoneButtonPressed(button:UIButton){
print("microphone button pressed")
volumeAdjuster = VolumeAdjusterView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
self.view.addSubview(volumeAdjuster!)
}
和clone()
来制作模型的副本。我该怎么办?
答案 0 :(得分:3)
这有很多顶点需要推动。你真的需要一次装满它们吗?你能简化模型吗?
创建SCNLevelOfDetail
个实例会有所帮助。这在WWDC 2014 SceneKit幻灯片示例代码中的AAPLSlideLOD.m中有说明。
NSMutableArray *levelsOfDetail = [NSMutableArray array];
for (NSUInteger i = 1; i < 5; i++) {
SCNNode *teapotNode = [self.groundNode childNodeWithName:[NSString stringWithFormat:@"Teapot%lu", (unsigned long)i] recursively:YES];
SCNGeometry *teapot = teapotNode.geometry;
// Unshare the material because we will highlight the different levels of detail with different colors in the next step
teapot.firstMaterial = [teapot.firstMaterial copy];
// Build the SCNLevelOfDetail instance
SCNLevelOfDetail *levelOfDetail = [SCNLevelOfDetail levelOfDetailWithGeometry:teapot worldSpaceDistance:distances[i - 1]];
[levelsOfDetail addObject:levelOfDetail];
}
teapot.geometry.levelsOfDetail = levelsOfDetail;
答案 1 :(得分:3)
这不是技术性答案,而是对如何管理多边形复杂性和表现形式的更多描述。
LOD =详细程度,虽然它是Scene Kit和其他3D应用程序和框架中的技术术语,但值得花点时间考虑这三个词作为设备敏感度的预兆观众/用户感知。
问问自己,在距离相机视点的任何给定距离处,您的模型需要具备何种程度的细节。
答案将根据距离,模型的复杂程度以及您使用的照明和材料而有所不同。
自从计算机上的3D艺术首先被构思和创造以来,一切都是&#34; hack&#34;在演示中欺骗观众在硬件的极限。
我们仍然受到硬件的限制(很大程度上)。
所以值得花时间投资来发现所有这些细节/复杂性和感知。
其中一些是:
还有很多其他人。
也许最好的起点是:
http://www.katsbits.com/tutorials/blender/baking-normal-maps-from-models-advanced.php
因为这将让您了解在3D技术设计的技术设计的一个方面考虑到感知的优化程度和考虑因素。
答案 2 :(得分:0)
你可以这样做
int numberOfSpheres = 20;
for(int i=0;i<numberOfSpheres;i++) {
NSURL *itemUrl = [[NSBundle mainBundle] URLForResource:@"yourResourceScene" withExtension:@".dae"];
SCNSceneSource *source = [SCNSceneSource sceneSourceWithURL:itemUrl options:nil];
SCNGeometry *nodeGeometry = (SCNGeometry *)[source entryWithIdentifier:@"objectInScene" withClass:[SCNGeometry class]];
SCNNode *myNode = [SCNNode nodeWithGeometry:nodeGeometry];
[MainScene.rootNode addChildNode:myNode];
// set position for each node here
// set scale of each node here
// set material of each node here
}