Origin plane: add semi transparent face

This commit is contained in:
Ronny Standtke
2023-04-29 17:51:58 +02:00
committed by Adrián Insaurralde Avalos
parent 6d186183b2
commit 28d5f47b14
3 changed files with 33 additions and 1 deletions

View File

@@ -76,6 +76,9 @@ public:
/// Returns default size. Use this if it is not possible to determine appropriate size by other means
static double defaultSize();
// default color for origini: light-blue (50, 150, 250, 255 stored as 0xRRGGBBAA)
static const uint32_t defaultColor = 0x3296faff;
protected:
void onChanged(const App::Property* prop) override;
bool onDelete(const std::vector<std::string> &) override;

View File

@@ -49,7 +49,7 @@ ViewProviderOriginFeature::ViewProviderOriginFeature () {
ADD_PROPERTY_TYPE ( Size, (ViewProviderOrigin::defaultSize()), 0, App::Prop_ReadOnly,
QT_TRANSLATE_NOOP("App::Property", "Visual size of the feature"));
ShapeColor.setValue ( 50.f/255, 150.f/255, 250.f/255 ); // Set default color for origin (light-blue)
ShapeColor.setValue ( ViewProviderOrigin::defaultColor ); // Set default color for origin (light-blue)
BoundingBox.setStatus(App::Property::Hidden, true); // Hide Boundingbox from the user due to it doesn't make sense
// Create node for scaling the origin

View File

@@ -26,10 +26,14 @@
#ifndef _PreComp_
# include <Inventor/nodes/SoAsciiText.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoFaceSet.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoShapeHints.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/SbColor.h>
#endif
#include "ViewProviderPlane.h"
@@ -73,6 +77,31 @@ void ViewProviderPlane::attach ( App::DocumentObject *obj ) {
pLines->coordIndex.setValues(0, 6, lines);
sep->addChild ( pLines );
// add semi transparent face
auto faceSeparator = new SoSeparator();
sep->addChild(faceSeparator);
auto material = new SoMaterial();
material->transparency.setValue(0.95f);
auto color = new SbColor();
float alpha = 0.0f;
color->setPackedValue(ViewProviderOrigin::defaultColor, alpha);
material->ambientColor.setValue(*color);
material->diffuseColor.setValue(*color);
faceSeparator->addChild(material);
// disable backface culling and render with two-sided lighting
auto shapeHints = new SoShapeHints();
shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
faceSeparator->addChild(shapeHints);
auto faceSet = new SoFaceSet();
auto vertexProperty = new SoVertexProperty();
vertexProperty->vertex.setValues(0, 4, verts);
faceSet->vertexProperty.setValue(vertexProperty);
faceSeparator->addChild(faceSet);
auto textTranslation = new SoTranslation ();
textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size * 9./10., 0 ) );
sep->addChild ( textTranslation );