2017-02-03 9 views
2

목표는 무한한 체스 판 패턴을 만드는 것입니다.SceneKit : 이미지에서 SCNFloor에 대한 체스 판 패턴을 만드는 방법은 무엇입니까?

SCNFloor와 첨부 된 이미지를 사용하여 우리는 가까이에 있지만 체스 판처럼 보이지 않는 것을 만들어냅니다. 검은 색 정사각형은 병합해서는 안됩니다.

우리는 Scale, WrapS, WrapT, Min filter, Map filterMip filter에 대해 다른 값을 시도했다. 스크린 샷은 현재 값을 보여줍니다.

기본 이미지가 올바르지 않습니까, 아니면 SCNFloor를 변경해야합니까?

이미지가 반복 :

enter image description here

결과 : SCNFloor는 그것을 무한 될 수있는 기능을 제공, 솔기를 가지고 있으며, 아마 허용 같은

enter image description here

+0

나는 SCNFloor에서 질감을 시험해 보았고 스크린 샷과는 달리 사각형이 규칙적으로 보였다. 다른 설정을 변경 했습니까? –

+0

@JamesP nope. SCNFloor가 일반 체스 판처럼 생겼다고 말하는 겁니까? 방금 기본 설정을 사용 했습니까? – Crashalot

+0

예, 모든 것이 기본값이며, 1 등급입니다. 예상했던 것처럼 보입니다. 모서리에있는 작은 미리보기 영역도 잘못 보입니다. 텍스처가 오프셋되어 있습니다. 내 중심에 있습니다. –

답변

0

같습니다 시스템에 의한 LOD 최적화의 양. 자신 만의 바닥을 만들어야 할 수도 있습니다.

+0

나는 여기서 두 번째로 혼란스럽고 그렇게하기 위해 이미지가 필요 없다고 말한다. 필요한 것은 많은 비행기로 바닥을 만드는 것입니다. 각 비행기는 흰색 소재 또는 검은 소재 중 하나가됩니다. 모든 흰색 노드와 모든 검정 노드에 대한 형상과 재료를 공유 할 수 있습니다. 모든 노드가 상위 노드에 연결됩니다. –

+0

@ KarlSigiscar 감사하지만 조금 혼란스러워합니다. 여러 평면을 사용하여 바닥을 시뮬레이션하는 방법은 무엇입니까? 흰색 비행기를 검은 색 평면과 겹치게 만들거나 (또는 ​​검은 색/흰색이 아닌 다른 색/이미지) 체스 판 패턴을 생성하려면 어떻게합니까? – Crashalot

0
#import "GameViewController.h" 

@interface GameViewController() 

@property (nonatomic) CGFloat chessBoardWidth; 
@property (nonatomic) CGFloat chessBoardDepth; 
@property (nonatomic) CGFloat tileWidth; 
@property (nonatomic) CGFloat tileDepth; 
@property (nonatomic, getter=isOdd) BOOL odd; 

@end 

@implementation GameViewController 

-(instancetype)init { 
    self = [super init]; 

    if(self) { 
     self.chessBoardWidth = 10.0f; 
     self.chessBoardDepth = 10.0f; 
     self.tileWidth = 1.0f; 
     self.tileDepth = 1.0f; 
    } 

    return self; 
} 

-(void)awakeFromNib 
{ 
    [super awakeFromNib]; 

    // create a new scene 
    SCNScene *scene = [SCNScene sceneNamed:@"art.scnassets/chessboard.scn"]; 

    // create and add a camera to the scene 
    SCNNode *cameraNode = [SCNNode node]; 
    cameraNode.camera = [SCNCamera camera]; 
    [scene.rootNode addChildNode:cameraNode]; 

    // place the camera 
    cameraNode.position = SCNVector3Make(0, 0, 150); 

    // create and add a light to the scene 
    SCNNode *lightNode = [SCNNode node]; 
    lightNode.light = [SCNLight light]; 
    lightNode.light.type = SCNLightTypeOmni; 
    lightNode.position = SCNVector3Make(0, 10, 10); 
    [scene.rootNode addChildNode:lightNode]; 

    // create and add an ambient light to the scene 
    SCNNode *ambientLightNode = [SCNNode node]; 
    ambientLightNode.light = [SCNLight light]; 
    ambientLightNode.light.type = SCNLightTypeAmbient; 
    ambientLightNode.light.color = [NSColor darkGrayColor]; 
    [scene.rootNode addChildNode:ambientLightNode]; 

    // Material 

    SCNMaterial *blackMaterial = [SCNMaterial material]; 
    blackMaterial.diffuse.contents = [NSColor blackColor]; 

    SCNMaterial *whiteMaterial = [SCNMaterial material]; 
    whiteMaterial.diffuse.contents = [NSColor whiteColor]; 

    // Geometry 

    SCNPlane *blackTile = [[SCNPlane alloc] init]; 
    blackTile.firstMaterial = blackMaterial; 

    SCNPlane *whiteTile = [[SCNPlane alloc] init]; 
    whiteTile.firstMaterial = whiteMaterial; 

    // Parent node 

    SCNNode *parentNode = [[SCNNode alloc] init]; 
    [scene.rootNode addChildNode:parentNode]; 

    self.odd = YES; 

    for (uint x=0; x < self.chessBoardWidth; x++) { 
     for (uint z=0; z < self.chessBoardDepth; z++) { 

      // Add tile 

      SCNNode *tileNode = [[SCNNode alloc] init]; 

      if(self.isOdd) { 
       tileNode.geometry = blackTile; 
      } else { 
       tileNode.geometry = whiteTile; 
      } 

      [parentNode addChildNode:tileNode]; 

      // Position tile 
      tileNode.position = SCNVector3Make(self.tileWidth * x, 0, self.tileDepth * z); 

      // Alternate 

      if(self.isOdd) { 
       self.odd = NO; 
      } else { 
       self.odd = YES; 
      } 
     } 
    } 

    // set the scene to the view 
    self.gameView.scene = scene; 

    // allows the user to manipulate the camera 
    self.gameView.allowsCameraControl = YES; 

    // show statistics such as fps and timing information 
    self.gameView.showsStatistics = YES; 

    // configure the view 
    self.gameView.backgroundColor = [NSColor grayColor]; 
} 

@end 
+0

감사! 그러나 이것은 SCNFloor와 같은 무한한 보드를 만들 것입니까? 이것이 무한하다면'chessBoardWidth'와'chessBoardDepth'가 무엇을위한 것인지 명확하지 않습니까? 예를 들어이 값들을 고치지 않으면 카메라가'chessBoardDepth'를 지나서 체스 보드가 사라진다는 것을 의미합니까? – Crashalot

+0

그러나 그 값이나 타일의 크기를 늘리고 카메라의 뷰잉 프러스 텀을 항상 커버 할 수 있습니다. 무한 할 필요는 없습니다. –

+0

감사합니다. Karl. 이 접근 방식을 시도해 보았고 공연자임을 보증 할 수 있습니까? 그렇지 않다면 일부 테스트 할 수는 있지만이 접근법은 SCNFloor만큼 성능이 좋지 않다는 점을 염려합니다. – Crashalot