Skip to content

Commit 03a5df6

Browse files
committed
README.md 수정 및 추가, ImportScene-ObjectWithFBX 동기화
1 parent 4d82637 commit 03a5df6

File tree

11 files changed

+77
-106
lines changed

11 files changed

+77
-106
lines changed

DX11ObjectWithFBX/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# DX11ObjectWithFBX
2+
3+
이 예제에서는 두가지 내용을 포함한다.
4+
5+
- FBX를 읽어오는 코드를 사용하여 버텍스 버퍼(위치, 노말, UV), 인덱스 버퍼를 생성 및 복사.(자세한 내용은 ImportScene 참조)
6+
- 구조화된 리소스 불러오기 및 구조화된 파이프라인 리소스 바인딩

DX11Tutorial2/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DX11Tutorial2
2+
3+
DirectX11에서 삼각형 폴리곤 '단하나' 렌더링시에 필요한 코드. 디바이스, 디바이스 컨텍스트, DXGI 기본 세팅이 있다.
4+

DX11Tutorial4/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# DX11Tutorial4
2+
3+
Tutorial2 에서는 버텍스 버퍼만으로 렌더링 했다면, Tutorial4에서는 인덱스 버퍼와 함께 렌더링 한다. 또한 쉐이어에서 콘스탄트 버퍼를 통하여 렌더링 하는 내용을 포함한다.

DX11Tutorial5/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# DX11Tutorial5
2+
3+
하나의 물체를 더 생성하여 렌더링 하고, 렌더링 순서와 상관없이 거리에 따른 ealry-z out 을 사용하기 위해 depth-stencil buffer 를 생성하여 렌더링 파이프라인에서 사용한다.

DX11Tutorial6/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# DX11Tutorial6
2+
3+
constant buffer 를 세분화 하여 필요한 경우에만 업데이트 하도록 한다.

DX11Tutorial7/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# DX11Tutorial7
2+
3+
쉐이더에서 텍스쳐를 렌더링 하기 위해, DirectXTex 라이브러리를 외부에서 불러오고, 여기서 제공하는 헬퍼함수를 사용하여 Shader Resource View를 생성한다. Texture2D 객체는 내부에서만 생성하는 것인듯. 또한 샘플러를 만들고, SRV, 샘플러를 렌더 파이프라인에 사용한다고 통지하여 텍스쳐를 참조하여 쉐이더에서 렌더링한다.

ImportScene/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# FBX Example : ImportScene from FBX
1+
# ImportScene
22

3-
- read geometry, skeleton, animation
4-
- geometry : position, normal, tangent, binormal
5-
- (WIP)skeleton : connected hierarchy
6-
- (WIP)animation : skeleton transformations
7-
- (WIP)topology is limited : only support triangle, quadrilateral polygon(quadrilateral is divided as triangle)
3+
기존의 FBXSDK 에서 지원하는 ImportScene 예제를 참조하여 directX11에 맞도록 데이터를 다시 가공한다. 특이점은 FBXSDK에서 제공하는 Triangulate 를 사용하여 모든 메쉬의 프리미티브를 전부 삼각형으로 바꾼다.
84

5+
- 정점 당 데이터 : 위치, 노말, 탄젠트, 바이노말, UV(여러개)
6+
- 정점 인덱스
7+
- (스켈레톤) : hierarchy 와 연동
8+
- (애니메이션) : 스켈레톤과 연결

ImportScene/fbximport.cpp

+30-87
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ bool BlendShapeToChunk(FbxScene* fbxScene, FBXChunk& chunk, const Allocaters* al
180180
bool SceneToChunk(FbxScene* fbxScene, FBXChunk& chunk, const FBXLoadOptionChunk* opt, const Allocaters* allocs)
181181
{
182182
chunk.allocs = allocs;
183-
//FbxGeometryConverter* conv = new FbxGeometryConverter(g_FbxManager);
184-
//conv->Triangulate(fbxScene, true);
183+
FbxGeometryConverter* conv = new FbxGeometryConverter(g_FbxManager);
184+
conv->Triangulate(fbxScene, true);
185185

186186
TraversalFBXNode(fbxScene->GetRootNode(), chunk, opt, allocs);
187187
SkeletonToChunk(fbxScene, chunk, allocs);
188188
BlendShapeToChunk(fbxScene, chunk, allocs);
189189

190-
//delete conv;
190+
delete conv;
191191

192192
return true;
193193
}
@@ -206,10 +206,8 @@ uint TraversalFBXNode(FbxNode* node, FBXChunk& chunk, const FBXLoadOptionChunk*
206206
switch (type)
207207
{
208208
case FbxNodeAttribute::EType::eMesh:
209-
{
210209
if (MeshToChunk(node->GetNameOnly(), node->GetMesh(), chunk, opt, allocs))
211210
count++;
212-
}
213211
break;
214212
case FbxNodeAttribute::EType::eSkeleton:
215213
if (SkeletonToChunk(node, chunk, allocs))
@@ -241,12 +239,13 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
241239

242240
// controlpoint to vertex
243241
FbxVector4* fbxVertices = fbxMesh->GetControlPoints();
244-
mesh.geometry.vertices = (Vector3f*)allocs->alloc(sizeof(Vector3f) * mesh.geometry.vertexCount);
242+
mesh.geometry.vertices = (Vector4f*)allocs->alloc(sizeof(Vector4f) * mesh.geometry.vertexCount);
245243
for (uint i = 0; i < mesh.geometry.vertexCount; i++)
246244
{
247245
mesh.geometry.vertices[i].x = static_cast<float>(fbxVertices[i].mData[0]);
248246
mesh.geometry.vertices[i].y = static_cast<float>(fbxVertices[i].mData[1]);
249247
mesh.geometry.vertices[i].z = static_cast<float>(fbxVertices[i].mData[2]);
248+
mesh.geometry.vertices[i].w = 1.f;
250249
}
251250

252251
// non-unifoirm polygon to uniform triangle
@@ -261,95 +260,23 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
261260
polygonSize = fbxMesh->GetPolygonSize(i);
262261

263262
FALSE_ERROR_MESSAGE_ARGS_RETURN_CODE(
264-
polygonSize == 3 || polygonSize == 4,
265-
L"fail to divide polygon(%d), because avaiable polygonsize is 3 or 4",
263+
polygonSize == 3,
264+
L"fail to divide polygon(%d), because only avaiable polygonsize is 3..",
266265
false,
267266
polygonSize
268267
);
269268

270-
indexCount = (polygonSize - 2) * 3;
271-
if (indexCount + lastTriangleIndex >= triangles.size())
272-
triangles.reserve(triangles.size() * 2);
273-
274-
if (polygonSize == 4)
269+
if (!opt->flipface)
275270
{
276-
bool zOrderQuad = false;
277-
int idxs[4] = {
278-
fbxMesh->GetPolygonVertex(i, 0), fbxMesh->GetPolygonVertex(i, 1),
279-
fbxMesh->GetPolygonVertex(i, 2), fbxMesh->GetPolygonVertex(i, 3)
280-
};
281-
Vector3f
282-
v0 = (mesh.geometry.vertices[idxs[1]] - mesh.geometry.vertices[idxs[0]]).normalized(),
283-
v1 = (mesh.geometry.vertices[idxs[3]] - mesh.geometry.vertices[idxs[2]]).normalized();
284-
if (1.f - abs(Dot(v0, v1)) > EPSILON)
285-
zOrderQuad = true;
286-
287-
v0 = (mesh.geometry.vertices[idxs[2]] - mesh.geometry.vertices[idxs[1]]).normalized();
288-
v1 = (mesh.geometry.vertices[idxs[0]] - mesh.geometry.vertices[idxs[3]]).normalized();
289-
if (1.f - abs(Dot(v0, v1)) > EPSILON)
290-
zOrderQuad = true;
291-
292-
if (!zOrderQuad)
293-
{
294-
if (!opt->flipface)
295-
{
296-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
297-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
298-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
299-
300-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
301-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
302-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 3));
303-
}
304-
else
305-
{
306-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
307-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
308-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
309-
310-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
311-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 3));
312-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
313-
}
314-
}
315-
else
316-
{
317-
if (!opt->flipface)
318-
{
319-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
320-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
321-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
322-
323-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
324-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 3));
325-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
326-
}
327-
else
328-
{
329-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
330-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
331-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
332-
333-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
334-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
335-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 3));
336-
}
337-
}
271+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
272+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
273+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
338274
}
339275
else
340276
{
341-
if (!opt->flipface)
342-
{
343-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
344-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
345-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
346-
}
347-
else
348-
{
349-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
350-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
351-
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
352-
}
277+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 0));
278+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 2));
279+
triangles.push_back(fbxMesh->GetPolygonVertex(i, 1));
353280
}
354281
}
355282

@@ -559,8 +486,14 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
559486
for (int itemIndex = 0; itemIndex < fbxMesh->GetPolygonSize(polyIndex); itemIndex++)
560487
{
561488
int controlPointIndex = fbxMesh->GetPolygonVertex(polyIndex, itemIndex);
489+
562490
uvs[controlPointIndex].x = static_cast<float>(fbxUV->GetDirectArray()[controlPointIndex].mData[0]);
563491
uvs[controlPointIndex].y = static_cast<float>(fbxUV->GetDirectArray()[controlPointIndex].mData[1]);
492+
493+
if (opt->flipU)
494+
uvs[controlPointIndex].x = 1.f - uvs[controlPointIndex].x;
495+
if (opt->flipV)
496+
uvs[controlPointIndex].y = 1.f - uvs[controlPointIndex].y;
564497
}
565498
}
566499
}
@@ -574,6 +507,11 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
574507
int uvIndex = fbxUV->GetIndexArray()[controlPointIndex];
575508
uvs[controlPointIndex].x = static_cast<float>(fbxUV->GetDirectArray()[uvIndex].mData[0]);
576509
uvs[controlPointIndex].y = static_cast<float>(fbxUV->GetDirectArray()[uvIndex].mData[1]);
510+
511+
if (opt->flipU)
512+
uvs[controlPointIndex].x = 1.f - uvs[controlPointIndex].x;
513+
if (opt->flipV)
514+
uvs[controlPointIndex].y = 1.f - uvs[controlPointIndex].y;
577515
}
578516
}
579517
}
@@ -593,6 +531,11 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
593531
int textureUVIndex = fbxMesh->GetTextureUVIndex(polyIndex, itemIndex);
594532
uvs[controlPointIndex].x = static_cast<float>(fbxUV->GetDirectArray()[textureUVIndex].mData[0]);
595533
uvs[controlPointIndex].y = static_cast<float>(fbxUV->GetDirectArray()[textureUVIndex].mData[1]);
534+
535+
if (opt->flipU)
536+
uvs[controlPointIndex].x = 1.f - uvs[controlPointIndex].x;
537+
if (opt->flipV)
538+
uvs[controlPointIndex].y = 1.f - uvs[controlPointIndex].y;
596539
}
597540
}
598541
}

ImportScene/fbximport.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ struct FBXLoadOptionChunk
1010
struct
1111
{
1212
uint flipface : 1;
13+
uint flipU : 1;
14+
uint flipV : 1;
1315
uint fillVertexNomral : 1;
1416
uint fillVertexTangent : 1;
1517
uint fillVertexBinormal : 1;
16-
uint padding : 4;
18+
uint padding : 2;
1719
};
1820
byte flags;
1921
};
@@ -38,7 +40,7 @@ struct FBXMeshChunk
3840
struct FBXGeometryChunk
3941
{
4042
uint vertexCount;
41-
Vector3f* vertices;
43+
Vector4f* vertices;
4244
Vector3f* normals;
4345
Vector3f* tangents;
4446
Vector3f* binormals;

ImportScene/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ void PrintFBXChunk(FILE* fp, FBXChunk* chunk)
1111
fprintf(fp, "meshname:%s, vertexcount:%d, indexcount:%d\n", m.name, m.geometry.vertexCount, m.geometry.indexCount);
1212

1313
uint j, k;
14+
Vector4f* v4;
1415
Vector3f* v3;
1516
Vector2f* v2;
1617
for (j = 0; j < m.geometry.indexCount; j++)
1718
fprintf(fp, "idx%d: %d\n", j, m.geometry.indices[j]);
1819

19-
for (j = 0; j < m.geometry.vertexCount && (v3 = m.geometry.vertices + j); j++)
20-
fprintf(fp, "pos%d: (%.2f, %.2f, %.2f)\n", j, v3->x, v3->y, v3->z);
20+
for (j = 0; j < m.geometry.vertexCount && (v4 = m.geometry.vertices + j); j++)
21+
fprintf(fp, "pos%d: (%.2f, %.2f, %.2f)\n", j, v4->x, v4->y, v4->z);
2122
for (j = 0; j < m.geometry.vertexCount && (v3 = m.geometry.tangents + j); j++)
2223
fprintf(fp, "tan%d: (%.2f, %.2f, %.2f)\n", j, v3->x, v3->y, v3->z);
2324
for (j = 0; j < m.geometry.vertexCount && (v3 = m.geometry.normals + j); j++)

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# RenderFromScratch
22

3-
this repository contain rendering components & implementation.
3+
여러 리얼타임 렌더링 관련한 수제 코드들이 뭉쳐있습니다.
44

55
- ide: visual studio 2017
6-
- contents: dx11, fbx tutorials
6+
- 내용: dx11, fbx 관련 간단한 튜토리얼
77

8-
# directx11 tutorials
8+
# directx11 튜토리얼
99

10-
- Tutorial2 : render triangle
11-
- Tutorial4 : render indexed triangles + constant buffer
12-
- Tutorial5 : add 1 object, add depthstencil
13-
- Tutorial6 : add constant buffer
14-
- Tutorial7 : add texture, sampler, resize
10+
- Tutorial2 : 삼각형 단 하나를 위한 코드
11+
- Tutorial4 : 인덱스 버퍼 및 콘스탄트 버퍼를 활용
12+
- Tutorial5 : 여러 오브젝트 렌더링 시 가시성을 유효화하기 위한 뎁스-스텐실 버퍼 사용
13+
- Tutorial6 : 콘스탄트 버퍼를 모듈화 하여 필요한 경우에만 업데이트
14+
- Tutorial7 : 텍스쳐 사용 및 리사이즈 코드
15+
(위는 전부 DirectX11 마지막 SDK에 포함된 예제들)
16+
- ObjectWithFBX : FBX에서 추출한 정점/인덱스 데이터 렌더링
17+
- (SkinningWithFBX) : FBX에서 추출한 정점/인덱스/스켈레톤/애니메이션 렌더링
1518

1619
# fbx tutorials
17-
- import fbx
20+
- ImportScene : 지오메트리 (, 스켈레톤, 애니메이션) 추출

0 commit comments

Comments
 (0)