本文整理汇总了C++中MeshInstance类的典型用法代码示例。如果您正苦于以下问题:C++ MeshInstance类的具体用法?C++ MeshInstance怎么用?C++ MeshInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MeshInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _find_meshes
void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
MeshInstance *mi = p_at_node->cast_to<MeshInstance>();
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) {
Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Rect3 aabb = mesh->get_aabb();
Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
if (Rect3(-extents,extents*2).intersects(xf.xform(aabb))) {
Baker::PlotMesh pm;
pm.local_xform=xf;
pm.mesh=mesh;
p_baker->mesh_list.push_back(pm);
}
}
}
for(int i=0;i<p_at_node->get_child_count();i++) {
Node *child = p_at_node->get_child(i);
if (!child->get_owner())
continue; //maybe a helper
_find_meshes(child,p_baker);
}
}
示例2: _parse_obj
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
List<Ref<Mesh> > meshes;
Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps);
if (err != OK) {
if (r_err) {
*r_err = err;
}
return NULL;
}
Spatial *scene = memnew(Spatial);
for (List<Ref<Mesh> >::Element *E = meshes.front(); E; E = E->next()) {
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(E->get());
mi->set_name(E->get()->get_name());
scene->add_child(mi);
mi->set_owner(scene);
}
if (r_err) {
*r_err = OK;
}
return scene;
}
示例3: memnew
void MeshInstanceEditor::_create_outline_mesh() {
Ref<Mesh> mesh = node->get_mesh();
if (mesh.is_null()) {
err_dialog->set_text(TTR("MeshInstance lacks a Mesh!"));
err_dialog->popup_centered_minsize();
return;
}
Ref<Mesh> mesho = mesh->create_outline(outline_size->get_val());
if (mesho.is_null()) {
err_dialog->set_text(TTR("Could not create outline!"));
err_dialog->popup_centered_minsize();
return;
}
MeshInstance *mi = memnew( MeshInstance );
mi->set_mesh(mesho);
Node *owner=node->get_owner();
if (get_tree()->get_edited_scene_root()==node) {
owner=node;
}
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
ur->create_action(TTR("Create Outline"));
ur->add_do_method(node,"add_child",mi);
ur->add_do_method(mi,"set_owner",owner);
ur->add_do_reference(mi);
ur->add_undo_method(node,"remove_child",mi);
ur->commit_action();
}
示例4: switch
void NavigationMeshInstance::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Spatial *c = this;
while (c) {
navigation = c->cast_to<Navigation>();
if (navigation) {
if (enabled && navmesh.is_valid()) {
nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
break;
}
c = c->get_parent_spatial();
}
if (navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) {
MeshInstance *dm = memnew(MeshInstance);
dm->set_mesh(navmesh->get_debug_mesh());
if (is_enabled()) {
dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
add_child(dm);
debug_view = dm;
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (navigation && nav_id != -1) {
navigation->navmesh_set_transform(nav_id, get_relative_transform(navigation));
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (navigation) {
if (nav_id != -1) {
navigation->navmesh_remove(nav_id);
nav_id = -1;
}
}
if (debug_view) {
debug_view->queue_delete();
debug_view = NULL;
}
navigation = NULL;
} break;
}
}
示例5: getSceneStats
////////////////////////////////////////////////////////////////////////////////
// SoftShadowsRenderer::getSceneStats()
////////////////////////////////////////////////////////////////////////////////
void SoftShadowsRenderer::getSceneStats(uint64_t &numIndices, uint64_t &numVertices, uint32_t &lightResolution) const
{
numIndices = 0;
numVertices = 0;
lightResolution = LIGHT_RES;
for (MeshInstanceList::const_iterator it = m_meshInstances.begin(); it != m_meshInstances.end(); ++it)
{
MeshInstance *instance = *it;
instance->accumStats(numIndices, numVertices);
}
}
示例6: drawMeshes
////////////////////////////////////////////////////////////////////////////////
// SoftShadowsRenderer::drawMeshes()
////////////////////////////////////////////////////////////////////////////////
void SoftShadowsRenderer::drawMeshes(SceneShader &shader)
{
shader.setUseDiffuse(true);
for (MeshInstanceList::iterator it = m_meshInstances.begin(); it != m_meshInstances.end(); ++it)
{
MeshInstance *instance = *it;
if (instance == m_podiumMesh)
shader.setUseTexture(m_useTexture ? 2 : 0);
else
shader.setUseTexture(0);
instance->draw(shader);
}
}
示例7: hMeshInstance
void ClientGameObjectManagerAddon::createSpaceShip(int &threadOwnershipMask)
{
//create hierarchy:
//scene root
// scene node // tracks position/orientation
// SpaceShip
//game object manager
// SpaceShipController
// scene node
PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);
pMeshInstance->addDefaultComponents();
pMeshInstance->initFromFile("space_frigate_6.mesha", "FregateTest", threadOwnershipMask);
// need to create a scene node for this mesh
PE::Handle hSN("SCENE_NODE", sizeof(SceneNode));
SceneNode *pSN = new(hSN) SceneNode(*m_pContext, m_arena, hSN);
pSN->addDefaultComponents();
Vector3 spawnPos(0, 0, 0.0f);
pSN->m_base.setPos(spawnPos);
pSN->addComponent(hMeshInstance);
RootSceneNode::Instance()->addComponent(hSN);
// now add game objects
PE::Handle hSpaceShip("ClientSpaceShip", sizeof(ClientSpaceShip));
ClientSpaceShip *pSpaceShip = new(hSpaceShip) ClientSpaceShip(*m_pContext, m_arena, hSpaceShip, 0.05f, spawnPos, 0.05f);
pSpaceShip->addDefaultComponents();
addComponent(hSpaceShip);
// add the same scene node to tank controller
static int alllowedEventsToPropagate[] = {0}; // we will pass empty array as allowed events to propagate so that when we add
// scene node to the square controller, the square controller doesnt try to handle scene node's events
// because scene node handles events through scene graph, and is child of space ship just for referencing purposes
pSpaceShip->addComponent(hSN, &alllowedEventsToPropagate[0]);
pSpaceShip->activate();
}
示例8: get_shape
void CollisionShape::_update_debug_shape() {
debug_shape_dirty = false;
if (debug_shape) {
debug_shape->queue_delete();
debug_shape = NULL;
}
Ref<Shape> s = get_shape();
if (s.is_null())
return;
Ref<Mesh> mesh = s->get_debug_mesh();
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(mesh);
add_child(mi);
debug_shape = mi;
}
示例9: get_parent
void CollisionShape::make_convex_from_brothers() {
Node *p = get_parent();
if (!p)
return;
for (int i = 0; i < p->get_child_count(); i++) {
Node *n = p->get_child(i);
MeshInstance *mi = Object::cast_to<MeshInstance>(n);
if (mi) {
Ref<Mesh> m = mi->get_mesh();
if (m.is_valid()) {
Ref<Shape> s = m->create_convex_shape();
set_shape(s);
}
}
}
}
示例10: switch
void HRMEMainWindow::setSelectedObject(MapObject* selected_object) {
positionPropertyFrame->setEnabled(false);
rotationPropertyFrame->setEnabled(false);
scalePropertyFrame->setEnabled(false);
colorPropertyFrame->setEnabled(false);
attenuationPropertyFrame->setEnabled(false);
meshInstancePropertyFrame->setEnabled(false);
Light* light;
MeshInstance* instance;
if (selected_object) {
switch (selected_object->getType()) {
case MapObject::LIGHT:
light = ((LightObject*)selected_object)->getLight();
lightStrengthBox->setValue(light->getStrength());
lightAttenuationBox->setChecked(light->getHasAttenuation());
attenuationPropertyFrame->setEnabled(true);
break;
case MapObject::MESH_INSTANCE:
instance = ((MeshInstanceObject*)selected_object)->getMeshInstance();
meshInstancePropertyFrame->setEnabled(true);
instanceTypeBox->setCurrentIndex(static_cast<int>(instance->getType()));
;break;
default:
break;
}
positionPropertyFrame->setEnabled(true);
colorPropertyFrame->setEnabled(selected_object->hasColors());
rotationPropertyFrame->setEnabled(selected_object->hasRotation());
scalePropertyFrame->setEnabled(selected_object->hasScale());
}
for (int i = 0; i < objectPropertyWidgets.size(); i++) {
objectPropertyWidgets.at(i)->setVisible(objectPropertyWidgets.at(i)->parentWidget()->isEnabled());
}
}
示例11: get_relative_transform
void NavigationMeshInstance::set_enabled(bool p_enabled) {
if (enabled == p_enabled)
return;
enabled = p_enabled;
if (!is_inside_tree())
return;
if (!enabled) {
if (nav_id != -1) {
navigation->navmesh_remove(nav_id);
nav_id = -1;
}
} else {
if (navigation) {
if (navmesh.is_valid()) {
nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
}
}
if (debug_view) {
MeshInstance *dm = debug_view->cast_to<MeshInstance>();
if (is_enabled()) {
dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
}
update_gizmo();
}
示例12: get_mesh
void MeshInstance::create_debug_tangents() {
Vector<Vector3> lines;
Vector<Color> colors;
Ref<Mesh> mesh = get_mesh();
if (!mesh.is_valid())
return;
for (int i = 0; i < mesh->get_surface_count(); i++) {
Array arrays = mesh->surface_get_arrays(i);
Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
if (norms.size() == 0)
continue;
Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
if (tangents.size() == 0)
continue;
for (int j = 0; j < verts.size(); j++) {
Vector3 v = verts[j];
Vector3 n = norms[j];
Vector3 t = Vector3(tangents[j * 4 + 0], tangents[j * 4 + 1], tangents[j * 4 + 2]);
Vector3 b = (n.cross(t)).normalized() * tangents[j * 4 + 3];
lines.push_back(v); //normal
colors.push_back(Color(0, 0, 1)); //color
lines.push_back(v + n * 0.04); //normal
colors.push_back(Color(0, 0, 1)); //color
lines.push_back(v); //tangent
colors.push_back(Color(1, 0, 0)); //color
lines.push_back(v + t * 0.04); //tangent
colors.push_back(Color(1, 0, 0)); //color
lines.push_back(v); //binormal
colors.push_back(Color(0, 1, 0)); //color
lines.push_back(v + b * 0.04); //binormal
colors.push_back(Color(0, 1, 0)); //color
}
}
if (lines.size()) {
Ref<SpatialMaterial> sm;
sm.instance();
sm->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
sm->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
sm->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
Ref<ArrayMesh> am;
am.instance();
Array a;
a.resize(Mesh::ARRAY_MAX);
a[Mesh::ARRAY_VERTEX] = lines;
a[Mesh::ARRAY_COLOR] = colors;
am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
am->surface_set_material(0, sm);
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(am);
mi->set_name("DebugTangents");
add_child(mi);
#ifdef TOOLS_ENABLED
if (this == get_tree()->get_edited_scene_root())
mi->set_owner(this);
else
mi->set_owner(get_owner());
#endif
}
}
示例13: Component
Flyer::Flyer(PE::GameContext &context, PE::MemoryArena arena, PE::Handle hMyself, int &threadOwnershipMask)
: Component(context, arena, hMyself)
, m_prevCameraType(CameraManager::CameraType_Count)
{
// NUI testing
#ifdef _XBOX
// Could also try for a bit more smoothing ( 0.25f, 0.25f, 0.25f, 0.03f, 0.05f );
m_JointFilter.Init( 0.5f, 0.5f, 0.5f, 0.05f, 0.05f );
// create event which will be signaled when frame processing ends
m_hFrameEndEvent = CreateEvent( NULL,
FALSE, // auto-reset
FALSE, // create unsignaled
"NuiFrameEndEvent" );
if ( !m_hFrameEndEvent )
{
ATG_PrintError( "Failed to create NuiFrameEndEvent\n" );
return;
// return E_FAIL;
}
HRESULT hr = NuiInitialize( NUI_INITIALIZE_FLAG_USES_SKELETON |
NUI_INITIALIZE_FLAG_USES_COLOR |
NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX,
NUI_INITIALIZE_DEFAULT_HARDWARE_THREAD );
if( FAILED( hr ))
{
ATG::NuiPrintError( hr, "NuiInitialize" );
return;
// return E_FAIL;
}
// register frame end event with NUI
hr = NuiSetFrameEndEvent( m_hFrameEndEvent, 0 );
if( FAILED(hr) )
{
ATG::NuiPrintError( hr, "NuiSetFrameEndEvent" );
return;
// return E_FAIL;
}
/*
// Open the color stream
hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 1, NULL, &m_hImage );
if( FAILED (hr) )
{
ATG::NuiPrintError( hr, "NuiImageStreamOpen" );
return E_FAIL;
}
// Open the depth stream
hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, NUI_IMAGE_RESOLUTION_320x240, 0, 1, NULL, &m_hDepth );
if( FAILED (hr) )
{
ATG::NuiPrintError( hr, "NuiImageStreamOpen" );
return E_FAIL;
}
*/
hr = NuiSkeletonTrackingEnable( NULL, 0 );
if( FAILED( hr ))
{
ATG::NuiPrintError( hr, "NuiSkeletonTrackingEnable" );
}
m_pNuiJointConverterConstrained = new ATG::NuiJointConverter();
if( m_pNuiJointConverterConstrained == NULL )
{
// return E_FAIL;
return;
}
m_pNuiJointConverterConstrained->AddDefaultConstraints();
Handle hSN("SceneNode", sizeof(SceneNode));
m_pNuiSN = new(hSN) SceneNode(context, arena, hSN);
m_pNuiSN->addDefaultComponents();
m_pNuiSN->m_base.setPos(Vector3(0.0f, 0, 25.0f));
m_pNuiSN->m_base.turnRight(1.2f * 3.1415f);
RootSceneNode::Instance()->addComponent(hSN);
for (int i = 0; i < XAVATAR_MAX_SKELETON_JOINTS; i++)
{
PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);
pMeshInstance->addDefaultComponents();
pMeshInstance->initFromFile("box.x_main_mesh.mesha", "Default", threadOwnershipMask);
Handle hSN("SceneNode", sizeof(SceneNode));
m_sceneNodes[i] = new(hSN) SceneNode(context, arena, hSN);
m_sceneNodes[i]->addDefaultComponents();
m_sceneNodes[i]->addComponent(hMeshInstance);
m_pNuiSN->addComponent(hSN);
if (m_pNuiJointConverterConstrained->MapAvatarJointToNUI_POSITION_INDEX(i) == NUI_SKELETON_POSITION_SHOULDER_RIGHT)
{
PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);
pMeshInstance->addDefaultComponents();
//.........这里部分代码省略.........
示例14: _fix_node
Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map,uint32_t p_flags,Set<Ref<ImageTexture> >& image_map) {
// children first..
for(int i=0;i<p_node->get_child_count();i++) {
Node *r = _fix_node(p_node->get_child(i),p_root,collision_map,p_flags,image_map);
if (!r) {
print_line("was erased..");
i--; //was erased
}
}
String name = p_node->get_name();
bool isroot = p_node==p_root;
if (!isroot && p_flags&SCENE_FLAG_REMOVE_NOIMP && _teststr(name,"noimp")) {
memdelete(p_node);
return NULL;
}
{
List<PropertyInfo> pl;
p_node->get_property_list(&pl);
for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
if (E->get().type==Variant::OBJECT || E->get().type==Variant::ARRAY || E->get().type==Variant::DICTIONARY) {
_find_resources(p_node->get(E->get().name),image_map);
}
}
}
if (p_flags&SCENE_FLAG_CREATE_BILLBOARDS && p_node->cast_to<MeshInstance>()) {
MeshInstance *mi = p_node->cast_to<MeshInstance>();
bool bb=false;
if ((_teststr(name,"bb"))) {
bb=true;
} else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"bb"))) {
bb=true;
}
if (bb) {
mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true);
if (mi->get_mesh().is_valid()) {
Ref<Mesh> m = mi->get_mesh();
for(int i=0;i<m->get_surface_count();i++) {
Ref<FixedMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
fm->set_flag(Material::FLAG_UNSHADED,true);
fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
fm->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
}
}
}
}
}
if (p_flags&SCENE_FLAG_REMOVE_NOIMP && p_node->cast_to<AnimationPlayer>()) {
//remove animations referencing non-importable nodes
AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>();
List<StringName> anims;
ap->get_animation_list(&anims);
for(List<StringName>::Element *E=anims.front();E;E=E->next()) {
Ref<Animation> anim=ap->get_animation(E->get());
ERR_CONTINUE(anim.is_null());
for(int i=0;i<anim->get_track_count();i++) {
NodePath path = anim->track_get_path(i);
for(int j=0;j<path.get_name_count();j++) {
String node = path.get_name(j);
if (_teststr(node,"noimp")) {
anim->remove_track(i);
i--;
break;
}
}
}
}
}
if (p_flags&SCENE_FLAG_CREATE_IMPOSTORS && p_node->cast_to<MeshInstance>()) {
//.........这里部分代码省略.........
示例15: print_line
Error EditorSceneImporterFBXConv::_parse_nodes(State& state,const Array &p_nodes,Node* p_base) {
for(int i=0;i<p_nodes.size();i++) {
Dictionary n = p_nodes[i];
Spatial *node=NULL;
bool skip=false;
String id;
if (n.has("id")) {
id=_id(n["id"]);
}
print_line("ID: "+id);
if (state.skeletons.has(id)) {
Skeleton *skeleton = state.skeletons[id];
node=skeleton;
skeleton->localize_rests();
print_line("IS SKELETON! ");
} else if (state.bones.has(id)) {
if (p_base)
node=p_base->cast_to<Spatial>();
if (!state.bones[id].has_anim_chan) {
print_line("no has anim "+id);
}
skip=true;
} else if (n.has("parts")) {
//is a mesh
MeshInstance *mesh = memnew( MeshInstance );
node=mesh;
Array parts=n["parts"];
String long_identifier;
for(int j=0;j<parts.size();j++) {
Dictionary part=parts[j];
if (part.has("meshpartid")) {
String partid=part["meshpartid"];
long_identifier+=partid;
}
}
Ref<Mesh> m;
if (state.mesh_cache.has(long_identifier)) {
m=state.mesh_cache[long_identifier];
} else {
m = Ref<Mesh>( memnew( Mesh ) );
//and parts are surfaces
for(int j=0;j<parts.size();j++) {
Dictionary part=parts[j];
if (part.has("meshpartid")) {
_add_surface(state,m,part);
}
}
state.mesh_cache[long_identifier]=m;
}
mesh->set_mesh(m);
}
if (!skip) {
if (!node) {
node = memnew( Spatial );
}
node->set_name(id);
node->set_transform(_get_transform(n));
p_base->add_child(node);
node->set_owner(state.scene);
}
if (n.has("children")) {
Error err = _parse_nodes(state,n["children"],node);
if (err)
return err;
}
}
return OK;
}