2015-02-01 1 views
0

Visual Studio 2010에있는 OpenGL 코드로 3D 오브젝트 메쉬를 가져와야합니다. 내가 OpenGL을에 relateively 새로운 그래서 난 다음 튜토리얼에서 학습 봤는데 해요 (번호 7) :OpenGL에 단순 메쉬를로드하는 데 문제가 있습니다

이제 http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/

이 자습서는 ".OBJ"파일을 가져올 라이브러리보다는 간단한 코드를 사용 자습서를 사용하는 사람들은 자습서의 작성자가 제공 한 "cube.obj"가 올바르게 작동한다는 것을 알게됩니다. 그러나 내 간단한 큐브 메쉬를로드하려고하면 "간단한 파서가 .obj 파일을 처리 할 수 ​​없습니다. 다른 옵션으로 내보내기를 시도하십시오."라는 메시지가 프로그램에 표시됩니다.

나는이 코드에 문제가 생각과 그의 Assimp 튜토리얼로 이동 : http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/

이번에, "Suzanne.obj는"샘플로 제공되고있다. 그러나 다시 한번, 코드에 내 자신의 개체를 내보낼 때마다 프로그램이 "Visual Studio가 작동을 멈췄다"라는 오류가 발생합니다. 이는 내가 반출 한 오브젝트에서만 발생합니다. 문제의 원인을 좁히려면 튜토리얼 7의 튜토리얼 7에 제공된 "cube.obj"를 사용했고 제대로 작동했습니다. 따라서 문제는 블렌더에서 개체를 내보내는 것과 같습니다.

개체를 내보내는 동안 어떤 옵션을 선택해야하는지에 관한 지침서 7의 모든 지침을 따랐습니다. 그러나 내보낼 개체의 ".obj"코드는 줄 바꿈없이 한 줄에 나타납니다. 다음과 같이

# Blender v2.73 (sub 0) OBJ File: 'ROOM.blend' 
# www.blender.org 
mtllib room.mtl 
o Cube_Cube.004 
v -1.000000 -1.000000 1.000000 
v -1.000000 -1.000000 -1.000000 
v 1.000000 -1.000000 -1.000000 
v 1.000000 -1.000000 1.000000 
v -1.000000 1.000000 1.000000 
v -1.000000 1.000000 -1.000000 
v 1.000000 1.000000 -1.000000 
v 1.000000 1.000000 1.000000 
vn -1.000000 0.000000 0.000000 
vn 0.000000 0.000000 -1.000000 
vn 1.000000 0.000000 0.000000 
vn 0.000000 0.000000 1.000000 
vn 0.000000 -1.000000 0.000000 
vn 0.000000 1.000000 0.000000 
usemtl None 
s off 
f 6//1 2//1 1//1 
f 7//2 3//2 2//2 
f 8//3 4//3 3//3 
f 5//4 1//4 4//4 
f 2//5 3//5 4//5 
f 7//6 6//6 5//6 
f 5//1 6//1 1//1 
f 6//2 7//2 2//2 
f 7//3 8//3 3//3 
f 8//4 5//4 4//4 
f 1//5 2//5 4//5 
f 8//6 7//6 5//6 

비교하여 튜토리얼에서 제공하는 큐브의 .OBJ 코드는 다음과 같습니다 : 이것은 내가 내 보낸 간단한 큐브 메쉬의 OBJ 코드

# Blender3D v249 OBJ File: untitled.blend 
# www.blender3d.org 
mtllib cube.mtl 
v 1.000000 -1.000000 -1.000000 
v 1.000000 -1.000000 1.000000 
v -1.000000 -1.000000 1.000000 
v -1.000000 -1.000000 -1.000000 
v 1.000000 1.000000 -1.000000 
v 0.999999 1.000000 1.000001 
v -1.000000 1.000000 1.000000 
v -1.000000 1.000000 -1.000000 
vt 0.748573 0.750412 
vt 0.749279 0.501284 
vt 0.999110 0.501077 
vt 0.999455 0.750380 
vt 0.250471 0.500702 
vt 0.249682 0.749677 
vt 0.001085 0.750380 
vt 0.001517 0.499994 
vt 0.499422 0.500239 
vt 0.500149 0.750166 
vt 0.748355 0.998230 
vt 0.500193 0.998728 
vt 0.498993 0.250415 
vt 0.748953 0.250920 
vn 0.000000 0.000000 -1.000000 
vn -1.000000 -0.000000 -0.000000 
vn -0.000000 -0.000000 1.000000 
vn -0.000001 0.000000 1.000000 
vn 1.000000 -0.000000 0.000000 
vn 1.000000 0.000000 0.000001 
vn 0.000000 1.000000 -0.000000 
vn -0.000000 -1.000000 0.000000 
usemtl Material_ray.png 
s off 
f 5/1/1 1/2/1 4/3/1 
f 5/1/1 4/3/1 8/4/1 
f 3/5/2 7/6/2 8/7/2 
f 3/5/2 8/7/2 4/8/2 
f 2/9/3 6/10/3 3/5/3 
f 6/10/4 7/6/4 3/5/4 
f 1/2/5 5/1/5 2/9/5 
f 5/1/6 6/10/6 2/9/6 
f 5/1/7 8/11/7 6/10/7 
f 8/11/7 7/12/7 6/10/7 
f 1/2/8 2/9/8 3/13/8 
f 1/2/8 3/13/8 4/14/8 

에 추락 한 프로그램을 디버깅하면 다음 예외가 발생합니다.

처리되지 않음 tutorial09_AssImp.exe에서 0x00007FF76255E2D5 예외 : 0xC0000005 : 0x0000000000000000 위치를 읽는 액세스 위반.

호출 스택은 다음과 같습니다!

tutorial09_AssImp.exe aiVector3t :: aiVector3t (const를 aiVector3t & O) 라인 67 C++ tutorial09_AssImp.exe loadAssImp (const를 문자 * 경로, 표준 : : 벡터> & 지수, 표준 : : 벡터, 표준 : : 할당

,

& vertices, std :: vector, std :: allocator & uvs, std :: vector, std :: allocator & 법선) Line 149 C++ tutorial09_AssImp.exe!주() (92) C++ 또한

는 예외로 그렇게 보이는 vector3.h에서 발생 분명히

/* 
--------------------------------------------------------------------------- 
Open Asset Import Library (assimp) 
--------------------------------------------------------------------------- 

Copyright (c) 2006-2012, assimp team 

All rights reserved. 

Redistribution and use of this software in source and binary forms, 
with or without modification, are permitted provided that the following 
conditions are met: 

* Redistributions of source code must retain the above 
    copyright notice, this list of conditions and the 
    following disclaimer. 

* Redistributions in binary form must reproduce the above 
    copyright notice, this list of conditions and the 
    following disclaimer in the documentation and/or other 
    materials provided with the distribution. 

* Neither the name of the assimp team, nor the names of its 
    contributors may be used to endorse or promote products 
    derived from this software without specific prior 
    written permission of the assimp team. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
--------------------------------------------------------------------------- 
*/ 
/** @file aiVector3D.h 
* @brief 3D vector structure, including operators when compiling in C++ 
*/ 
#ifndef AI_VECTOR3D_H_INC 
#define AI_VECTOR3D_H_INC 

#include <math.h> 


#include "./Compiler/pushpack1.h" 

#ifdef __cplusplus 

template<typename TReal> class aiMatrix3x3t; 
template<typename TReal> class aiMatrix4x4t; 

// --------------------------------------------------------------------------- 
/** Represents a three-dimensional vector. */ 
template <typename TReal> 
class aiVector3t 
{ 
public: 

    aiVector3t() : x(), y(), z() {} 
    aiVector3t (TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {} 
    explicit aiVector3t (TReal _xyz) : x(_xyz), y(_xyz), z(_xyz) {} 
    aiVector3t (const aiVector3t& o) : x(o.x), y(o.y), z(o.z) {} //exception generated here 

public: 

    // combined operators 
    const aiVector3t& operator += (const aiVector3t& o); 
    const aiVector3t& operator -= (const aiVector3t& o); 
    const aiVector3t& operator *= (TReal f); 
    const aiVector3t& operator /= (TReal f); 

    // transform vector by matrix 
    aiVector3t& operator *= (const aiMatrix3x3t<TReal>& mat); 
    aiVector3t& operator *= (const aiMatrix4x4t<TReal>& mat); 

    // access a single element 
    TReal operator[](unsigned int i) const; 
    TReal& operator[](unsigned int i); 

    // comparison 
    bool operator== (const aiVector3t& other) const; 
    bool operator!= (const aiVector3t& other) const; 

    template <typename TOther> 
    operator aiVector3t<TOther>() const; 

public: 

    /** @brief Set the components of a vector 
    * @param pX X component 
    * @param pY Y component 
    * @param pZ Z component */ 
    void Set(TReal pX, TReal pY, TReal pZ); 

    /** @brief Get the squared length of the vector 
    * @return Square length */ 
    TReal SquareLength() const; 


    /** @brief Get the length of the vector 
    * @return length */ 
    TReal Length() const; 


    /** @brief Normalize the vector */ 
    aiVector3t& Normalize(); 


    /** @brief Componentwise multiplication of two vectors 
    * 
    * Note that vec*vec yields the dot product. 
    * @param o Second factor */ 
    const aiVector3t SymMul(const aiVector3t& o); 

    TReal x, y, z; 
} PACK_STRUCT; 


typedef aiVector3t<float> aiVector3D; 

#else 

struct aiVector3D { 

    float x,y,z; 
} PACK_STRUCT; 

#endif // __cplusplus 

#include "./Compiler/poppack1.h" 

#ifdef __cplusplus 



#endif // __cplusplus 

#endif // AI_VECTOR3D_H_INC 

수출 권리 동안이 일을하고 있지 않다 내 모델. 내가 뭘 잘못 할 수 있니? 실종 된 단계가 있습니까?

답변

1

objloader.cpp의 149 번째 줄에서 프로그램이 중단됩니다 (호출 스택을 말합니다) 이 줄은 약 UV 좌표입니다. 모델에 아무 것도 표시되지 않습니다. =)

법선, btw와 동일한 문제가 있습니다.

  • 개체가의 UV 및 법선
  • 의 UV 또는 법선없이 로더 지원 메시를 확인이 있는지 확인하십시오 :

    그래서, 당신은 두 가지 옵션이 있습니다.

어쨌든 필요하기 때문에 첫 번째 것이 좋습니다.

블렌더에서

다음 UV를 들어

  • ('A'키) 모든 정점을 선택, 편집 모드로 이동 mesh-> UVs-> 자동 언랩을; 힘들다면 튜토리얼 15에는 필요한 모든 것을 보여주는 비디오가 포함되어 있습니다.
  • 법선의 경우 OBJ로 내보낼 때 "법선 내보내기"옵션을 선택하십시오. 의 이유는 위에 설명 : 어떤 경우에

는 출력 OBJ는 V (위치) VN (법선)

EDIT합니다 (V '의 사이에 연결 VT) (의 UV) 및 F 있어야 aiVector3Dt 대한 호출 스택 협상 : 라인 148

aiVector3D UVW = mesh->mTextureCoords[0][i]; 

UVW이 사본이다 mesh-> mTextureCoords [0] [i]를 메모리에서 유효한 위치를 가리 키지 않는, 버퍼는 '년후 때문에 귀하의 OBJ가 없기 때문에 할당되었습니다. 따라서이 메모리 블록을 UVW로 복사하려고하면 생성자 (호출 스택 : aiVector3Dt :: aiVector3Dt())가 충돌합니다. 충돌은 한 줄 나중에 발생하기 때문에 여기에는 약간의 차이점이 있지만 컴파일러 최적화에 불과합니다. 따라서 aiVector3D의 코드는 완벽하게 올바르지 만 그에게 나쁜 주소를 부여하고 있습니다. 현재 프레임을 loadAssImp()로 설정하고 mesh-> mTextureCoords [0]을 스파이로 설정하여 디버거에서이를 볼 수 있습니다.

관련 문제