Merge pull request #373 from martin-frbg/vrml-sphere

Add support for the VRML node "sphere" to the io_x3d plugin
This commit is contained in:
Marco Callieri 2018-10-18 10:02:06 +02:00 committed by GitHub
commit 42ef8f6c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -783,7 +783,7 @@ namespace io {
QString coorTag[] = {"Coordinate", "CoordinateDouble"};
QDomElement coordinate = findNode(coorTag, 2, geometry);
//If geometry node is supported, get info on color, normal and texture coordinate (per vertex, per color, or per wedge)
if ((!coordinate.isNull() && ((coordinate.attribute("point")!= "") || coordinate.attribute("USE", "") != "")) || (tagName == "ElevationGrid") || (tagName == "Cylinder"))
if ((!coordinate.isNull() && ((coordinate.attribute("point")!= "") || coordinate.attribute("USE", "") != "")) || (tagName == "ElevationGrid") || (tagName == "Cylinder") || (tagName == "Sphere"))
{
bool copyTextureFile = true;
QStringList colorList, normalList, textureList;
@ -1891,6 +1891,32 @@ namespace io {
return E_NOERROR;
}
static int LoadSphere(QDomElement geometry,
OpenMeshType& m,
const vcg::Matrix44<ScalarType>& tMatrix,
AdditionalInfoX3D* info,
CallBackPos *cb)
{
vcg::Matrix44<ScalarType> t, tmp;
t.SetIdentity();
QStringList radiusList;
findAndParseAttribute(radiusList, geometry, "radius", "1");
float radius = radiusList[0].toFloat();
tmp.SetScale(radius,radius,radius);
t *= tmp;
tmp = tMatrix * t;
OpenMeshType newSphere;
vcg::tri::Sphere<OpenMeshType>(newSphere, 3);
if (info->meshColor)
vcg::tri::UpdateColor<OpenMeshType>::PerVertexConstant(newSphere, info->color, false);
// vcg::tri::UpdatePosition<OpenMeshType>::Matrix(newSphere, tMatrix, false);
vcg::tri::UpdatePosition<OpenMeshType>::Matrix(newSphere, tmp, false);
vcg::tri::Append<OpenMeshType, OpenMeshType>::Mesh(m, newSphere);
info->numvert++;
if (cb !=NULL) (*cb)(10 + 80*info->numvert/info->numface, "Loading X3D Object...");
return E_NOERROR;
}
//Load texture info from Appearance node.
@ -2486,7 +2512,7 @@ namespace io {
QDomElement coordinate = findNode(coordTag, 2, geometry);
result = solveDefUse(coordinate, defMap, coordinate, info);
if (result != E_NOERROR) return result;
if ((!coordinate.isNull() && (coordinate.attribute("point") != "")) || (geometry.tagName() == "ElevationGrid") || (geometry.tagName() == "Cylinder"))
if ((!coordinate.isNull() && (coordinate.attribute("point") != "")) || (geometry.tagName() == "ElevationGrid") || (geometry.tagName() == "Cylinder") || (geometry.tagName() == "Sphere"))
{
//Get coordinate
QStringList coordList;
@ -2602,6 +2628,8 @@ namespace io {
return LoadPointSet(geometry, m, tMatrix, coordList, colorList, colorComponent, info, cb);
else if (geometry.tagName() == "Cylinder")
return LoadCylinder(geometry, m, tMatrix, info, cb);
else if (geometry.tagName() == "Sphere")
return LoadSphere(geometry, m, tMatrix, info, cb);
}
else if (geometry.tagName() == "Polypoint2D")
return LoadPolypoint2D(geometry, m, tMatrix, info, cb);

View File

@ -160,7 +160,7 @@ QDomDocument *doc;
x3dNode.insert("TriangleFanSet"); x3dNode.insert("TriangleSet"); x3dNode.insert("TriangleSet2D");
x3dNode.insert("TriangleStripSet"); x3dNode.insert("TwoSidedMaterial"); x3dNode.insert("UniversalJoint");
x3dNode.insert(" Viewpoint"); x3dNode.insert("ViewpointGroup"); x3dNode.insert("VolumeEmitter");
x3dNode.insert("VolumePicker"); x3dNode.insert("WindPhysicsModel"); x3dNode.insert("Cylinder");
x3dNode.insert("VolumePicker"); x3dNode.insert("WindPhysicsModel"); x3dNode.insert("Cylinder"); x3dNode.insert("Sphere");
}