Beispiel #1
0
Ogre::SceneNode *EMDOgre::createOgreSceneNodeModel(EMDModel *model, Ogre::SceneNode *parent, Ogre::SceneManager *scene_manager) {
	Ogre::SceneNode *model_node = parent->createChildSceneNode();
	vector<EMDMesh *> &meshes = model->getMeshes();
	for (size_t i = 0; i < meshes.size(); i++) {
		vector<EMDSubmesh *> &submeshes = meshes[i]->getSubmeshes();
		if (!mesh_resources_created) {
			createOgreEntityMeshes(meshes[i]);
		}

		for (size_t j = 0; j < submeshes.size(); j++) {
			Ogre::Entity *entity = scene_manager->createEntity(meshes[i]->getName() + "_" + submeshes[j]->getMaterialName());
			entity->setMaterialName(name + "_" + submeshes[j]->getMaterialName());

			// Create Render Object Listeners depending on submesh definitions
			vector<EMDSubmeshDefinition> definitions = submeshes[j]->getDefinitions();

			EMBOgre *texture_pack = material_pack->getTexturePack();
			EMBOgre *texture_dyt_pack = material_pack->getDYTTexturePack();

			if (texture_pack && texture_dyt_pack) {
				vector<Ogre::TexturePtr> textures = texture_pack->getOgreTextures();
				vector<Ogre::TexturePtr> textures_dyt = texture_dyt_pack->getOgreTextures();

				for (size_t k = 0; k < definitions.size(); k++) {
					unsigned short texture_index = definitions[k].tex_index;
					unsigned short dyt_texture_index = definitions[k].tex_index;

					if (texture_index >= textures.size()) texture_index = textures.size()-1;
					if (dyt_texture_index >= textures_dyt.size()) dyt_texture_index = textures_dyt.size() - 1;

					EMDRenderObject *emd_render_object = new EMDRenderObject(textures[texture_index], textures_dyt[dyt_texture_index]);
					EMDRenderObjectAssignVisitor visitor(emd_render_object);
					entity->visitRenderables(&visitor);
					created_render_objects.push_back(emd_render_object);

					break; // FIXME: Figure out why there's multiple definitions
				}
			}

			// Share Skeleton Instances with ESK's fake entity
			if (skeleton) {
				if (entity->hasSkeleton()) {
					entity->shareSkeletonInstanceWith(skeleton->getEntity());
				}
			}

			model_node->attachObject(entity);
		}
	}
	return model_node;
}
Beispiel #2
0
Ogre::Entity *VLogicModel::_createEntity(const VString &meshName)
{
    Ogre::Entity *entity = VNULL;

    loadMesh(meshName, Ogre::StringUtil::BLANK, Ogre::StringUtil::BLANK, DEFAULT_RESOURCE_GROUP_NAME);

    VString entityName = mModelMainNode->getName() + "_Entity" + "_" + meshName +
                         Ogre::StringConverter::toString(mCreatedEntityCount++);

    VGraphicsSystem *system = VENGINE.getGfxSystem();
    entity = system->getSceneManager()->createEntity(entityName, meshName);

    mModelMainNode->attachObject(entity);

    if (!entity->getMesh()->getSkeleton().isNull())
    {
        if (VNULL == mSkeletonEntity)
        {
            const Ogre::MeshPtr &originMesh = entity->getMesh();
            assert(!originMesh.isNull());
            const Ogre::SkeletonPtr &originSke = originMesh->getSkeleton();
            assert(!originSke.isNull());

            _createSkeletonEntity(originSke);
        }

        assert(mSkeletonEntity);

        entity->shareSkeletonInstanceWith(mSkeletonEntity);
    }

// 	_convertEntityToCharacterMaterial(entity);

    if (mSkeletonEntity && !mSkeleton)
    {
        mSkeleton = mSkeletonEntity->getSkeleton();
        mSkeleton->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
    }

    entity->setCastShadows(mShadowCastable && !isShadowUncastable(meshName));

    return entity;
}