Skip to content

Commit

Permalink
First working implementation of volume via ADF. Need more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanmunawar committed Jul 10, 2021
1 parent 95a155b commit c167b16
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 18 deletions.
39 changes: 26 additions & 13 deletions adf_loader/version_1_0/adf_loader_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,30 +2206,31 @@ bool ADFLoader_1_0::loadVolumeAttribs(YAML::Node *a_node, afVolumeAttributes *at
YAML::Node nameSpaceNode = node["namespace"];
YAML::Node imagesNode = node["images"];


ADFUtils::getIdentificationAttribsFromNode(&node, &attribs->m_identificationAttribs);
ADFUtils::getCommunicationAttribsFromNode(&node, &attribs->m_communicationAttribs);
ADFUtils::getShaderAttribsFromNode(&node, &attribs->m_shaderAttribs);
ADFUtils::getPluginAttribsFromNode(&node, &attribs->m_pluginAttribs);

if (imagesNode.IsDefined()){
YAML::Node pathNode = node["path"];
YAML::Node prefixNode = node["prefix"];
YAML::Node formatNode = node["format"];
YAML::Node countNode = node["count"];
YAML::Node pathNode = imagesNode["path"];
YAML::Node prefixNode = imagesNode["prefix"];
YAML::Node formatNode = imagesNode["format"];
YAML::Node countNode = imagesNode["count"];
try{
attribs->m_multiImageAttribs.m_path = pathNode.as<string>();
attribs->m_multiImageAttribs.m_prefix = prefixNode.as<string>();
attribs->m_multiImageAttribs.m_format = formatNode.as<string>();
attribs->m_multiImageAttribs.m_count = countNode.as<uint>();
attribs->m_specificationType = afVolumeSpecificationType::MULTI_IMAGES;
attribs->m_multiImageAttribs.m_count = countNode.as<int>();
attribs->m_specificationType = afVolumeSpecificationType::MULTI_IMAGE;
}
catch(YAML::Exception e){
catch(YAML::Exception& e){
cerr << "ERROR! FAILED TO LOAD VOLUME: " << attribs->m_identificationAttribs.m_name << endl;
e.what();
return 0;
}

}

ADFUtils::getIdentificationAttribsFromNode(&node, &attribs->m_identificationAttribs);
ADFUtils::getCommunicationAttribsFromNode(&node, &attribs->m_communicationAttribs);
ADFUtils::getShaderAttribsFromNode(&node, &attribs->m_shaderAttribs);
ADFUtils::getPluginAttribsFromNode(&node, &attribs->m_pluginAttribs);

return result;
}

Expand Down Expand Up @@ -2505,6 +2506,7 @@ bool ADFLoader_1_0::loadModelAttribs(YAML::Node *a_node, afModelAttributes *attr
YAML::Node softBodiesNode = node["soft bodies"];
YAML::Node ghostObjectsNode = node["ghost objects"];
YAML::Node vehiclesNode = node["vehicles"];
YAML::Node volumesNode = node["volumes"];
YAML::Node jointsNode = node["joints"];
YAML::Node sensorsNode = node["sensors"];
YAML::Node actuatorsNode = node["actuators"];
Expand Down Expand Up @@ -2672,6 +2674,17 @@ bool ADFLoader_1_0::loadModelAttribs(YAML::Node *a_node, afModelAttributes *attr
}
}

// Load Volumes
for (size_t i = 0 ; i < volumesNode.size(); i++){
afVolumeAttributes volumeAttribs;
string identifier = volumesNode[i].as<string>();
YAML::Node volumeNode = node[identifier];
if (loadVolumeAttribs(&volumeNode, &volumeAttribs)){
volumeAttribs.m_identifier = identifier;
attribs->m_volumeAttribs.push_back(volumeAttribs);
}
}

ADFUtils::getPluginAttribsFromNode(&node, &attribs->m_pluginAttribs);

// This flag would ignore collision for all the multibodies in the scene
Expand Down
6 changes: 5 additions & 1 deletion ambf_framework/afAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ struct afVehicleAttributes: public afBaseObjectAttributes

enum class afVolumeSpecificationType{
INVALID,
MULTI_IMAGES
MULTI_IMAGE
};


Expand Down Expand Up @@ -1138,6 +1138,10 @@ struct afModelAttributes: public afBaseObjectAttributes, public afFileObjectAttr
m_actuatorAttribs[i]->resolveRelativePathAttribs(a_parentPath);
}

for (int i = 0 ; i < m_volumeAttribs.size() ; i++){
m_volumeAttribs[i].resolveRelativePathAttribs(a_parentPath);
}

m_pathsResolved = true;
}
return true;
Expand Down
80 changes: 80 additions & 0 deletions ambf_framework/afFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8539,6 +8539,14 @@ bool afModel::createFromAttribs(afModelAttributes *a_attribs)
}
}

// Load Volumes
for (size_t i = 0; i < attribs.m_volumeAttribs.size(); ++i) {
afVolumePtr volumePtr = new afVolume(m_afWorld, this);
if (volumePtr->createFromAttribs(&attribs.m_volumeAttribs[i])){
// addLight(lightPtr);
}
}

loadPlugins(&attribs.m_pluginAttribs);
m_pluginManager.init(this, a_attribs);

Expand Down Expand Up @@ -9389,19 +9397,91 @@ void afNoiseModel::createFromAttribs(afNoiseModelAttribs *a_attribs)
m_randomDistribution = new normal_distribution<double>(m_attribs.m_mean, m_attribs.m_std_dev);
}

///
/// \brief afVolume::afVolume
/// \param a_afWorld
/// \param a_modelPtr
///
afVolume::afVolume(afWorldPtr a_afWorld, afModelPtr a_modelPtr): afBaseObject(afType::VOLUME, a_afWorld, a_modelPtr)
{

}


///
/// \brief afVolume::~afVolume
///
afVolume::~afVolume()
{

}

///
/// \brief afVolume::createFromAttribs
/// \param a_attribs
/// \return
///
bool afVolume::createFromAttribs(afVolumeAttributes *a_attribs)
{
m_attribs = *a_attribs;

if (m_attribs.m_specificationType == afVolumeSpecificationType::MULTI_IMAGE){
m_multiImage = cMultiImage::create();
string path_and_prefix = m_attribs.m_multiImageAttribs.m_path.c_str() + "/" + m_attribs.m_multiImageAttribs.m_prefix;
if (m_multiImage->loadFromFiles(path_and_prefix, m_attribs.m_multiImageAttribs.m_format, m_attribs.m_multiImageAttribs.m_count)){
cTexture3dPtr texture = cTexture3d::create();
texture->setImage(m_multiImage);
m_voxelObject = new cVoxelObject();
m_voxelObject->setTexture(texture);

cShaderProgramPtr shaderPgm = afShaderUtils::createFromAttribs(&m_attribs.m_shaderAttribs, m_name, "VOLUME");
if (shaderPgm){
m_voxelObject->setCustomShaderProgram(shaderPgm);
}
else{
m_voxelObject->setRenderingModeIsosurfaceColorMap();
}

m_voxelObject->setLocalPos(0.0, 0.0, 0.0);

// rotate object
m_voxelObject->rotateExtrinsicEulerAnglesDeg(90, 30, -90, C_EULER_ORDER_YXZ);

// set the dimensions by assigning the position of the min and max corners
m_voxelObject->m_minCorner.set(-0.5,-0.5,-0.5);
m_voxelObject->m_maxCorner.set( 0.5, 0.5, 0.5);

// set the texture coordinate at each corner.
m_voxelObject->m_minTextureCoord.set(0.0, 0.0, 0.0);
m_voxelObject->m_maxTextureCoord.set(1.0, 1.0, 1.0);

// set haptic properties
m_voxelObject->m_material->setStiffness(0.2 * 1);
m_voxelObject->m_material->setStaticFriction(0.0);
m_voxelObject->m_material->setDynamicFriction(0.0);

// enable materials
m_voxelObject->setUseMaterial(true);

// set material
m_voxelObject->m_material->setWhite();

// set quality of graphic rendering
m_voxelObject->setQuality(0.5);

m_voxelObject->setTransparencyLevel(1.0);

m_voxelObject->setIsosurfaceValue(0.45);
m_voxelObject->setOpticalDensity(1.2);

m_afWorld->addSceneObjectToWorld(m_voxelObject);
}
else{
cerr << "ERROR! FAILED TO LOAD VOLUME FROM MULTI_IMAGES PATH: " << m_attribs.m_multiImageAttribs.m_path.c_str() << "/" << m_attribs.m_multiImageAttribs.m_prefix << endl;
}
}

return true;
}

void afVolume::update(double dt)
Expand Down
3 changes: 3 additions & 0 deletions ambf_framework/afFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class afRigidBody;
class afSoftBody;
class afGhostObject;
class afJoint;
class afVolume;
class afWorld;
struct afRenderOptions;
class afCartesianController;
Expand All @@ -140,6 +141,7 @@ typedef afWorld* afWorldPtr;
typedef afConstraintActuator* afConstraintActuatorPtr;
typedef afRayTracerSensor* afRayTracerSensorPtr;
typedef afResistanceSensor* afResistanceSensorPtr;
typedef afVolume* afVolumePtr;

typedef map<string, afRigidBodyPtr> afRigidBodyMap;
typedef map<string, afSoftBodyPtr> afSoftBodyMap;
Expand Down Expand Up @@ -2530,6 +2532,7 @@ class afVolume: public afBaseObject{
protected:
afVolumeAttributes m_attribs;
cVoxelObject* m_voxelObject;
cMultiImagePtr m_multiImage;
};


Expand Down
2 changes: 1 addition & 1 deletion ambf_utilities/ambf_addon
Submodule ambf_addon updated 3 files
+7 −30 README.md
+1,354 −3,426 ambf_addon.py
+0 −103 get_co.py
20 changes: 17 additions & 3 deletions external/chai3d/src/world/CVoxelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,8 @@ void cVoxelObject::setCustomShaders(std::string vtx_shader, std::string frag_sha
C_SHADER_CUSTOM_VERT = vtx_shader;
C_SHADER_CUSTOM_FRAG = frag_shader;

int mode;

// select mode
mode = C_RENDERING_MODE_CUSTOM;
int mode = C_RENDERING_MODE_CUSTOM;

// setup vertex shader
m_vertexShaders[mode] = cShader::create(C_VERTEX_SHADER);
Expand All @@ -343,6 +341,22 @@ void cVoxelObject::setCustomShaders(std::string vtx_shader, std::string frag_sha
setRenderingModeCustom();
}

void cVoxelObject::setCustomShaderProgram(cShaderProgramPtr a_shaderPgm)
{
// select mode
int mode = C_RENDERING_MODE_CUSTOM;

// setup program shader
m_programShaders[mode] = cShaderProgram::create();
m_programShaders[mode]->attachShader(m_vertexShaders[mode]);
m_programShaders[mode]->attachShader(m_fragmentShaders[mode]);

// link program shader
m_programShaders[mode]->linkProgram();

setRenderingModeCustom();
}


//==============================================================================
/*!
Expand Down
3 changes: 3 additions & 0 deletions external/chai3d/src/world/CVoxelObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class cVoxelObject : public cMesh
//! This method sets the custom shaders. Call before setting custom mode
void setCustomShaders(std::string vtx_shader, std::string frag_shader);

//! This method sets the custom shader Program.
void setCustomShaderProgram(cShaderProgramPtr a_shaderPgm);


//--------------------------------------------------------------------------
// PUBLIC METHODS - SETTINGS:
Expand Down

0 comments on commit c167b16

Please sign in to comment.