コード例 #1
0
ファイル: FffProcessor.cpp プロジェクト: 976717326/CuraEngine
std::string FffProcessor::getAllSettingsString(MeshGroup& meshgroup, bool first_meshgroup)
{
    std::stringstream sstream;
    if (first_meshgroup)
    {
        sstream << getAllLocalSettingsString(); // global settings
        sstream << " -g";
    }
    else 
    {
        sstream << " --next";
    }
    sstream << meshgroup.getAllLocalSettingsString();
    for (int extruder_nr = 0; extruder_nr < meshgroup.getExtruderCount(); extruder_nr++)
    {
        ExtruderTrain* train = meshgroup.getExtruderTrain(extruder_nr);
        sstream << " -e" << extruder_nr << train->getAllLocalSettingsString();
    }
    for (unsigned int mesh_idx = 0; mesh_idx < meshgroup.meshes.size(); mesh_idx++)
    {
        Mesh& mesh = meshgroup.meshes[mesh_idx];
        sstream << " -e" << mesh.getSettingAsIndex("extruder_nr") << " -l \"" << mesh_idx << "\"" << mesh.getAllLocalSettingsString();
    }
    sstream << "\n";
    return sstream.str();
}
コード例 #2
0
void
countVertices(MeshGroup const & mg, long & num_vertices)
{
  for (MeshGroup::MeshConstIterator mi = mg.meshesBegin(); mi != mg.meshesEnd(); ++mi)
    num_vertices += (*mi)->numVertices();

  for (MeshGroup::GroupConstIterator ci = mg.childrenBegin(); ci != mg.childrenEnd(); ++ci)
    countVertices(**ci, num_vertices);
}
コード例 #3
0
ファイル: gcodeExport.cpp プロジェクト: Mambix/CuraEngine
void GCodeExport::setInitialTemps(const MeshGroup& settings)
{
    for (unsigned int extr_nr = 0; extr_nr < extruder_count; extr_nr++)
    {
        const ExtruderTrain* extr_train = settings.getExtruderTrain(extr_nr);
        assert(extr_train);
        double temp = extr_train->getSettingInDegreeCelsius((extr_nr == 0)? "material_print_temperature" : "material_standby_temperature");
        setInitialTemp(extr_nr, temp);
    }

    initial_bed_temp = settings.getSettingInDegreeCelsius("material_bed_temperature");
}
コード例 #4
0
MeshGroup *
Mesh::getAncestor(long generations) const
{
  if (generations < 1)
  {
    THEA_ERROR << getName() << ": Ancestor generation gap must be >= 1";
    return NULL;
  }

  MeshGroup * anc = parent;
  if (!anc)
      return anc;

  while (--generations > 0 && anc->getParent())
    anc = anc->getParent();

  return anc;
}
コード例 #5
0
// A rather hacky way of forming a joint descriptor, suitable only for exact matches like we want here
void
accumGroupFeatures(MeshGroup const & mg, TheaArray<double> & features)
{
  for (MeshGroup::MeshConstIterator mi = mg.meshesBegin(); mi != mg.meshesEnd(); ++mi)
  {
    TheaArray<double> const & mf = (*mi)->getFeatures();
    if (features.empty())
      features.resize(mf.size());

    alwaysAssertM(mf.size() == features.size(), "Feature vectors have different sizes");

    for (array_size_t j = 0; j < features.size(); ++j)
      features[j] += mf[j];
  }

  for (MeshGroup::GroupConstIterator ci = mg.childrenBegin(); ci != mg.childrenEnd(); ++ci)
    accumGroupFeatures(**ci, features);
}
コード例 #6
0
ファイル: FffProcessor.cpp プロジェクト: 976717326/CuraEngine
bool FffProcessor::processFiles(const std::vector< std::string >& files)
{
    time_keeper.restart();
    MeshGroup* meshgroup = new MeshGroup(this);
    
    for(std::string filename : files)
    {
        log("Loading %s from disk...\n", filename.c_str());

        FMatrix3x3 matrix;
        if (!loadMeshIntoMeshGroup(meshgroup, filename.c_str(), matrix))
        {
            logError("Failed to load model: %s\n", filename.c_str());
            return false;
        }
    }
    
    meshgroup->finalize();

    log("Loaded from disk in %5.3fs\n", time_keeper.restart());
    return processMeshGroup(meshgroup);
}
コード例 #7
0
static void Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glCullFace(GL_BACK);
	
	meshGroup.Render();
	
	//glBindVertexArray(vao);
	//glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0);
	//glBindVertexArray(0);

	glDisable(GL_DEPTH_TEST);
	glutSwapBuffers();
}
コード例 #8
0
void CommandSocket::handleObjectList(cura::proto::ObjectList* list)
{
    if (list->objects_size() <= 0)
    {
        return;
    }

    FMatrix3x3 matrix;
    //private_data->object_count = 0;
    //private_data->object_ids.clear();
    private_data->objects_to_slice.push_back(std::make_shared<MeshGroup>(FffProcessor::getInstance()));
    MeshGroup* meshgroup = private_data->objects_to_slice.back().get();
    
    for (auto setting : list->settings())
    {
        meshgroup->setSetting(setting.name(), setting.value());
    }
    
    for (int extruder_nr = 0; extruder_nr < FffProcessor::getInstance()->getSettingAsCount("machine_extruder_count"); extruder_nr++)
    { // initialize remaining extruder trains and load the defaults
        ExtruderTrain* train = meshgroup->createExtruderTrain(extruder_nr); // create new extruder train objects or use already existing ones
        SettingRegistry::getInstance()->loadExtruderJSONsettings(extruder_nr, train);
    }
    
    for (auto object : list->objects())
    {
        int bytes_per_face = BYTES_PER_FLOAT * FLOATS_PER_VECTOR * VECTORS_PER_FACE;
        int face_count = object.vertices().size() / bytes_per_face;

        if (face_count <= 0)
        {
            logWarning("Got an empty mesh, ignoring it!");
            continue;
        }
        DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("solid Cura_out\n");
        int extruder_train_nr = 0; // TODO: make primary extruder configurable!
        for (auto setting : object.settings())
        {
            if (setting.name() == "extruder_nr")
            {
                extruder_train_nr = std::stoi(setting.value());
                break;
            }
        }
        SettingsBase* extruder_train = meshgroup->getExtruderTrain(extruder_train_nr);

        meshgroup->meshes.push_back(extruder_train); //Construct a new mesh (with the corresponding extruder train as settings parent object) and put it into MeshGroup's mesh list.
        Mesh& mesh = meshgroup->meshes.back();

        for (int i = 0; i < face_count; ++i)
        {
            //TODO: Apply matrix
            std::string data = object.vertices().substr(i * bytes_per_face, bytes_per_face);
            const FPoint3* float_vertices = reinterpret_cast<const FPoint3*>(data.data());

            Point3 verts[3];
            verts[0] = matrix.apply(float_vertices[0]);
            verts[1] = matrix.apply(float_vertices[1]);
            verts[2] = matrix.apply(float_vertices[2]);
            mesh.addFace(verts[0], verts[1], verts[2]);

            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("  facet normal -1 0 0\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("    outer loop\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("      vertex "<<INT2MM(verts[0].x) <<" " << INT2MM(verts[0].y) <<" " << INT2MM(verts[0].z) << "\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("      vertex "<<INT2MM(verts[1].x) <<" " << INT2MM(verts[1].y) <<" " << INT2MM(verts[1].z) << "\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("      vertex "<<INT2MM(verts[2].x) <<" " << INT2MM(verts[2].y) <<" " << INT2MM(verts[2].z) << "\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("    endloop\n");
            DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("  endfacet\n");
        }
        DEBUG_OUTPUT_OBJECT_STL_THROUGH_CERR("endsolid Cura_out\n");
        for (auto setting : object.settings())
        {
            mesh.setSetting(setting.name(), setting.value());
        }

        mesh.finish();
    }

    private_data->object_count++;
    meshgroup->finalize();
}
コード例 #9
0
int main(int argc, char *argv[])
{
	glutInit(&argc, argv);

	Init("Robot", 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);

	glewExperimental = true;
	GLenum err = glewInit();
	if (err != GLEW_OK)
	{
		fprintf(stderr, "main(): glew init error (error: %s)\n",
			glewGetErrorString(err));
		system("pause");
		return -1;
	}

	GLuint gShaderProgram = glCreateProgram();
	GLuint vShader = LoadShader(GL_VERTEX_SHADER, "shader.vs");
	GLuint fShader = LoadShader(GL_FRAGMENT_SHADER, "shader.fs");
	glAttachShader(gShaderProgram, vShader);
	glAttachShader(gShaderProgram, fShader);

	GLint success;

	glLinkProgram(gShaderProgram);
	glGetProgramiv(gShaderProgram, GL_LINK_STATUS, &success);
	if (success == 0) {
		GLchar ErrorLog[1024];
		glGetProgramInfoLog(gShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
	}
	glValidateProgram(gShaderProgram);
	glUseProgram(gShaderProgram);
	glDetachShader(gShaderProgram, vShader);
	glDetachShader(gShaderProgram, fShader);

	//static const float FieldDepth = 20.0f;
	//static const float FieldWidth = 10.0f;

	//Vertex Vertices[4] = { 
	//	Vertex(glm::vec3(-1.0f, -1.0f, 0.5773f), glm::vec2(0.0f, 0.0f)),
	//	Vertex(glm::vec3(0.0f, -1.0f, -1.15475f), glm::vec2(0.5f, 0.0f)),
	//	Vertex(glm::vec3(1.0f, -1.0f, 0.5773f),  glm::vec2(1.0f, 0.0f)),
	//	Vertex(glm::vec3(0.0f, 1.0f, 0.0f),      glm::vec2(0.5f, 1.0f)) };

	//unsigned int Indices[] = { 0, 3, 1,
	//	1, 3, 2,
	//	2, 3, 0,
	//	1, 2, 0 };

	//CalcNormals(Indices, 12, Vertices, 4);

	meshGroup.Load("resource/boblampclean.md5mesh");
	
	gWVP = glGetUniformLocation(gShaderProgram, "gWVP");
	gWorldLocation = glGetUniformLocation(gShaderProgram, "gWorld");
	gSampler = glGetUniformLocation(gShaderProgram, "gSampler");
	gdirLightColorLocation = glGetUniformLocation(gShaderProgram, "gDirectionalLight.Color");
	gdirLightAmbientIntensityLocation = glGetUniformLocation(gShaderProgram, "gDirectionalLight.AmbientIntensity");
	gdirLightDirectionLocation = glGetUniformLocation(gShaderProgram, "gDirectionalLight.Direction");
	gdirLightDiffuseIntensityLocation = glGetUniformLocation(gShaderProgram, "gDirectionalLight.DiffuseIntensity");
	gEyeWorldPosLocation = glGetUniformLocation(gShaderProgram, "gEyeWorldPos");
	gMatSpecularIntensityLocation = glGetUniformLocation(gShaderProgram, "gMatSpecularIntensity");
	gSpecularPowerLocation = glGetUniformLocation(gShaderProgram, "gSpecularPower");
	glUniform1i(gSampler, 0);
	glUniform3f(gdirLightColorLocation, 1, 1, 1);
	glUniform1f(gdirLightAmbientIntensityLocation, 0.55f);
	glUniform3f(gdirLightDirectionLocation, 0, 0, 1);
	glUniform1f(gdirLightDiffuseIntensityLocation, .8f);
	glUniform3f(gEyeWorldPosLocation, gCameraPos.x, gCameraPos.y, gCameraPos.z);
	glUniform1f(gMatSpecularIntensityLocation, 1.0);
	glUniform1f(gSpecularPowerLocation, 8);
	glutMainLoop();

	return 0;
}
コード例 #10
0
ファイル: ObjMesh.cpp プロジェクト: canadar/SchoolWork
GLvoid ObjMesh::readFile(string filename)
{
    // Clean up any lingering data
    rawVerts.clear(); rawNorms.clear(); rawColors.clear();
    rawTexCords.clear(); rawTangents.clear();

    for(uint32_t i=0; i<group.size(); i++)
        delete group[i];
    group.clear();

    uint32_t lineNum = 0;
    MeshGroup* curGroup = NULL;

    // Try to open file
    ifstream fin;
    fin.open(filename.c_str());
    if(!fin.is_open()) return;

    // Parse file
    stringstream linein;
    string firstToken, restOfLine;
    while(!fin.eof() && !fin.bad())
    {
        // Ignore comments (remember to skip to end of line)
        if(fin.peek() == '#') { fin.ignore(256, '\n'); continue; }

        // Read characters up to white-space, null character or EOF
        fin >> firstToken;

        // Read the rest of the line (and any line-breaks)
        getline(fin, restOfLine);
        while(restOfLine.find('\\') != string::npos)
        {
            string tempLine;
            restOfLine[restOfLine.find('\\')] = ' ';
            getline(fin, tempLine);
            restOfLine.append(tempLine);
        }

        // Turn line into stringstrem
        linein.clear();
        linein.str(restOfLine);

        // Parse the different line types
        if(firstToken == "g")
        {
            // If it's not empty (and not NULL), store the current group
            if(curGroup != NULL)
            {
                if(curGroup->isEmpty()) delete curGroup;
                else group.push_back(curGroup);
            }

            // Build list of group names
            vector<string> groupNames; string curName;
            linein >> curName;
            while(!linein.fail())
            {
                if(curName != "") groupNames.push_back(curName);
                linein >> curName;
            }

            // Create a new group
            curGroup = new MeshGroup(this, groupNames);
        }

        //		To properly implement smoothing and merging groups they must be completely
        //		Independent from polygonal groups.  This would require big changes and they
        //		don't come up often enough to warrant this change.  They can be safely
        //		ignored if you are not going to do any merging or smoothing.

        //		else if(firstToken == "s")
        //		{
        //		}

        //		else if(firstToken == "mg")
        //		{
        //		}
        //
        else if(firstToken == "v")
        {
            // Read a vertex
            double X, Y, Z;
            linein >> X >> Y >> Z;

            // Check for formatted input failure
            if(!linein.fail())
            {
                // Store vertex
                rawVerts.push_back(X);
                rawVerts.push_back(Y);
                rawVerts.push_back(Z);

                // Update maximums and minimums
                if(X > maxX) maxX = X; if(X < minX) minX = X;
                if(Y > maxY) maxY = Y; if(Y < minY) minY = Y;
                if(Z > maxZ) maxZ = Z; if(Z < minZ) minZ = Z;

                //				printf("\tv (%f, %f, %f)\n", X, Y, Z);
            }
            else cout << "Vertex line error: '" << restOfLine << "'\n";
        }