CC3Vector* vertices; // Array of simple vertex location data // Start with default initial values // Interleave the vertex locations, normals and tex coords // Create vertex location array, allocating enough space for the stride of the full structure CC3VertexLocations* locArray = [CC3VertexLocations vertexArrayWithName: @"PointCloudLocations"]; locArray.drawingMode = GL_POINTS;// GL_TRIANGLE_STRIP; // Location array will do the drawing as a strip locArray.elementStride = sizeof(CC3Vector); // Set stride before allocating elements. locArray.elementOffset = 0; // Only locations locArray.bufferUsage = GL_DYNAMIC_DRAW; vertices = (CC3Vector*)[locArray allocateElements: vCount]; // set pointcloud data to vertices memcpy(vertices,(float*)points->points, sizeof(float)*3*vCount); // Create mesh model with vertex location array CC3VertexArrayMeshModel* demoMeshModel = [[CC3VertexArrayMeshModel meshWithName:@"demoMeshModel"] retain]; demoMeshModel.vertexLocations = locArray; CC3MeshNode* demoMesh = [CC3MeshNode nodeWithName:@"demoMeshNode"]; demoMesh.mesh = demoMeshModel; static ccColor4F color = {1.0, 0.0, 0.0, 1.0}; //red color // create a material for points CC3Material* pointMaterial = [CC3Material material]; [pointMaterial setAmbientColor:color]; [pointMaterial setDiffuseColor:color]; [pointMaterial setSpecularColor:color]; [pointMaterial setIsOpaque:NO]; demoMesh.material = pointMaterial;//[CC3Material shiny]; demoMesh.material.name = [NSString stringWithFormat: @"demoMeshNodeMat"]; //demoMesh.material.diffuseColor = CCC4FMake(1.0, 0.0, 0.0, 1.0);//fill the mesh with red color [mainworld addChild:demoMesh];
mainworld 是CC3world的子类实例。