Страница:
ComputeNormals
Страницы
AttributeSort
Clean
CompactVB
ComputeCullData
ComputeInputLayout
ComputeMeshlets
ComputeNormals
ComputeSubsets
ComputeTangentFrame
ComputeVertexCacheMissRate
ConcatenateMesh
ConvertPointRepsToAdjacency
DirectXMesh
FinalizeIB
FinalizeVB
FinalizeVBAndPointReps
FlexibleVertexFormat
FormatUtilities
GenerateAdjacencyAndPointReps
GenerateGSAdjacency
Geometry formats
Home
IsValid
Meshconvert
OptimizeFaces
OptimizeFacesLRU
OptimizeVertices
ReorderIB
ReorderIBAndAdjacency
Resources
Utilities
VBO
VBReader
VBWriter
Validate
WaveFrontReader
WeldVertices
10
ComputeNormals
Chuck Walbourn редактировал(а) эту страницу 2022-01-20 17:34:24 -08:00
Содержание
DirectXMesh |
---|
Generates vertex normals for a mesh.
HRESULT ComputeNormals(
const uint16_t* indices, size_t nFaces,
const XMFLOAT3* positions, size_t nVerts,
CNORM_FLAGS flags,
XMFLOAT3* normals );
HRESULT ComputeNormals(
const uint32_t* indices, size_t nFaces,
const XMFLOAT3* positions, size_t nVerts,
CNORM_FLAGS flags,
XMFLOAT3* normals );
Parameters
flags: A combination of control flags
CNORM_DEFAULT
is used to compute vertex normals by averaging of the face normals weighted by angle.CNORM_WEIGHT_BY_AREA
is used to compute vertex normals by averaging of the face normals weighted by triangle area.CNORM_WEIGHT_EQUAL
is used to compute vertex normals by average the face normals with equal weight.CNORM_WIND_CW
is used to indicate that the face winding order is clockwise, rather than the default of counter-clockwise winding. This impacts the direction of the generated face normals used in this computation.
Remarks
These functions assume the triangular mesh description is valid. See Validate and Clean
Example
auto mesh = std::make_unique<WaveFrontReader<uint16_t>>();
if ( FAILED( mesh->Load( L"test.obj" ) ) )
// Error
if ( mesh->hasNormals )
// Skip next computation
size_t nFaces = mesh->indices.size() / 3;
size_t nVerts = mesh->vertices.size();
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
for( size_t j = 0; j < nVerts; ++j )
pos[ j ] = mesh->vertices[ j ].position;
auto normals = std::make_unique<XMFLOAT3[]>(nVerts);
if ( FAILED( ComputeNormals( mesh->indices.data(), nFaces,
pos.get(), nVerts, CNORM_DEFAULT, normals.get() ) ) )
// Error
Further Reading
S Jin, R R Lewis, and D West; "A comparison of algorithms for vertex normal computation". link
Nelson Max, "Weights for Computing Vertex Normals from Facet Normals" link
Max Wagner, "Generating Vertex Normals" link
For Use
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7 Service Pack 1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
Architecture
- x86
- x64
- ARM64
For Development
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- GCC 10.5, 11.4, 12.3
- MinGW 12.2, 13.2
- CMake 3.20
Related Projects
DirectX Tool Kit for DirectX 11
DirectX Tool Kit for DirectX 12
Tools
See also
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.