Question

Hi friends I want to draw mesh on 2d image as shown in this image, below I have given code, but application is crashing and no error message is displaying...so facing difficulty to identify the problem.

    float arr_location[] = {0.0,0.0,0.0,  0.0,1.0, 0.0,  1.0,1.0,0.0, 1.0,0.0,0.0};

CC3VertexLocations* Vlocation = 
    [[CC3VertexLocations vertexArrayWithName:@"demoLocation"] retain];
Vlocation.drawingMode = GL_TRIANGLES;//
Vlocation.vertexCount = 3;
Vlocation.vertices = arr_location;

    float arr_normal[] = {0.0,0.0,-1.0};
CC3VertexNormals* normal = [[CC3VertexNormals vertexArrayWithName:@"demoNormal"] retain];
normal.vertexCount = 1;
normal.vertices = arr_normal;

    float arr_indice[] = {0,1,2};
CC3VertexIndices* demoIndices = [CC3VertexIndices vertexArrayWithName: @"demoIndicies"];
demoIndices.drawingMode = GL_TRIANGLES;
demoIndices.vertexCount = 3;
demoIndices.vertices = arr_indice;

CC3VertexArrayMesh* demoMeshModel = 
     [[CC3VertexArrayMesh meshWithName:@"demoMeshModel"] retain];
demoMeshModel.vertexLocations = Vlocation;
demoMeshModel.vertexNormals = normal;
demoMeshModel.vertexIndices = demoIndices;

CC3PlaneNode *meshNode = [[CC3PlaneNode alloc] init];
meshNode.mesh = demoMeshModel;
meshNode.material = [CC3Material shiny];
meshNode.texture = [CC3Texture textureFromFile: @"2.jpg"];

[self addChild: meshNode];

Refrence image

Crash SnapShot

Was it helpful?

Solution

I don't think that's possible with cocos2d, that looks like 3D actually, you can do it with OpenGL ES for sure, though I'm not sure how exactly, haven't worked at such a low level yet, but if you can use cocos3d then it's pretty easy using a CC3PlaneNode and setting the picture as the texture. I recommend you to read the programming guide and asking again if you have any further questions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top