2014-06-22 8 views
7

पर दृश्यता पृष्ठभूमि की सामग्री कैसे सेट करें I 6 दृश्यों के सरणी का उपयोग करके एक दृश्य की पृष्ठभूमि सामग्री को स्काईबॉक्स प्रभाव में सेट करने का प्रयास कर रहा हूं।घन मानचित्र

मैं सही क्रम में छवियों की सरणी बनाया है, मैं जानता हूँ कि मैं फिर भी मैं बाहर काम करने के लिए संघर्ष कर रहा हूँ तो

+ (instancetype) materialPropertyWithContents:(id)contents 

उपयोग करने की आवश्यकता कैसे और कहाँ बिल्कुल मैं उस वर्ग विधि का उपयोग वापस जाने के लिए घन मानचित्र युक्त संपत्ति।

उत्तर

17

एससीएनएससीएन की "पृष्ठभूमि" संपत्ति एससीएनएमटेरियलप्रोपर्टी कक्षा का है। तो आप अपने स्काईबॉक्स को सेट करने के लिए 6 छवियों की सरणी में सीधे इसकी सामग्री सेट कर सकते हैं (SCNScene.h देखें)।

aScene.background.contents = @[@"Right.png", @"Left.png", @"Top.png", @"Bottom.png", @"Back.png", @"Front.png"]; 

सुनिश्चित करें कि आपकी 6 छवियां वर्ग हैं और समान आयाम हैं।

+0

तरह लग रहा है यह skybox चेतन करने के लिए संभव हो है बारी बारी से करने के लिए कदम पर है? –

+0

यह भी ध्यान देने योग्य है कि छवियों का आकार 2. – gargantuan

2

उसके बारे में यहां ScnView उपवर्ग के लिए मेरे awakeFromNib

हाँ अपनी भ्रामक के रूप में सामग्री को असाइन मूल्य आईडी है और इसलिए कुछ नमूने theres।

उसके बारे में यहां ScnView उपवर्ग

उपयोग किसी भी 6 एक ही आकार के छवियों के लिए मेरी awakeFromNib। टीजीए की आवश्यकता नहीं है।

उदाहरण के लिए Google Skybox Google Skybox।

यह नमूना एक आकाशबॉक्स बनाता है और एक ही छवि को एक घन में लागू करता है जो इसे आकाश को दर्पण करने लगता है।

कैमरा नियंत्रण तो बस अपने माउस क्या एक मिरर घन

// 
// SkyBoxSceneView.h 
// SceneKit_Skybox 
// 
// Created by Brian Clear on 12/06/2014. 
// Copyright (c) 2014 Brian Clear. All rights reserved. 
// 
#import <SceneKit/SceneKit.h> 


@interface SkyBoxSceneView : SCNView 

@end 



// 
// SkyBoxSceneView.m 
// SceneKit_Skybox 
// 
// Created by Brian Clear on 12/06/2014. 
// Copyright (c) 2014 Brian Clear. All rights reserved. 
// 

#import "SkyBoxSceneView.h" 


@implementation SkyBoxSceneView 


-(void)awakeFromNib 
{ 
    // create a new scene 
    SCNScene *scene = [SCNScene scene]; 






    //----------------------------------------------------------------------------------- 
    //SET THE SKYBOX 
    //----------------------------------------------------------------------------------- 
    //it took me a while to get it working 
    //"APPLE IF YOU WANT SCENE KIT TO SUCCEED YOU NEED A FULL BLOWN GUIDE!!" 
    //----------------------------------------------------------------------------------- 
    //FIRST ISSUE - Error:scene.background is readonly 

    // I misread the help as "to set skybox set the scene.background" 
    /* 
    scene.background = ;   //INCORRECT 
    scene.background.contents = ; //OK 
    */ 
    //I should have read it as "to set skybox set the scene.background content e.g. scene.background.contents" 


    //----------------------------------------------------------------------------------- 
    //ONLY EXAMPLE OF setting material.reflective DOESNT WORK for scene.background.content 
    /* 
    I couldnt get sky box to work for ages because the only example of using reflective property I found was in 
    in the 2014 sample code 
    AAPLSlideMaterialLayer.m 
    https://developer.apple.com/library/prerelease/mac/samplecode/SceneKitWWDC2014/Listings/Scene_Kit_Session_WWDC_2014_Sources_Slides_AAPLSlideMaterialLayer_m.html#//apple_ref/doc/uid/TP40014551-Scene_Kit_Session_WWDC_2014_Sources_Slides_AAPLSlideMaterialLayer_m-DontLinkElementID_62 

    _material.reflective.contents = @[@"right.tga", @"left.tga", @"top.tga", @"bottom.tga", @"back.tga", @"front.tga"]; 

    so I tried it on scene.background.contents = 

    but didnt work 
    */ 
    //WRONG 
    //scene.background.contents = @[@"right.png", @"left.png", @"top.png", @"bottom.png", @"back.png", @"front.png"]; 

    //----------------------------------------------------------------------------------- 
    //ATTEMPT 3 - I changed all tga to png but still nothing 

    //----------------------------------------------------------------------------------- 
    //ATTEMPT 4 - Note this is very wrong. I was way off here 
    //when I saw this 
    // _material.reflective.contents = @[@"right.tga", @"left.tga", @"top.tga", @"bottom.tga", @"back.tga", @"front.tga"]; 
    //I then saw this 
    //scene.background.contents = ... 
    //I made the mistake of presuming that both "content" properties were the same 
    //SceneKit take a lot of id properties so WITHOUT A GUIDE you have to guess what goes into thes id properties 

    //I though scene.background was a SCNMaterialProperty cos it had scene.background.content 
    //same as material.reflective.content - reflective is a SCNMaterialProperty 

    //----------------------------------------------------------------------------------- 
    //tried it with SCNMaterialProperty.content 
    //but would never work as scene.background isnt a SCNMaterialProperty.content 
    // SCNMaterialProperty *scnMaterialProperty = [SCNMaterialProperty materialPropertyWithContents: @[@"right.tga", @"left.tga", @"top.tga", @"bottom.tga", @"back.tga", @"front.tga"]]; 
    //----------------------------------------------------------------------------------- 
    //tried with png but same issue 
    // SCNMaterialProperty *scnMaterialProperty = [SCNMaterialProperty materialPropertyWithContents: @[@"right.png", @"left.png", @"top.png", @"bottom.png", @"back.png", @"front.png"]]; 
    //----------------------------------------------------------------------------------- 
    //I had tried passing NSImage instead of NSString for material which worked 
    //boxNode.geometry.firstMaterial.reflective.contents = @[[NSImage imageNamed:@"right.tga"],.... 
    //so tried that for scne.background.content 
    //but was doomed as not a SCNMaterialProperty 
    // SCNMaterialProperty *scnMaterialProperty = [SCNMaterialProperty materialPropertyWithContents: @[[NSImage imageNamed:@"right.tga"], 
    //  [NSImage imageNamed:@"left.tga"], 
    //  [NSImage imageNamed:@"top.tga"], 
    //  [NSImage imageNamed:@"bottom.tga"], 
    //  [NSImage imageNamed:@"back.tga"], 
    //  [NSImage imageNamed:@"front.tga"]]]; 

    //----------------------------------------------------------------------------------- 
    //Test 4 - try with one image 

    //WORKS - set whole background to one image 
    //scene.background.contents = [NSImage imageNamed:@"left.tga"];//OK 

    //this proved that the image does load 
    //----------------------------------------------------------------------------------- 

    //use same one image in a SCNMaterialProperty 
    //DOESNT WORK - so issue is the SCNMaterialProperty 
    // SCNMaterialProperty *scnMaterialProperty = [SCNMaterialProperty materialPropertyWithContents:[NSImage imageNamed:@"right.tga"]]; 
    // scnMaterialProperty.intensity = 0.7; 
    // scene.background.contents = scnMaterialProperty;//OK 
    //----------------------------------------------------------------------------------- 
    //----------------------------------------------------------------------------------- 
    //SKYBOX WORKS!!!! 
    //----------------------------------------------------------------------------------- 
    //----------------------------------------------------------------------------------- 

    //version3 - pass array in directly (NOT through SCNMaterialProperty!!!!) 
    scene.background.contents = @[[NSImage imageNamed:@"right.tga"], 
            [NSImage imageNamed:@"left.tga"], 
            [NSImage imageNamed:@"top.tga"], 
            [NSImage imageNamed:@"bottom.tga"], 
            [NSImage imageNamed:@"back.tga"], 
            [NSImage imageNamed:@"front.tga"]]; 

    //----------------------------------------------------------------------------------- 
    //DOESNT WORK 
    //scene.background.contents = @"frozen.mov";// 

    //----------------------------------------------------------------------------------- 
    //CAMERA and CUBE 
    //----------------------------------------------------------------------------------- 
    // 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, 2); 

    // create and add a 3d box to the scene 
    SCNNode *boxNode = [SCNNode node]; 
    boxNode.geometry = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0.02]; 
    [scene.rootNode addChildNode:boxNode]; 
    //----------------------------------------------------------------------------------- 

    // create and configure a material 
// SCNMaterial *material = [SCNMaterial material]; 
// material.diffuse.contents = [NSColor brownColor];//= [NSImage imageNamed:@"texture"]; 
// material.specular.contents = [NSColor brownColor]; 
// material.specular.intensity = 0.2; 
// material.locksAmbientWithDiffuse = YES; 
//  

// //material.reflective.contents = @[@"right.tga", @"left.tga", @"top.tga", @"bottom.tga", @"back.tga", @"front.tga"]; 
// material.reflective.contents = @[@"right.png", @"left.png", @"top.png", @"bottom.png", @"back.png", @"front.png"]; 
//  
// material.diffuse.contents = [NSColor blackColor]; 
//  
//  
// // set the material to the 3d object geometry 
// boxNode.geometry.firstMaterial = material; 
//  
// earth-reflective.jpg 
// boxNode.geometry.firstMaterial.reflective.intensity = 0.7; 
//  

    //boxNode.geometry.firstMaterial.reflective.contents = [NSImage imageNamed:@"earth-reflective"]; 
// boxNode.geometry.firstMaterial.reflective.contents = @[@"right.tga", @"left.tga", @"top.tga", @"bottom.tga", @"back.tga", @"front.tga"]; 



    //----------------------------------------------------------------------------------- 
    //CUBE MATERIAL 
    //----------------------------------------------------------------------------------- 

    //make the cube reflect the sky 
    //the sky isnt really being reflected comment out line above "scene.background.contents = ...." 
    //and cube will still reflect the sky 
    //also comment out both of these lines "boxNode.geometry.firstMaterial.reflective 
    //and sky box will still work 
    //----------------------------------------------------------------------------------- 

    //VERSION 1 - ALSO WORKS! 
    boxNode.geometry.firstMaterial.reflective.contents = @[[NSImage imageNamed:@"right.tga"], 
                  [NSImage imageNamed:@"left.tga"], 
                  [NSImage imageNamed:@"top.tga"], 
                  [NSImage imageNamed:@"bottom.tga"], 
                  [NSImage imageNamed:@"back.tga"], 
                  [NSImage imageNamed:@"front.tga"]]; 

    boxNode.geometry.firstMaterial.reflective.intensity = 0.7; 
    //----------------------------------------------------------------------------------- 
    //VERSION 2 - ALSO WORKS! 
    //this uses same image for all sides of the cube 
    //boxNode.geometry.firstMaterial.reflective.contents = [NSImage imageNamed:@"right.tga"];//ok 
    //boxNode.geometry.firstMaterial.reflective.intensity = 0.7; 


    //----------------------------------------------------------------------------------- 
    //VERSION 3 - BLACK 2010 a space odyssey shiny cube 
    //get the earth-reflective.jpg from 
    //https://developer.apple.com/library/mac/samplecode/SceneKit_Slides_WWDC2013/Introduction/Intro.html 
// boxNode.geometry.firstMaterial.reflective.contents = [NSImage imageNamed:@"earth-reflective"]; 
// boxNode.geometry.firstMaterial.reflective.intensity = 0.7; 

    //----------------------------------------------------------------------------------- 
    //----------------------------------------------------------------------------------- 
    //REQUIRED else above reflections look weird 
    boxNode.geometry.firstMaterial.diffuse.contents = [NSColor blackColor]; 
    boxNode.geometry.firstMaterial.specular.intensity = 0.0; 

    //----------------------------------------------------------------------------------- 
    // animate the 3d object - camera control is on so cube spins with the sky 
    //comment in to animate cube 

// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"rotation"]; 
// animation.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(1, 1, 0, M_PI*2)]; 
// animation.duration = 5; 
// animation.repeatCount = MAXFLOAT; //repeat forever 
// [boxNode addAnimation:animation forKey:nil]; 

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

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

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

} 
@end 
+0

की शक्ति होना चाहिए। एससीएनएमटेरियलप्रॉपर्टी.contents की परिभाषा के अनुसार, आप इनमें से किसी भी का उपयोग कर सकते हैं: 1. एक क्षैतिज पट्टी छवि जहां '6 * image.height == image.width ' 2. एक लंबवत पट्टी छवि जहां' image.height == 6 * image.width' 3. एक क्षैतिज क्रॉस छवि जहां '4 * image.height == 3 * image.width' 4. एक लंबवत क्रॉस छवि जहां '3 * image.height == 4 * image.width' 5. एक लेट/लम्बी छवि जहां' image.height == 2 * image.width' 6. 6 छवियों का एक एनएसएआरएआरई। – alexchandel

संबंधित मुद्दे