本文整理汇总了C++中MeshObject类的典型用法代码示例。如果您正苦于以下问题:C++ MeshObject类的具体用法?C++ MeshObject怎么用?C++ MeshObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MeshObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMeshObjectPtr
PyObject* MeshPy::writeInventor(PyObject *args)
{
float creaseangle=0.0f;
if (!PyArg_ParseTuple(args, "|f",&creaseangle))
return NULL;
MeshObject* mesh = getMeshObjectPtr();
const MeshCore::MeshFacetArray& faces = mesh->getKernel().GetFacets();
std::vector<int> indices;
std::vector<Base::Vector3f> coords;
coords.reserve(mesh->countPoints());
for (MeshObject::const_point_iterator it = mesh->points_begin(); it != mesh->points_end(); ++it)
coords.push_back(Base::Vector3f((float)it->x,(float)it->y,(float)it->z));
indices.reserve(4*faces.size());
for (MeshCore::MeshFacetArray::_TConstIterator it = faces.begin(); it != faces.end(); ++it) {
indices.push_back(it->_aulPoints[0]);
indices.push_back(it->_aulPoints[1]);
indices.push_back(it->_aulPoints[2]);
indices.push_back(-1);
}
std::stringstream result;
Base::InventorBuilder builder(result);
builder.addIndexedFaceSet(coords, indices, creaseangle);
builder.close();
return Py::new_reference_to(Py::String(result.str()));
}
示例2: saveMeshObject
void saveMeshObject(const std::string& filename, MeshObject& mo)
{
std::vector<tinyobj::shape_t> out_shape(1);
tinyobj::mesh_t& mesh = out_shape[0].mesh;
VerticesArray& vts = mo.getVertices();
NormalsArray& nls = mo.getNormals();
FacesArray& fs = mo.getFaces();
for (size_t v = 0; v < vts.size(); ++ v)
{
mesh.positions.push_back(vts[v].x());
mesh.positions.push_back(vts[v].y());
mesh.positions.push_back(vts[v].z());
}
for (size_t n = 0; n < nls.size(); ++ n)
{
mesh.normals.push_back(nls[n].x());
mesh.normals.push_back(nls[n].y());
mesh.normals.push_back(nls[n].z());
}
for (size_t f = 0; f < fs.size(); ++ f)
{
mesh.indices.push_back(fs[f][0]);
mesh.indices.push_back(fs[f][1]);
mesh.indices.push_back(fs[f][2]);
}
bool ret = WriteObj(filename, out_shape, false);
assert(ret);
}
示例3: Material
MainApplication::ComponentCollection MainApplication::addDrawDebug(MeshCollider * collider, int level)
{
BVHNode * root = collider->m_bvh->root();
Material * wireframe = new Material(Shader::find("shader"));
wireframe->setAmbientColor(glm::vec4(1.0f));
wireframe->setWireframe(true);
std::vector<BVHNode *> nodes;
collectBvhs(nodes, root, level, level);
int leaves = 0;
ComponentCollection components;
for (unsigned i = 0; i < nodes.size(); i++) {
BoundingSphere * bs = nodes[i]->m_bv;
if (nodes[i]->m_isLeaf)
leaves++;
MeshObject * sphere = new MeshObject(MeshFactory::Sphere(glm::vec4(1.0f), 10), wireframe);
sphere->transform().translate(bs->c);
sphere->transform().translate(collider->transform().position());
sphere->transform().scale(glm::vec3(1.0f) * bs->r);
components.push_back(sphere);
}
Trace::info("Nodes at level %d: %d (%d leaves)\n", level, nodes.size(), leaves);
return components;
}
示例4: MovableText
void Actor::setHighlighted(bool highlight)
{
if (highlight != mHighlighted)
{
//getControlledObject()->setHighlighted(highlight);
mHighlighted = highlight;
}
if (mHighlighted && mDescription == NULL)
{
if (mSceneNode != NULL)
{
mDescription = new MovableText(mName + "_desc", mName);
mDescription->showOnTop(true);
mDescription->setAlignment(MovableText::ALIGN_CENTER);
if (mActorControlledObject && mActorControlledObject->isMeshObject())
{
MeshObject* mo = static_cast<MeshObject*>(mActorControlledObject);
AxisAlignedBox aabb = mo->getDefaultSize();
mDescription->setPositionOffset(Vector3(0, aabb.getMaximum().y * 1.1, 0));
}
mSceneNode->attachObject(mDescription);
}
}
else if (mDescription)
{
mDescription->setVisible(highlight);
}
}
示例5: switch
void PSCM_Accessor::Set(PB2Value &v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t)
{
switch(id)
{
// case anima_specular_body:
case anima_rgb_value:
// case anima_specular_head:
if (obj!=NULL)
obj->UpdateMaterialValues();
break;
case anima_max_model_value:
if (obj!=NULL)
obj->UpdateMaxModel();
UpdateLabelInfo();
break;
case anima_filepath:
MeshObject::meshObject->Clear();
UpdateLabelInfo();
//MeshObject::meshObject->Load(v.s,FindNodeRef(MeshObject::meshObject));
//MeshObject::meshObject->Load();
// map->SetCubeMapFile(v.s);
break;
}
}
示例6: loadMeshObject
void loadMeshObject(const std::string& filename, MeshObject& mo)
{
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string err = tinyobj::LoadObj(shapes, materials, filename.c_str());
if (!err.empty()) {
std::cerr << err << std::endl;
exit(1);
}
assert(shapes.size() == 1 ? true : ("obj should be only one shape" && false));
tinyobj::mesh_t& mesh = shapes[0].mesh;
assert((mesh.positions.size() % 3) == 0);
assert((mesh.normals.size() % 3) == 0);
assert((mesh.indices.size() % 3) == 0);
VerticesArray& vts = mo.getVertices();
NormalsArray& nls = mo.getNormals();
FacesArray& fs = mo.getFaces();
for (size_t v = 0; v < mesh.positions.size() / 3; v++)
vts.push_back(VertexType(mesh.positions[3*v+0], mesh.positions[3*v+1], mesh.positions[3*v+2]));
for (size_t n = 0; n < mesh.normals.size() / 3; n++)
nls.push_back(NormalType(mesh.normals[3*n+0], mesh.normals[3*n+1], mesh.normals[3*n+2]));
for (size_t f = 0; f < mesh.indices.size() / 3; f++)
fs.push_back(Face(mesh.indices[3*f+0], mesh.indices[3*f+1], mesh.indices[3*f+2]));
}
示例7: MeshObject
RefTargetHandle MeshObject::Clone(RemapDir& remap)
{
MeshObject* newob = new MeshObject(NULL,false);
newob->ReplaceReference(0,remap.CloneRef(pblock));
newob->ivalid.SetEmpty();
BaseClone(this, newob, remap);
return(newob);
}
示例8: getFeaturePtr
PyObject* MeshFeaturePy::removeNonManifolds(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
Mesh::Feature* obj = getFeaturePtr();
MeshObject* kernel = obj->Mesh.startEditing();
kernel->removeNonManifolds();
obj->Mesh.finishEditing();
Py_Return
}
示例9: setItem
bool MaterialSlot::setItem(Item* item)
{
if (!Slot::setItem(item))
{
return false;
}
if (item)
{
try
{
CeGuiString mat = item->getProperty("material").toString();
CeGuiString mesh = item->getSubmeshName();
///@todo: what to do if actor is null?, think about changing the inventory of an gameobject not in scene
if (mOwner->getActor())
{
MeshObject* mo = dynamic_cast<MeshObject*>(
mOwner->getActor()->getControlledObject());
MergeableMeshObject* mmo = dynamic_cast<MergeableMeshObject*>(
mo);
if (mmo && !mesh.empty())
{
mmo->replaceSubmesh(mSubmesh, mesh.c_str());
}
if (mo)
{
mo->setMaterial(mat.c_str(), mSubmesh);
}
}
}
catch (const IllegalArgumentException&)
{
LOG_ERROR(Logger::RULES, "Item " + item->getName() + " has no property material.");
}
catch (const WrongFormatException&)
{
LOG_ERROR(Logger::RULES, "Item " + item->getName() + " has a property material, but it is no string property.");
}
}
else
{
///@todo reset material?
}
return true;
}
示例10: compute_smooth_vertex_normals_base_pose
void compute_smooth_vertex_normals_base_pose(MeshObject& object)
{
assert(object.get_vertex_normal_count() == 0);
const size_t vertex_count = object.get_vertex_count();
const size_t triangle_count = object.get_triangle_count();
vector<GVector3> normals(vertex_count, GVector3(0.0));
for (size_t i = 0; i < triangle_count; ++i)
{
Triangle& triangle = object.get_triangle(i);
triangle.m_n0 = triangle.m_v0;
triangle.m_n1 = triangle.m_v1;
triangle.m_n2 = triangle.m_v2;
const GVector3& v0 = object.get_vertex(triangle.m_v0);
const GVector3& v1 = object.get_vertex(triangle.m_v1);
const GVector3& v2 = object.get_vertex(triangle.m_v2);
const GVector3 normal = normalize(cross(v1 - v0, v2 - v0));
normals[triangle.m_v0] += normal;
normals[triangle.m_v1] += normal;
normals[triangle.m_v2] += normal;
}
object.reserve_vertex_normals(vertex_count);
for (size_t i = 0; i < vertex_count; ++i)
object.push_vertex_normal(safe_normalize(normals[i]));
}
示例11: compute_smooth_vertex_tangents
void compute_smooth_vertex_tangents(MeshObject& object)
{
compute_smooth_vertex_tangents_base_pose(object);
for (size_t i = 0; i < object.get_motion_segment_count(); ++i)
compute_smooth_vertex_tangents_pose(object, i);
}
示例12: insert_objects
void ObjectCollectionItem::insert_objects(const string& path) const
{
const string base_object_name =
bf::path(path).replace_extension().filename().string();
ParamArray params;
params.insert("filename", path);
SearchPaths search_paths;
MeshObjectArray mesh_objects;
if (!MeshObjectReader().read(
search_paths,
base_object_name.c_str(),
params,
mesh_objects))
return;
for (size_t i = 0; i < mesh_objects.size(); ++i)
{
MeshObject* object = mesh_objects[i];
m_parent_item->add_item(object);
m_parent.objects().insert(auto_release_ptr<Object>(object));
const string object_instance_name = string(object->get_name()) + "_inst";
auto_release_ptr<ObjectInstance> object_instance(
ObjectInstanceFactory::create(
object_instance_name.c_str(),
ParamArray(),
object->get_name(),
Transformd::identity(),
StringDictionary()));
m_parent_item->add_item(object_instance.get());
m_parent.object_instances().insert(object_instance);
}
if (!mesh_objects.empty())
{
m_parent.bump_version_id();
m_editor_context.m_project_builder.slot_notify_project_modification();
}
}
示例13: importer
static PyObject * importer(PyObject *self, PyObject *args)
{
char* Name;
char* DocName=0;
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
return NULL;
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
PY_TRY {
App::Document *pcDoc = 0;
if (DocName)
pcDoc = App::GetApplication().getDocument(DocName);
else
pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument(DocName);
}
MeshObject mesh;
if (mesh.load(EncodedName.c_str())) {
Base::FileInfo file(EncodedName.c_str());
unsigned long segmct = mesh.countSegments();
if (segmct > 1) {
for (unsigned long i=0; i<segmct; i++) {
std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(mesh.getSegment(i).getIndices()));
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
pcFeature->Label.setValue(file.fileNamePure().c_str());
pcFeature->Mesh.swapMesh(*segm);
pcFeature->purgeTouched();
}
}
else {
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
pcFeature->Label.setValue(file.fileNamePure().c_str());
pcFeature->Mesh.swapMesh(mesh);
pcFeature->purgeTouched();
}
}
} PY_CATCH;
Py_Return;
}
示例14: compute_smooth_vertex_tangents_pose
void compute_smooth_vertex_tangents_pose(MeshObject& object, const size_t motion_segment_index)
{
assert(object.get_tex_coords_count() > 0);
const size_t vertex_count = object.get_vertex_count();
const size_t triangle_count = object.get_triangle_count();
vector<GVector3> tangents(vertex_count, GVector3(0.0));
for (size_t i = 0; i < triangle_count; ++i)
{
const Triangle& triangle = object.get_triangle(i);
if (!triangle.has_vertex_attributes())
continue;
const GVector2 v0_uv = object.get_tex_coords(triangle.m_a0);
const GVector2 v1_uv = object.get_tex_coords(triangle.m_a1);
const GVector2 v2_uv = object.get_tex_coords(triangle.m_a2);
//
// Reference:
//
// Physically Based Rendering, first edition, pp. 128-129
//
const GScalar du0 = v0_uv[0] - v2_uv[0];
const GScalar dv0 = v0_uv[1] - v2_uv[1];
const GScalar du1 = v1_uv[0] - v2_uv[0];
const GScalar dv1 = v1_uv[1] - v2_uv[1];
const GScalar det = du0 * dv1 - dv0 * du1;
if (det == GScalar(0.0))
continue;
const GVector3& v2 = object.get_vertex_pose(triangle.m_v2, motion_segment_index);
const GVector3 dp0 = object.get_vertex_pose(triangle.m_v0, motion_segment_index) - v2;
const GVector3 dp1 = object.get_vertex_pose(triangle.m_v1, motion_segment_index) - v2;
const GVector3 tangent = normalize(dv1 * dp0 - dv0 * dp1);
tangents[triangle.m_v0] += tangent;
tangents[triangle.m_v1] += tangent;
tangents[triangle.m_v2] += tangent;
}
for (size_t i = 0; i < vertex_count; ++i)
object.set_vertex_tangent_pose(i, motion_segment_index, safe_normalize(tangents[i]));
}
示例15: p
// 添加一个盒子
void GameGrid::AddBox(const Point3& pos)
{
// 格子被占据,不添加
if (!m_World[pos.x][pos.y][pos.z].obj)
{
Vector3f p((float)pos.x - 0.5f - WORLD_SIZE / 2 + 1, (float)pos.y + 0.5f, (float)pos.z - 0.5f - WORLD_SIZE / 2 + 1);
WorldGrid* grid = &m_World[pos.x][pos.y][pos.z];
//grid->pos = pos;
MeshObject* obj = FACTORY_CREATE(m_Scene, MeshObject);
obj->SetMesh(m_MeshBox);
obj->SetPosition(p);
obj->SetMaterial(m_BoxMaterial, 0);
//obj->CreateLightableObject();
grid->obj = obj;
}
}