Ejemplo n.º 1
0
        template <bool align> void DeinterleaveUv(const uint8_t * uv, size_t uvStride, size_t width, size_t height, 
            uint8_t * u, size_t uStride, uint8_t * v, size_t vStride)
        {
            assert(width >= A);
            if(align)
                assert(Aligned(uv) && Aligned(uvStride) && Aligned(u) && Aligned(uStride) && Aligned(v) && Aligned(vStride));

            size_t alignedWidth = AlignLo(width, A);
            for(size_t row = 0; row < height; ++row)
            {
                Loader<align> _uv(uv);
                Storer<align> _u(u), _v(v);
                DeinterleavedUv<align, true>(_uv, _u, _v);
                for(size_t col = A; col < alignedWidth; col += A)
                    DeinterleavedUv<align, false>(_uv, _u, _v);
                Flush(_u, _v);

                if(width != alignedWidth)
                {
                    Loader<false> _uv(uv + 2*(width - A));
                    Storer<false> _u(u + width - A), _v(v + width - A);
                    DeinterleavedUv<false, true>(_uv, _u, _v);
                    Flush(_u, _v);
                }

                uv += uvStride;
                u += uStride;
                v += vStride;
            }
        }
Ejemplo n.º 2
0
size_t assimp_load_meshes(const aiScene *scene, triangle_meshes_array& meshes)
{
	for (size_t i = 0; i < scene->mNumMeshes; ++i)
	{
		vertices_array verts; 
		face_indices_array faces; 
		normals_array normals;
		tangents_array tangents; 
		uvs_array uvs;

		size_t num_verts = scene->mMeshes[i]->mNumVertices;
		size_t num_faces = scene->mMeshes[i]->mNumFaces; 

		bool has_normals = scene->mMeshes[i]->HasNormals(); 
		bool has_tangents = scene->mMeshes[i]->HasTangentsAndBitangents(); 
		bool has_uvs = scene->mMeshes[i]->HasTextureCoords(0); 
		
		// Vertex Data
		for (size_t v = 0; v < scene->mMeshes[i]->mNumVertices; ++v)
		{
			point3f vert(scene->mMeshes[i]->mVertices[v].x, scene->mMeshes[i]->mVertices[v].y, scene->mMeshes[i]->mVertices[v].z);
			verts.push_back(vert);

			if (has_normals)
			{
				vector3f normal(scene->mMeshes[i]->mNormals[v].x, scene->mMeshes[i]->mNormals[v].y, scene->mMeshes[i]->mNormals[v].z);
				normals.push_back(normal); 
			}
			if (has_tangents)
			{
				vector3f tangent(scene->mMeshes[i]->mTangents[v].x, scene->mMeshes[i]->mTangents[v].y, scene->mMeshes[i]->mTangents[v].z);
				tangents.push_back(tangent); 
			}
			if (has_uvs)
			{
				uv _uv(scene->mMeshes[i]->mTextureCoords[0][v].x, scene->mMeshes[i]->mTextureCoords[0][v].y);
				uvs.push_back(_uv);
			}
		}
		
		// Triangle Face Data
		for (size_t f = 0; f < scene->mMeshes[i]->mNumFaces; ++f)
		{
			tri_indices face(scene->mMeshes[i]->mFaces[f].mIndices[0], scene->mMeshes[i]->mFaces[f].mIndices[1], scene->mMeshes[i]->mFaces[f].mIndices[2]);
			faces.push_back(face);
		} 
		
		triangle_mesh_ptr mesh = triangle_mesh_ptr(new c_triangle_mesh(verts, normals, tangents, uvs, faces));
		meshes.push_back(mesh);
	}

	return scene->mNumMeshes;
}