objective-c – 更改SCNNodeGeometryMaterial的颜色

objective-c – 更改SCNNodeGeometryMaterial的颜色,第1张

概述我是SceneKit的新手,正在开始测试应用程序.我有一个移动的小立方体.我想添加轴(X,Y,Z).我是这样创造的. SCNVector3 xPositions[] = {SCNVector3Make(-50, 0, 0), SCNVector3Make(50, 0, 0)}; int indicies[] = {0, 1}; NSData *indexData = [NSDat 我是SceneKit的新手,正在开始测试应用程序.我有一个移动的小立方体.我想添加轴(X,Y,Z).我是这样创造的.

SCNVector3 xpositions[] = {SCNVector3Make(-50,0),SCNVector3Make(50,0)};    int indicIEs[] = {0,1};    NSData *indexData = [NSData dataWithBytes:indicIEs length:sizeof(indicIEs)];// X axis    SCNGeometrySource *xSource = [SCNGeometrySource geometrySourceWithVertices:xpositions count:2];    SCNGeometryElement *xElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeline primitiveCount:2 bytesPerIndex:sizeof(int)];    SCNGeometry *xAxis = [SCNGeometry geometryWithSources:@[xSource] elements:@[xElement]];    SCNNode *xNode = [SCNNode nodeWithGeometry:xAxis];    [self.gameVIEw.scene.rootNode addChildNode:xNode];    // Y axis    SCNVector3 ypositions[] = {SCNVector3Make(0,-50,SCNVector3Make(0,50,0)};    SCNGeometrySource *ySource = [SCNGeometrySource geometrySourceWithVertices:ypositions count:2];    SCNGeometryElement *yElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeline primitiveCount:2 bytesPerIndex:sizeof(int)];    SCNGeometry *yAxis = [SCNGeometry geometryWithSources:@[ySource] elements:@[yElement]];    SCNNode *yNode = [SCNNode nodeWithGeometry:yAxis];    [self.gameVIEw.scene.rootNode addChildNode:yNode];    // Z axis    SCNVector3 zpositions[] = {SCNVector3Make(0,-50),50)};    SCNGeometrySource *zSource = [SCNGeometrySource geometrySourceWithVertices:zpositions count:2];    SCNGeometryElement *zElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeline primitiveCount:2 bytesPerIndex:sizeof(int)];    SCNGeometry *zAxis = [SCNGeometry geometryWithSources:@[zSource] elements:@[zElement]];    SCNNode *zNode = [SCNNode nodeWithGeometry:zAxis];    [self.gameVIEw.scene.rootNode addChildNode:zNode];

我的问题是,我想改变它们的颜色,以便我可以分辨哪个是哪个.有没有办法可以做到这一点,还是我必须以另一种方式创建我的线?我正在制作一个Mac应用程序,而不是iOS应用程序,只是一个fyi.此外,我知道重复代码,我只是累了,我会解决这个问题.

解决方法 使用-firstMaterial或(如果它是一个复杂的对象)-materials数组更改几何体的材质.

SCNMaterial *redMaterial = [SCNMaterial new];redMaterial.diffuse.contents = [NScolor redcolor];xAxis.firstMaterial = redMaterial;

或者更简洁:

yAxis.firstMaterial.diffuse.contents = [NScolor magentacolor];zAxis.firstMaterial.diffuse.contents = [NScolor yellowcolor];
总结

以上是内存溢出为你收集整理的objective-c – 更改SCNNode / Geometry / Material的颜色全部内容,希望文章能够帮你解决objective-c – 更改SCNNode / Geometry / Material的颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1002863.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存