From 6ed66561fc402c90538741f9a6cc2be41c7ab966 Mon Sep 17 00:00:00 2001 From: Soji Yamakawa Date: Sun, 8 Dec 2024 21:02:23 -0500 Subject: [PATCH] PLY Loader. --- src/ysgebl/src/kernel/ysshellext.cpp | 21 +++++++++++++++++++++ src/ysgebl/src/kernel/ysshellext.h | 6 ++++++ src/ysgebl/src/kernel/ysshellextio.cpp | 26 ++++++++++++++++++++++++++ src/ysgebl/src/kernel/ysshellextio.h | 3 +++ 4 files changed, 56 insertions(+) diff --git a/src/ysgebl/src/kernel/ysshellext.cpp b/src/ysgebl/src/kernel/ysshellext.cpp index ff5e21c..88e6262 100644 --- a/src/ysgebl/src/kernel/ysshellext.cpp +++ b/src/ysgebl/src/kernel/ysshellext.cpp @@ -796,6 +796,27 @@ YSRESULT YsShellExt::SetVertexPosition(VertexHandle vtHd,const YsVec3 &pos) return ModifyVertexPosition(vtHd,pos); } +YSRESULT YsShellExt::SetVertexNormal(VertexHandle vtHd,const YsVec3 &nom) +{ + auto *vtx=YsShell::GetVertex(vtHd); + if(nullptr!=vtx) + { + vtx->SetNormal(nom); + return YSOK; + } + return YSERR; +} + +YsVec3 YsShellExt::GetVertexNormal(VertexHandle vtHd) const +{ + auto *vtx=YsShell::GetVertex(vtHd); + if(nullptr!=vtx) + { + return vtx->GetNormal(); + } + return YsVec3::Origin(); +} + YSRESULT YsShellExt::SetVertexRoundFlag(YsShellVertexHandle vtHd,YSBOOL round) { VertexAttrib *vtAttrib=GetVertexAttrib(vtHd); diff --git a/src/ysgebl/src/kernel/ysshellext.h b/src/ysgebl/src/kernel/ysshellext.h index 068b6f7..18fab89 100644 --- a/src/ysgebl/src/kernel/ysshellext.h +++ b/src/ysgebl/src/kernel/ysshellext.h @@ -1243,6 +1243,12 @@ class YsShellExt : protected YsShell /*! This function moves vertex. */ YSRESULT SetVertexPosition(VertexHandle VtHd,const YsVec3 &NewPos); + /*! Vertex normal is not undo/redo target. */ + YSRESULT SetVertexNormal(VertexHandle vtHd,const YsVec3 &nom); + + /*! Vertex normal is not undo/redo target. */ + YsVec3 GetVertexNormal(VertexHandle vtHd) const; + /*! This function sets ROUND flag of the vertex. */ YSRESULT SetVertexRoundFlag(YsShellVertexHandle vtHd,YSBOOL round); diff --git a/src/ysgebl/src/kernel/ysshellextio.cpp b/src/ysgebl/src/kernel/ysshellextio.cpp index acfc18a..dcc4cb4 100644 --- a/src/ysgebl/src/kernel/ysshellextio.cpp +++ b/src/ysgebl/src/kernel/ysshellextio.cpp @@ -2162,6 +2162,11 @@ YSRESULT YsShellExtPlyReader::ReadOneLine(YsShellExt &shl,YsString &str) { auto vtHd=shl.AddVertex(vtx); state.vtHdList.push_back(vtHd); + if(true==nomSet) + { + state.vertexHasNormal=true; + shl.SetVertexNormal(vtHd,nom); + } --state.nVtxLeft; } else @@ -2261,6 +2266,18 @@ YSRESULT YsShellExtPlyReader::ReadOneLine(YsShellExt &shl,YsString &str) } plHd=shl.AddPolygon(plVtHd); + + if(true==texCoordSet && plVtHd.size()*2<=texCoord.size()) + { + YsArray plTxHd; + for(size_t i=0; i+1 vtHdList; + bool vertexHasNormal=false; + void Initialize(void) { inHeader=true; @@ -356,6 +358,7 @@ class YsShellExtPlyReader definingPolygon=false; nVtxLeft=0; nFaceLeft=0; + vertexHasNormal=false; } }; class PlyOptions