Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Cocos3D-hello world场景在集成到uikit中时不显示_Iphone_Objective C_Ipad_Cocos2d Iphone_Cocos3d - Fatal编程技术网

Iphone Cocos3D-hello world场景在集成到uikit中时不显示

Iphone Cocos3D-hello world场景在集成到uikit中时不显示,iphone,objective-c,ipad,cocos2d-iphone,cocos3d,Iphone,Objective C,Ipad,Cocos2d Iphone,Cocos3d,我想在我的一个视图中集成cocos3d。因此,我有一个普通的视图控制器(MapEditorViewController)和一个视图,在我的视图控制器中,(我创建了一个IBOutlet CCGLView*openGLView),我希望cocos3d在其中。在我的视图控制器中,我有一个方法setupCocos3D: MapEditorViewController - (void)setupCocos3D { [[CCDirector sharedDirector] setOpenGLVie

我想在我的一个视图中集成cocos3d。因此,我有一个普通的视图控制器(
MapEditorViewController
)和一个视图,在我的视图控制器中,(我创建了一个
IBOutlet CCGLView*openGLView
),我希望cocos3d在其中。在我的视图控制器中,我有一个方法setupCocos3D:

MapEditorViewController

- (void)setupCocos3D {

    [[CCDirector sharedDirector] setOpenGLView:openGLView];

    // Create the customized CC3Layer that supports 3D rendering.
    CC3Layer* cc3Layer = [HelloWorldLayer node];

    // Create the customized 3D scene and attach it to the layer.
    // Could also just create this inside the customer layer.
    cc3Layer.cc3Scene = [testScene scene];

    // Assign to a generic variable so we can uncomment options below to play with the capabilities
    CC3ControllableLayer* mainLayer = cc3Layer;

    // The 3D layer can run either directly in the scene, or it can run as a smaller "sub-window"
    // within any standard CCLayer. So you can have a mostly 2D window, with a smaller 3D window
    // embedded in it. To experiment with this smaller embedded 3D window, uncomment the following lines:
    //  CGSize winSize = CCDirector.sharedDirector.winSize;
    //  cc3Layer.position = ccp(30.0, 30.0);
    //  cc3Layer.contentSize = CGSizeMake(winSize.width - 100.0, winSize.width - 40.0);
    //  cc3Layer.alignContentSizeWithDeviceOrientation = YES;
    //  mainLayer = [CC3ControllableLayer node];
    //  [mainLayer addChild: cc3Layer];

    // A smaller 3D layer can even be moved around on the screen dyanmically. To see this in action,
    // uncomment the lines above as described, and also uncomment the following two lines.
    //  cc3Layer.position = ccp(0.0, 0.0);
    //  [cc3Layer runAction: [CCMoveTo actionWithDuration: 15.0 position: ccp(500.0, 250.0)]];

    // Attach the layer to the controller and run a scene with it.


    [CCDirector sharedDirector].animationInterval = (1.0f / kAnimationFrameRate);
    [CCDirector sharedDirector].displayStats = YES;
[[CCDirector sharedDirector] enableRetinaDisplay: YES];

    [[CCDirector sharedDirector] runWithScene:mainLayer];
}
在类
MapEditorViewController
viewDidLoad
中调用
SetupCoCoCos3D

我有两个文件
testScene
testLayer(这里称为HelloWorldLayer)
,它们是从helloworld默认cocos3d项目复制的

testScene.m

/**
 * Constructs the 3D scene.
 *
 * Adds 3D objects to the scene, loading a 3D 'hello, world' message
 * from a POD file, and creating the camera and light programatically.
 *
 * When adapting this template to your application, remove all of the content
 * of this method, and add your own to construct your 3D model scene.
 *
 * NOTES:
 *
 * 1) To help you find your scene content once it is loaded, the onOpen method below contains
 *    code to automatically move the camera so that it frames the scene. You can remove that
 *    code once you know where you want to place your camera.
 *
 * 2) The POD file used for the 'hello, world' message model is fairly large, because converting a
 *    font to a mesh results in a LOT of triangles. When adapting this template project for your own
 *    application, REMOVE the POD file 'hello-world.pod' from the Resources folder of your project.
 */
-(void) initializeScene {

    // Create the camera, place it back a bit, and add it to the scene
    CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"];
    cam.location = cc3v( 0.0, 0.0, 6.0 );
    [self addChild: cam];

    // Create a light, place it back and to the left at a specific
    // position (not just directional lighting), and add it to the scene
    CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
    lamp.location = cc3v( -2.0, 0.0, 0.0 );
    lamp.isDirectionalOnly = NO;
    [cam addChild: lamp];

    // This is the simplest way to load a POD resource file and add the
    // nodes to the CC3Scene, if no customized resource subclass is needed.
    [self addContentFromPODFile: @"hello-world.pod"];


    // Create OpenGL ES buffers for the vertex arrays to keep things fast and efficient,
    // and to save memory, release the vertex content in main memory because it is now redundant.
    [self createGLBuffers];
    [self releaseRedundantContent];

    // That's it! The scene is now constructed and is good to go.

    // To help you find your scene content once it is loaded, the onOpen method below contains
    // code to automatically move the camera so that it frames the scene. You can remove that
    // code once you know where you want to place your camera.

    // If you encounter problems displaying your models, you can uncomment one or more of the
    // following lines to help you troubleshoot. You can also use these features on a single node,
    // or a structure of nodes. See the CC3Node notes for more explanation of these properties.
    // Also, the onOpen method below contains additional troubleshooting code you can comment
    // out to move the camera so that it will display the entire scene automatically.

    // Displays short descriptive text for each node (including class, node name & tag).
    // The text is displayed centered on the pivot point (origin) of the node.
//  self.shouldDrawAllDescriptors = YES;

    // Displays bounding boxes around those nodes with local content (eg- meshes).
//  self.shouldDrawAllLocalContentWireframeBoxes = YES;

    // Displays bounding boxes around all nodes. The bounding box for each node
    // will encompass its child nodes.
//  self.shouldDrawAllWireframeBoxes = YES;

    // If you encounter issues creating and adding nodes, or loading models from
    // files, the following line is used to log the full structure of the scene.
    LogInfo(@"The structure of this scene is: %@", [self structureDescription]);

    // ------------------------------------------

    // And to add some dynamism, we'll animate the 'hello, world' message
    // using a couple of actions...

    // Fetch the 'hello, world' object that was loaded from the POD file and start it rotating
    CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeNamed: @"Hello"];
    CCActionInterval* partialRot = [CC3RotateBy actionWithDuration: 1.0
                                                          rotateBy: cc3v(0.0, 30.0, 0.0)];
    [helloTxt runAction: [CCRepeatForever actionWithAction: partialRot]];

    // To make things a bit more appealing, set up a repeating up/down cycle to
    // change the color of the text from the original red to blue, and back again.
    GLfloat tintTime = 8.0f;
    ccColor3B startColor = helloTxt.color;
    ccColor3B endColor = { 50, 0, 200 };
    CCActionInterval* tintDown = [CCTintTo actionWithDuration: tintTime
                                                          red: endColor.r
                                                        green: endColor.g
                                                         blue: endColor.b];
    CCActionInterval* tintUp = [CCTintTo actionWithDuration: tintTime
                                                        red: startColor.r
                                                      green: startColor.g
                                                       blue: startColor.b];
     CCActionInterval* tintCycle = [CCSequence actionOne: tintDown two: tintUp];
    [helloTxt runAction: [CCRepeatForever actionWithAction: tintCycle]];
}


#pragma mark Updating custom activity

/**
 * This template method is invoked periodically whenever the 3D nodes are to be updated.
 *
 * This method provides your app with an opportunity to perform update activities before
 * any changes are applied to the transformMatrix of the 3D nodes in the scene.
 *
 * For more info, read the notes of this method on CC3Node.
 */
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {}

/**
 * This template method is invoked periodically whenever the 3D nodes are to be updated.
 *
 * This method provides your app with an opportunity to perform update activities after
 * the transformMatrix of the 3D nodes in the scen have been recalculated.
 *
 * For more info, read the notes of this method on CC3Node.
 */
-(void) updateAfterTransform: (CC3NodeUpdatingVisitor*) visitor {
    // If you have uncommented the moveWithDuration: invocation in the onOpen: method, you
    // can uncomment the following to track how the camera moves, where it ends up, and what
    // the camera's clipping distances are, in order to determine how to position and configure
    // the camera to view the entire scene.
//  LogDebug(@"Camera: %@", activeCamera.fullDescription);
}


#pragma mark Scene opening and closing

/**
 * Callback template method that is invoked automatically when the CC3Layer that
 * holds this scene is first displayed.
 *
 * This method is a good place to invoke one of CC3Camera moveToShowAllOf:... family
 * of methods, used to cause the camera to automatically focus on and frame a particular
 * node, or the entire scene.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) onOpen {

    // Move the camera to frame the scene. You can uncomment the LogDebug line in the
    // updateAfterTransform: method to track how the camera moves, where it ends up, and
    // what the camera's clipping distances are, in order to determine how to position
    // and configure the camera to view your entire scene. Then you can remove this code.
    //[self.activeCamera moveWithDuration: 3.0 toShowAllOf: self withPadding: 0.5f];

    // Uncomment this line to draw the bounding box of the scene.
//  self.shouldDrawWireframeBox = YES;
}

/**
 * Callback template method that is invoked automatically when the CC3Layer that
 * holds this scene has been removed from display.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) onClose {}


#pragma mark Handling touch events 

/**
 * This method is invoked from the CC3Layer whenever a touch event occurs, if that layer
 * has indicated that it is interested in receiving touch events, and is handling them.
 *
 * Override this method to handle touch events, or remove this method to make use of
 * the superclass behaviour of selecting 3D nodes on each touch-down event.
 *
 * This method is not invoked when gestures are used for user interaction. Your custom
 * CC3Layer processes gestures and invokes higher-level application-defined behaviour
 * on this customized CC3Scene subclass.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {}

/**
 * This callback template method is invoked automatically when a node has been picked
 * by the invocation of the pickNodeFromTapAt: or pickNodeFromTouchEvent:at: methods,
 * as a result of a touch event or tap gesture.
 *
 * Override this method to perform activities on 3D nodes that have been picked by the user.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {

}
//
//  HelloWorldLayer.m
//  testCocos2d
//
//  Created by Etienne Noel on 2013-03-15.
//  Copyright __MyCompanyName__ 2013. All rights reserved.
//


// Import the interfaces
#import "HelloWorldLayer.h"

// Needed to obtain the Navigation Controller
#import "AppDelegate.h"




#pragma mark - HelloWorldLayer

// HelloWorldLayer implementation
@implementation HelloWorldLayer

/**
 * Override to set up your 2D controls and other initial state, and to initialize update processing.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) initializeControls {
    [self scheduleUpdate];
}


#pragma mark Updating layer

/**
 * Override to perform set-up activity prior to the scene being opened
 * on the view, such as adding gesture recognizers.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) onOpenCC3Layer {}

/**
 * Override to perform tear-down activity prior to the scene disappearing.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) onCloseCC3Layer {}

/**
 * The ccTouchMoved:withEvent: method is optional for the <CCTouchDelegateProtocol>.
 * The event dispatcher will not dispatch events for which there is no method
 * implementation. Since the touch-move events are both voluminous and seldom used,
 * the implementation of ccTouchMoved:withEvent: has been left out of the default
 * CC3Layer implementation. To receive and handle touch-move events for object
 * picking, uncomment the following method implementation.
 */
/*
 -(void) ccTouchMoved: (UITouch *)touch withEvent: (UIEvent *)event {
 [self handleTouch: touch ofType: kCCTouchMoved];
 }
 */
@end
HelloWorldLayer.m

/**
 * Constructs the 3D scene.
 *
 * Adds 3D objects to the scene, loading a 3D 'hello, world' message
 * from a POD file, and creating the camera and light programatically.
 *
 * When adapting this template to your application, remove all of the content
 * of this method, and add your own to construct your 3D model scene.
 *
 * NOTES:
 *
 * 1) To help you find your scene content once it is loaded, the onOpen method below contains
 *    code to automatically move the camera so that it frames the scene. You can remove that
 *    code once you know where you want to place your camera.
 *
 * 2) The POD file used for the 'hello, world' message model is fairly large, because converting a
 *    font to a mesh results in a LOT of triangles. When adapting this template project for your own
 *    application, REMOVE the POD file 'hello-world.pod' from the Resources folder of your project.
 */
-(void) initializeScene {

    // Create the camera, place it back a bit, and add it to the scene
    CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"];
    cam.location = cc3v( 0.0, 0.0, 6.0 );
    [self addChild: cam];

    // Create a light, place it back and to the left at a specific
    // position (not just directional lighting), and add it to the scene
    CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
    lamp.location = cc3v( -2.0, 0.0, 0.0 );
    lamp.isDirectionalOnly = NO;
    [cam addChild: lamp];

    // This is the simplest way to load a POD resource file and add the
    // nodes to the CC3Scene, if no customized resource subclass is needed.
    [self addContentFromPODFile: @"hello-world.pod"];


    // Create OpenGL ES buffers for the vertex arrays to keep things fast and efficient,
    // and to save memory, release the vertex content in main memory because it is now redundant.
    [self createGLBuffers];
    [self releaseRedundantContent];

    // That's it! The scene is now constructed and is good to go.

    // To help you find your scene content once it is loaded, the onOpen method below contains
    // code to automatically move the camera so that it frames the scene. You can remove that
    // code once you know where you want to place your camera.

    // If you encounter problems displaying your models, you can uncomment one or more of the
    // following lines to help you troubleshoot. You can also use these features on a single node,
    // or a structure of nodes. See the CC3Node notes for more explanation of these properties.
    // Also, the onOpen method below contains additional troubleshooting code you can comment
    // out to move the camera so that it will display the entire scene automatically.

    // Displays short descriptive text for each node (including class, node name & tag).
    // The text is displayed centered on the pivot point (origin) of the node.
//  self.shouldDrawAllDescriptors = YES;

    // Displays bounding boxes around those nodes with local content (eg- meshes).
//  self.shouldDrawAllLocalContentWireframeBoxes = YES;

    // Displays bounding boxes around all nodes. The bounding box for each node
    // will encompass its child nodes.
//  self.shouldDrawAllWireframeBoxes = YES;

    // If you encounter issues creating and adding nodes, or loading models from
    // files, the following line is used to log the full structure of the scene.
    LogInfo(@"The structure of this scene is: %@", [self structureDescription]);

    // ------------------------------------------

    // And to add some dynamism, we'll animate the 'hello, world' message
    // using a couple of actions...

    // Fetch the 'hello, world' object that was loaded from the POD file and start it rotating
    CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeNamed: @"Hello"];
    CCActionInterval* partialRot = [CC3RotateBy actionWithDuration: 1.0
                                                          rotateBy: cc3v(0.0, 30.0, 0.0)];
    [helloTxt runAction: [CCRepeatForever actionWithAction: partialRot]];

    // To make things a bit more appealing, set up a repeating up/down cycle to
    // change the color of the text from the original red to blue, and back again.
    GLfloat tintTime = 8.0f;
    ccColor3B startColor = helloTxt.color;
    ccColor3B endColor = { 50, 0, 200 };
    CCActionInterval* tintDown = [CCTintTo actionWithDuration: tintTime
                                                          red: endColor.r
                                                        green: endColor.g
                                                         blue: endColor.b];
    CCActionInterval* tintUp = [CCTintTo actionWithDuration: tintTime
                                                        red: startColor.r
                                                      green: startColor.g
                                                       blue: startColor.b];
     CCActionInterval* tintCycle = [CCSequence actionOne: tintDown two: tintUp];
    [helloTxt runAction: [CCRepeatForever actionWithAction: tintCycle]];
}


#pragma mark Updating custom activity

/**
 * This template method is invoked periodically whenever the 3D nodes are to be updated.
 *
 * This method provides your app with an opportunity to perform update activities before
 * any changes are applied to the transformMatrix of the 3D nodes in the scene.
 *
 * For more info, read the notes of this method on CC3Node.
 */
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {}

/**
 * This template method is invoked periodically whenever the 3D nodes are to be updated.
 *
 * This method provides your app with an opportunity to perform update activities after
 * the transformMatrix of the 3D nodes in the scen have been recalculated.
 *
 * For more info, read the notes of this method on CC3Node.
 */
-(void) updateAfterTransform: (CC3NodeUpdatingVisitor*) visitor {
    // If you have uncommented the moveWithDuration: invocation in the onOpen: method, you
    // can uncomment the following to track how the camera moves, where it ends up, and what
    // the camera's clipping distances are, in order to determine how to position and configure
    // the camera to view the entire scene.
//  LogDebug(@"Camera: %@", activeCamera.fullDescription);
}


#pragma mark Scene opening and closing

/**
 * Callback template method that is invoked automatically when the CC3Layer that
 * holds this scene is first displayed.
 *
 * This method is a good place to invoke one of CC3Camera moveToShowAllOf:... family
 * of methods, used to cause the camera to automatically focus on and frame a particular
 * node, or the entire scene.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) onOpen {

    // Move the camera to frame the scene. You can uncomment the LogDebug line in the
    // updateAfterTransform: method to track how the camera moves, where it ends up, and
    // what the camera's clipping distances are, in order to determine how to position
    // and configure the camera to view your entire scene. Then you can remove this code.
    //[self.activeCamera moveWithDuration: 3.0 toShowAllOf: self withPadding: 0.5f];

    // Uncomment this line to draw the bounding box of the scene.
//  self.shouldDrawWireframeBox = YES;
}

/**
 * Callback template method that is invoked automatically when the CC3Layer that
 * holds this scene has been removed from display.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) onClose {}


#pragma mark Handling touch events 

/**
 * This method is invoked from the CC3Layer whenever a touch event occurs, if that layer
 * has indicated that it is interested in receiving touch events, and is handling them.
 *
 * Override this method to handle touch events, or remove this method to make use of
 * the superclass behaviour of selecting 3D nodes on each touch-down event.
 *
 * This method is not invoked when gestures are used for user interaction. Your custom
 * CC3Layer processes gestures and invokes higher-level application-defined behaviour
 * on this customized CC3Scene subclass.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {}

/**
 * This callback template method is invoked automatically when a node has been picked
 * by the invocation of the pickNodeFromTapAt: or pickNodeFromTouchEvent:at: methods,
 * as a result of a touch event or tap gesture.
 *
 * Override this method to perform activities on 3D nodes that have been picked by the user.
 *
 * For more info, read the notes of this method on CC3Scene.
 */
-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {

}
//
//  HelloWorldLayer.m
//  testCocos2d
//
//  Created by Etienne Noel on 2013-03-15.
//  Copyright __MyCompanyName__ 2013. All rights reserved.
//


// Import the interfaces
#import "HelloWorldLayer.h"

// Needed to obtain the Navigation Controller
#import "AppDelegate.h"




#pragma mark - HelloWorldLayer

// HelloWorldLayer implementation
@implementation HelloWorldLayer

/**
 * Override to set up your 2D controls and other initial state, and to initialize update processing.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) initializeControls {
    [self scheduleUpdate];
}


#pragma mark Updating layer

/**
 * Override to perform set-up activity prior to the scene being opened
 * on the view, such as adding gesture recognizers.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) onOpenCC3Layer {}

/**
 * Override to perform tear-down activity prior to the scene disappearing.
 *
 * For more info, read the notes of this method on CC3Layer.
 */
-(void) onCloseCC3Layer {}

/**
 * The ccTouchMoved:withEvent: method is optional for the <CCTouchDelegateProtocol>.
 * The event dispatcher will not dispatch events for which there is no method
 * implementation. Since the touch-move events are both voluminous and seldom used,
 * the implementation of ccTouchMoved:withEvent: has been left out of the default
 * CC3Layer implementation. To receive and handle touch-move events for object
 * picking, uncomment the following method implementation.
 */
/*
 -(void) ccTouchMoved: (UITouch *)touch withEvent: (UIEvent *)event {
 [self handleTouch: touch ofType: kCCTouchMoved];
 }
 */
@end
//
//HelloWorldLayer.m
//testCocos2d
//
//由Etienne Noel于2013年3月15日创建。
//版权所有uu MyCompanyName uuu 2013。版权所有。
//
//导入接口
#导入“HelloWorldLayer.h”
//需要获取导航控制器
#导入“AppDelegate.h”
#pragma标记-HelloWorldLayer
//HelloWorldLayer实现
@HelloWorldLayer的实现
/**
*覆盖以设置2D控件和其他初始状态,并初始化更新处理。
*
*有关更多信息,请阅读CC3Layer上此方法的注释。
*/
-(无效)初始化控件{
[自计划更新];
}
#杂注标记更新层
/**
*覆盖以在打开场景之前执行设置活动
*在视图上,例如添加手势识别器。
*
*有关更多信息,请阅读CC3Layer上此方法的注释。
*/
-(void)层{}
/**
*覆盖以在场景消失之前执行拆除活动。
*
*有关更多信息,请阅读CC3Layer上此方法的注释。
*/
-(void)onCloseCC3层{}
/**
*ccTouchMoved:withEvent:方法对于是可选的。
*事件分派器不会分派没有方法的事件
*实施。由于触摸移动事件数量庞大且很少使用,
*默认情况下,ccTouchMoved:withEvent:的实现被排除在外
*CC3层实现。接收和处理对象的触摸移动事件
*拾取,取消对以下方法实现的注释。
*/
/*
-(无效)ccTouchMoved:(UITouch*)触摸事件:(UIEvent*)事件{
[自手触摸:触摸类型:KCCTOOCHMOVED];
}
*/
@结束
一切都在编译,我只看到一个黑屏。我已经包含了hello-world.pod文件,在控制台中,一切似乎都很好(日志显示该文件已正确加载)


为什么我没有看到hello world,即使我看到了统计数据(fps等)?

对于我来说,在MapEditorViewController中添加这一行:

mainLayer.contentSize = CGSizeMake(2048, 1320);
创建
mainLayer
解决了我的问题之后…

chk you mesh或“”