2017-03-05 31 views
1

我正在嘗試爲醫療應用程序準備3D人體部位選擇。關於顯示SCNView的選定位置的問題

其中我需要顯示一個選定的幾何位置。

但是我面臨的實現這個過程的問題是,當我從前視圖觸及身體時,圓圈(表示選定的位置)與身體平行。

但是,當我從背面或側面應用相同的東西,它並沒有畫出平行。

這是屏幕截圖。 Front view of 3D view, Side view of 3D view

我已經申請了

-(void)HandleTap:(UIGestureRecognizer *)sender 
{ 
CGPoint p = [sender locationInView:self.sceneView]; 
NSMutableArray *hitResults = nil; 
hitResults = [[self.sceneView hitTest:p options:nil] mutableCopy]; 
if([hitResults count] > 0){ 
    __block SCNHitTestResult *result = [hitResults objectAtIndex:0]; 
    float circleArea = .5; 
    SCNPlane * plane = [SCNPlane planeWithWidth:circleArea height:circleArea]; 
    plane.cornerRadius = circleArea/2.0; 
    plane.firstMaterial.diffuse.contents = [UIColor redColor]; 
    SCNNode *shapeNode = [SCNNode nodeWithGeometry: plane]; 
    shapeNode.position = SCNVector3Make(result.localCoordinates.x, result.localCoordinates.y, result.localCoordinates.z+.1); 
    [result.node addChildNode:shapeNode]; 
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Give a title to selected Human body area." preferredStyle:UIAlertControllerStyleAlert]; 
    __block UITextField * bodyAreaField; 
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 
     bodyAreaField = textField; 
    }]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Set" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 
     NSMutableArray * array = [[[NSUserDefaults standardUserDefaults] valueForKey:@"SelectedParts"] mutableCopy]; 
     if(!array) 
     { 
      array = [NSMutableArray new]; 
     } 
     NSDictionary * dict = @{@"BodyArea":bodyAreaField.text, 
           @"BodyArea_X_position":[NSNumber numberWithFloat:result.localCoordinates.x], 
           @"BodyArea_Y_position":[NSNumber numberWithFloat:result.localCoordinates.y], 
           @"BodyArea_Z_position":[NSNumber numberWithFloat:result.localCoordinates.z]}; 
     [array addObject:dict]; 
     [[NSUserDefaults standardUserDefaults] setValue:array forKey:@"SelectedParts"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 
     NSLog(@"stored body parts %@",[[NSUserDefaults standardUserDefaults] valueForKey:@"SelectedParts"]); 
    }]]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 
    }]]; 
    [self presentViewController:alert animated:YES completion:^{ 
    }]; 
} 
} 

下面的代碼演示,我想創建 https://www.dropbox.com/s/i7y28enid51d4cw/Selection%20of%20body%20part.mov?dl=0

+0

當你說「它不畫平行」 - 你期望兩個標記是在同一架飛機上,還是你希望他們面對相機?你能澄清預期的行爲是什麼嗎? – sambro

+0

我只是想要圓(觸摸點高亮)平行於身體的一部分。 例如,當我觸摸焊料時,圓應該與焊料平行。 如果我觸摸背部,它應該平行於背部,當我說平行時不需要精確,它應該像上面圖像中顯示的胸部上的點。 這將是很好,如果這些圓移動或變形,當我做同樣的3D身體。 –

回答

0

添加SCNBillboardConstraint至包含你圈子中的飛機。這將使他們面向相機。你還必須讓他們成爲場景的根節點的孩子,而不是身體的孩子,以便他們可以獨立於身體移動。