Skip to content

Commit

Permalink
PLY Loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
captainys committed Dec 9, 2024
1 parent ea5e265 commit 6ed6656
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ysgebl/src/kernel/ysshellext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/ysgebl/src/kernel/ysshellext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions src/ysgebl/src/kernel/ysshellextio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2261,6 +2266,18 @@ YSRESULT YsShellExtPlyReader::ReadOneLine(YsShellExt &shl,YsString &str)
}
plHd=shl.AddPolygon(plVtHd);


if(true==texCoordSet && plVtHd.size()*2<=texCoord.size())
{
YsArray <YsShell::TexCoordHandle> plTxHd;
for(size_t i=0; i+1<texCoord.size(); i+=2)
{
YsVec2 pos(texCoord[i],texCoord[i+1]);
plTxHd.push_back(shl.AddTexCoord(pos));
shl.SetPolygonTexCoord(plHd,plTxHd);
}
}

YsColor col;
col.SetIntRGBA(red,green,blue,alpha);
if(7==rgbSet)
Expand All @@ -2279,7 +2296,16 @@ YSRESULT YsShellExtPlyReader::ReadOneLine(YsShellExt &shl,YsString &str)
}
void YsShellExtPlyReader::EndRead(YsShellExt &shl)
{
if(0<state.textureFileName.size())
{
shl.AddMetaData(YsString("TextureFile"),state.textureFileName);
}
if(true==state.vertexHasNormal)
{
shl.AddMetaData(YsString("VertexHasNormal"),YsString("1"));
}
}

YSRESULT YsShellExtPlyReader::ReadPly(YsShellExt &shl,YsTextInputStream &inStream,const ReadOption &option)
{
YSRESULT res=YSOK;
Expand Down
3 changes: 3 additions & 0 deletions src/ysgebl/src/kernel/ysshellextio.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,16 @@ class YsShellExtPlyReader
YsString textureFileName;
YsArray <YsShell::VertexHandle> vtHdList;

bool vertexHasNormal=false;

void Initialize(void)
{
inHeader=true;
definingVertex=false;
definingPolygon=false;
nVtxLeft=0;
nFaceLeft=0;
vertexHasNormal=false;
}
};
class PlyOptions
Expand Down

0 comments on commit 6ed6656

Please sign in to comment.