Updated lots of things
This commit is contained in:
10
src/tests/CMakeLists.txt
Normal file
10
src/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
project(tests)
|
||||
find_package(pugixml CONFIG)
|
||||
find_package(assimp REQUIRED CONFIG)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
|
||||
add_executable(check_uv check_uv.cpp)
|
||||
target_link_libraries(check_uv ${ASSIMP_LIBRARIES})
|
||||
add_executable(ogre_check_uv ogre_check_uv.cpp)
|
||||
target_link_libraries(ogre_check_uv OgreBites OgreMain)
|
||||
|
||||
54
src/tests/check_uv.cpp
Normal file
54
src/tests/check_uv.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <assimp/version.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
Assimp::Importer importer;
|
||||
uint32_t flags = aiProcessPreset_TargetRealtime_Fast | aiProcess_TransformUVCoords | aiProcess_FlipUVs;
|
||||
flags &= ~(aiProcess_JoinIdenticalVertices | aiProcess_CalcTangentSpace); // optimize for fast loading
|
||||
if((flags & (aiProcess_GenSmoothNormals | aiProcess_GenNormals)) != aiProcess_GenNormals)
|
||||
flags &= ~aiProcess_GenNormals; // prefer smooth normals
|
||||
|
||||
float maxEdgeAngle = 0.75f;
|
||||
|
||||
importer.SetPropertyFloat("PP_GSN_MAX_SMOOTHING_ANGLE", maxEdgeAngle);
|
||||
importer.SetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, true);
|
||||
|
||||
if (argc < 2) {
|
||||
std::cerr << "path name needed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
const char *pname = argv[1];
|
||||
const aiScene* scene = importer.ReadFile(pname,
|
||||
flags);
|
||||
std::list<aiNode *> queue;
|
||||
if (!scene) {
|
||||
std::cerr << "could not process file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
queue.push_back(scene->mRootNode);
|
||||
while(!queue.empty()) {
|
||||
aiNode *node = queue.front();
|
||||
queue.pop_front();
|
||||
for (i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
int uv_count = 0;
|
||||
for (int uvindex = 0; uvindex < AI_MAX_NUMBER_OF_TEXTURECOORDS; uvindex++) {
|
||||
aiVector3D* uv = mesh->mTextureCoords[uvindex];
|
||||
if (!uv)
|
||||
break;
|
||||
uv_count++;
|
||||
}
|
||||
std::cout << "node: " << node->mName.C_Str() << " mesh: " << i << " mesh uv count: " << uv_count << std::endl;
|
||||
}
|
||||
for (i = 0; i < node->mNumChildren; i++)
|
||||
queue.push_back(node->mChildren[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
83
src/tests/ogre_check_uv.cpp
Normal file
83
src/tests/ogre_check_uv.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <iostream>
|
||||
#include <Ogre.h>
|
||||
#include <OgreCodec.h>
|
||||
#include <OgreFileSystem.h>
|
||||
#include <OgreFileSystemLayer.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
#include <OgreShaderGenerator.h>
|
||||
|
||||
static void getSubmeshUVs(const Ogre::Mesh *mesh, const Ogre::SubMesh *submesh,
|
||||
std::vector<Ogre::Vector2> &uvs, int index)
|
||||
{
|
||||
int j;
|
||||
float *pReal;
|
||||
Ogre::HardwareVertexBufferSharedPtr vbuf;
|
||||
Ogre::VertexData *vertex_data = submesh->useSharedVertices ?
|
||||
mesh->sharedVertexData :
|
||||
submesh->vertexData;
|
||||
const Ogre::VertexElement *uvElem =
|
||||
vertex_data->vertexDeclaration->findElementBySemantic(
|
||||
Ogre::VES_TEXTURE_COORDINATES, index);
|
||||
int vertex_count = 0;
|
||||
if (submesh->useSharedVertices)
|
||||
vertex_count += mesh->sharedVertexData->vertexCount;
|
||||
else
|
||||
vertex_count += submesh->vertexData->vertexCount;
|
||||
if (!uvElem)
|
||||
return;
|
||||
OgreAssert(uvs.size() == 0 || uvs.size() == vertex_count,
|
||||
"bad vertex count");
|
||||
uvs.resize(vertex_count);
|
||||
vbuf = vertex_data->vertexBufferBinding->getBuffer(uvElem->getSource());
|
||||
unsigned char *uv = static_cast<unsigned char *>(
|
||||
vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
|
||||
for (j = 0; j < vertex_data->vertexCount; ++j) {
|
||||
uvElem->baseVertexPointerToElement(uv, &pReal);
|
||||
uvs[j] = Ogre::Vector2(pReal[0], pReal[1]);
|
||||
uv += vbuf->getVertexSize();
|
||||
}
|
||||
vbuf->unlock();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Ogre::LogManager logMgr;
|
||||
logMgr.createLog("messages.log", true, true, true);
|
||||
Ogre::DefaultHardwareBufferManager bufferManager; // needed because we don't have a rendersystem
|
||||
Ogre::Root *ogre = new Ogre::Root("", "", "");
|
||||
Ogre::ConfigFile pluginsCfg;
|
||||
Ogre::FileSystemLayer fsLayer("Ogre3D");
|
||||
pluginsCfg.load(fsLayer.getConfigFilePath("plugins.cfg"));
|
||||
|
||||
auto pluginDir = Ogre::FileSystemLayer::resolveBundlePath(pluginsCfg.getSetting("PluginFolder")+"/");
|
||||
ogre->loadPlugin(pluginDir + "/Codec_Assimp");
|
||||
Ogre::MaterialManager::getSingleton().initialise();
|
||||
Ogre::RTShader::ShaderGenerator::initialize();
|
||||
Ogre::DefaultTextureManager texMgr;
|
||||
|
||||
auto& shadergen = Ogre::RTShader::ShaderGenerator::getSingleton();
|
||||
shadergen.setTargetLanguage("glsl"); // must be valid, but otherwise arbitrary
|
||||
shadergen.getRenderState(Ogre::MSN_SHADERGEN)->setLightCountAutoUpdate(false);
|
||||
shadergen.validateScheme(Ogre::MSN_SHADERGEN);
|
||||
|
||||
auto codec = Ogre::Codec::getCodec("glb");
|
||||
|
||||
Ogre::ResourceGroupManager::getSingleton().createResourceGroup(
|
||||
"Characters", true);
|
||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
|
||||
"characters", "FileSystem", "Characters", true, true);
|
||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
|
||||
"../characters", "FileSystem", "Characters", true, true);
|
||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
|
||||
"../../characters", "FileSystem", "Characters", true, true);
|
||||
Ogre::DataStreamPtr meshData = Ogre::ResourceGroupManager::getSingleton().openResource("shapes/male/edited-normal-male-base.glb", "Characters");
|
||||
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual("shapes/male/edited-normal-male-base.glb", "Characters");
|
||||
codec->decode(meshData, mesh.get());
|
||||
std::vector<Ogre::Vector2> uvs;
|
||||
getSubmeshUVs(mesh.get(), mesh->getSubMesh(0), uvs, 0);
|
||||
std::cout << "UV0: " << uvs.size() << std::endl;
|
||||
uvs.clear();
|
||||
getSubmeshUVs(mesh.get(), mesh->getSubMesh(0), uvs, 1);
|
||||
std::cout << "UV1: " << uvs.size() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user