Jer*_*026 0 objective-c ios scenekit
我正在尝试加载一个目前只有3个墙,一个天花板和一个地板的场景.我正在加载我在搅拌机中创建的场景并加载它.然而,SCNNode具有SCNBox正好几何形状的a 恰好穿过.盒子上附有一个动态物理体,我手动将其设置walls/floor为静态节点.下面是我用来设置场景和添加框的代码,.dae如果需要我也可以发布.任何人都对可能发生的事情有任何想法?
//Load the scene from file
SCNScene *scene = [SCNScene sceneNamed:@"mainScene.dar"];
//Get each node in the scene, and give it a static physics bodt
for (SCNNode *node in [[scene rootNode] childNodes]) {
SCNPhysicsBody *staticBody = [SCNPhysicsBody staticBody];
staticBody.restitution = 1.0;
node.presentationNode.physicsBody = staticBody;
NSLog(@"node.name %@",node.name);
}
//Create box
SCNNode *block = [SCNNode node];
block.position = SCNVector3Make(0, 0, 3);
//Set up the geometry
block.geometry = [SCNBox boxWithWidth:.8 height:.8 length:.8 chamferRadius:0.05];
block.geometry.firstMaterial.diffuse.mipFilter = SCNFilterModeLinear;
block.castsShadow = YES;
//Make it blue
for (SCNMaterial *mat in block.geometry.materials) {
mat.emission.contents = [UIColor blueColor];
}
//Add physics body
SCNPhysicsBody *body = [SCNPhysicsBody staticBody];
body.mass = 5;
body.restitution = .7;
body.friction = 0.5;
block.physicsBody = body;
//Add the node to the scene
[[scene rootNode] addChildNode:block];
Run Code Online (Sandbox Code Playgroud)
为了回应ricksters的回答,我尝试为每个新节点创建自定义几何体,但我的盒子仍然没有问题.这是我用于自定义几何的代码.这将替换原始代码中的for-in.
//Get each node in the scene, and give it a static physics bodt
for (SCNNode *node in [[scene rootNode] childNodes]) {
SCNGeometry *geometry = [SCNBox boxWithWidth:node.scale.x height:node.scale.y length:node.scale.z chamferRadius:0.0];
SCNPhysicsShape *physicsShape = [SCNPhysicsShape shapeWithGeometry:geometry options:nil];
SCNPhysicsBody *staticBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeStatic shape:physicsShape];
staticBody.restitution = 1.0;
node.physicsBody = staticBody;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
所以我遇到了类似的问题.我发现问题源于文件在3d建模软件中的创建方式.我用Blender测试了这个; 我用一个盒子做了一架飞机,在盒子上加了一个物理机构,飞机和盒子都掉了下来.我意识到这与规模有关.在Blender中,我通过按CTRL A并选择缩放选项来应用对象转换,将比例重置为1.0 1.0 1.0.所以最终似乎发生的事情是SceneKit使用基本几何体来忽略几何体的变换.您在屏幕上看到的是应用了节点变换的基础几何体.在导出Collada文件之前将转换设置为identity,您应该进行设置.
| 归档时间: |
|
| 查看次数: |
1740 次 |
| 最近记录: |