Skip to content

Commit

Permalink
fixed some loading issues and tool storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-Haefner committed Apr 13, 2016
1 parent 078493d commit bc94b8b
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/addons/Engineering/Factory/VRFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Geo {
//void init(vector<VRGeometryPtr>& geos, VRMaterialPtr mat) {
void init(vector<Geo>& geos, VRMaterialPtr mat, string path, bool thread) {
geo = VRGeometry::create("factory_part"); // init new object
cout << "Load VRML " << geo->getName() << endl;

pos = GeoPnt3fProperty::create();
norms = GeoVec3fProperty::create();
Expand Down
5 changes: 4 additions & 1 deletion src/core/objects/geometry/VRGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ void VRGeometry::setup() {
// get source info
// construct data from that

cout << "VRGeometry::setup " << source.type << " " << FILE << " " << source.parameter << endl;
string bname = getBaseName();
setName( "TMP_GEO_SETUP_NAME" );

switch(source.type) {
case CODE:
Expand All @@ -797,6 +798,8 @@ void VRGeometry::setup() {
setPrimitive(p1, p2);
break;
}

setName( bname );
}

void VRGeometry::readSharedMemory(string segment, string object) {
Expand Down
7 changes: 7 additions & 0 deletions src/core/scene/VRSceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "core/objects/VRLight.h"
#include "core/objects/VRLightBeacon.h"
#include "core/objects/geometry/VRGeometry.h"

#include "core/tools/VRWaypoint.h"
#include "core/tools/VRGeoPrimitive.h"
#include "core/tools/VRKinematictool.h"
//#include "addons/Engineering/CSG/CSGGeometry.h"

#include "VRScene.h"
Expand Down Expand Up @@ -59,6 +63,9 @@ void regObjectStorageTypes() {
VRStorage::regStorageType<VRLightBeacon>("LightBeacon");
VRStorage::regStorageType<VRGroup>("Group");
VRStorage::regStorageType<VRLod>("Lod");
VRStorage::regStorageType<VRWaypoint>("Waypoint");
VRStorage::regStorageType<VRGeoPrimitive>("GeoPrimitive");
VRStorage::regStorageType<VRJointTool>("JointTool");
}

VRSceneLoader::VRSceneLoader() { cout << "\nInit VRSceneLoader\n"; regObjectStorageTypes(); }
Expand Down
17 changes: 10 additions & 7 deletions src/core/scene/import/VRImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ VRTransformPtr VRImport::load(string path, VRObjectPtr parent, bool reload, stri

VRTransformPtr res = VRTransform::create("proxy");
LoadJob* job = new LoadJob(path, preset, res, progress);
if (!thread) job->load(VRThreadWeakPtr());
else {
if (!thread) {
job->load(VRThreadWeakPtr());
return cache[path].retrieve(parent);
} else {
job->loadCb = VRFunction< VRThreadWeakPtr >::create( "geo load", boost::bind(&LoadJob::load, job, _1) );
int t = VRSceneManager::getCurrent()->initThread(job->loadCb.get(), "geo load thread", false, 1);
fillCache(path, res);
return cache[path].retrieve(parent);
}

fillCache(path, res);
return cache[path].retrieve(parent);
}

VRImport::LoadJob::LoadJob(string p, string pr, VRTransformPtr r, VRProgressPtr pg) {
Expand Down Expand Up @@ -145,6 +146,7 @@ void VRImport::LoadJob::load(VRThreadWeakPtr tw) {
};

loadSwitch();
VRImport::get()->fillCache(path, res);
if (t) t->syncToMain();
}

Expand Down Expand Up @@ -258,6 +260,7 @@ void VRImport::fillCache(string path, VRTransformPtr obj) {
cache[path].root = static_pointer_cast<VRTransform>(obj);
for (auto o : cache[path].root->getChildren(true)) cache[path].objects[o->getName()] = o;
cache[path].copy = 0; // TODO
cout << "VRImport::fillCache " << path << ", cache size: " << cache[path].objects.size() << endl;
}

VRGeometryPtr VRImport::loadGeometry(string file, string object, string preset, bool thread) {
Expand All @@ -270,9 +273,9 @@ VRGeometryPtr VRImport::loadGeometry(string file, string object, string preset,

if (cache[file].objects.count(object) == 0) {
cout << "VRImport::loadGeometry - Warning: " << file << " in cache but has no object " << object << endl;
cout << cache[file].root->getName() << endl;
cout << " cache root: " << cache[file].root->getName() << " cache size: " << cache[file].objects.size() << endl;
//for (auto o : cache[file].root->getChildren(true)) cout << " cache " << o->getName() << endl;
for (auto o : cache[file].objects) cout << " cache " << o.first << endl;
for (auto o : cache[file].objects) cout << ", cache " << o.first << endl;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/tools/VRGeoPrimitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void VRGeoPrimitive::setupHandles() {
if (n == "Number of teeth") continue;

auto h = VRHandle::create(n);
h->setPersistency(0);
handles.push_back(h);
addChild(h);

Expand Down
2 changes: 1 addition & 1 deletion src/core/tools/VRGeoPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VRGeoPrimitive : public VRGeometry {
public:
VRGeoPrimitive(string name);

static VRGeoPrimitivePtr create(string name);
static VRGeoPrimitivePtr create(string name = "None");
VRGeoPrimitivePtr ptr();

vector<VRHandlePtr> getHandles();
Expand Down
28 changes: 28 additions & 0 deletions src/core/tools/VRKinematictool.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "VRKinematictool.h"
#include "core/utils/toString.h"
#include "core/utils/VRFunction.h"
#include "core/utils/VRStorage_template.h"
#include "core/objects/VRTransform.h"
#include "core/objects/material/VRMaterial.h"
#include "core/scene/VRScene.h"
#include "core/scene/VRSceneManager.h"
#include "VRAnalyticGeometry.h"

#include <OpenSG/OSGPlane.h>
#include <OpenSG/OSGLine.h>
#include <boost/bind.hpp>

OSG_BEGIN_NAMESPACE;
using namespace std;
Expand All @@ -22,6 +27,16 @@ VRJointTool::VRJointTool(string name) : VRGeometry(name) {

ageo = VRAnalyticGeometry::create();
ageo->setLabelParams(0.05, true, true);
ageo->setPersistency(0);

store("jt_anchor1", &anchor1);
store("jt_anchor2", &anchor2);
storeObjName("jt_obj1_name", &obj1, &obj1_name);
storeObjName("jt_obj2_name", &obj2, &obj2_name);
//store("jt_active", &active);
//store("jt_lastAppended", &lastAppended);

regStorageUpdateFkt( VRFunction<int>::create("jointtool setup", boost::bind(&VRJointTool::setup, this)) );
}

VRJointTool::~VRJointTool() { clear(); }
Expand All @@ -34,6 +49,17 @@ VRJointToolPtr VRJointTool::create(string name) {
return ptr;
}

void VRJointTool::setup() {
auto fkt = VRFunction<int>::create("jointtool delayed setup", boost::bind(&VRJointTool::delayed_setup, this));
VRSceneManager::getCurrent()->queueJob( fkt );
}

void VRJointTool::delayed_setup() {
obj1 = dynamic_pointer_cast<VRTransform>( getRoot()->find(obj1_name) );
obj2 = dynamic_pointer_cast<VRTransform>( getRoot()->find(obj2_name) );
updateVis();
}

void VRJointTool::clear() {
setActive(0);
obj1.reset();
Expand All @@ -44,9 +70,11 @@ void VRJointTool::clear() {
int VRJointTool::append(VRTransformPtr t, pose p) {
if (lastAppended) {
obj1 = t;
obj1_name = t->getName();
anchor1 = p;
} else {
obj2 = t;
obj2_name = t->getName();
anchor2 = p;
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/tools/VRKinematictool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ class VRJointTool : public VRGeometry {
private:
VRTransformWeakPtr obj1;
VRTransformWeakPtr obj2;
string obj1_name;
string obj2_name;
pose anchor1;
pose anchor2;
bool selected = true;
bool active = true;
bool lastAppended = true;
VRAnalyticGeometryPtr ageo;

void delayed_setup();
void setup();
void updateVis();

public:
VRJointTool(string name);
~VRJointTool();

static VRJointToolPtr create(string name);
static VRJointToolPtr create(string name = "None");
VRJointToolPtr ptr();

int append(VRTransformPtr t, pose p);
Expand Down
6 changes: 5 additions & 1 deletion src/core/tools/VRProjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ void VRProjectManager::addItem(VRStoragePtr s, string mode) {
if (mode == "REBUILD") vault_rebuild.push_back(s);
}

vector<VRStoragePtr> VRProjectManager::getItems() { return vault_rebuild; }
vector<VRStoragePtr> VRProjectManager::getItems() {
vector<VRStoragePtr> res;
for (auto v : vault_rebuild) if(v) res.push_back(v);
return res;
}

void VRProjectManager::save(string path) {
if (fs::exists(path)) path = fs::canonical(path).string();
Expand Down
15 changes: 15 additions & 0 deletions src/core/tools/VRWaypoint.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
#include "VRWaypoint.h"
#include "core/objects/material/VRMaterial.h"
#include "core/utils/VRFunction.h"
#include "core/utils/VRStorage_template.h"

#include <OpenSG/OSGPlane.h>
#include <boost/bind.hpp>

using namespace OSG;

VRWaypoint::VRWaypoint(string name) : VRGeometry(name) {
type = "Waypoint";

store("wp_pose", &Pose);
store("wp_floor", &Floor);
store("wp_at", &at);

regStorageUpdateFkt( VRFunction<int>::create("waypoint setup", boost::bind(&VRWaypoint::setup, this)) );
}

VRWaypointPtr VRWaypoint::create(string name) { return shared_ptr<VRWaypoint>(new VRWaypoint(name) ); }
VRWaypointPtr VRWaypoint::ptr() { return static_pointer_cast<VRWaypoint>( shared_from_this() ); }

void VRWaypoint::setup() {
auto m = VRMaterial::get("waypoint");
m->setDiffuse(Vec3f(1,0,0));
setMaterial(m);
}

void VRWaypoint::set(pose p) { Pose = p; updateGeo(); }
void VRWaypoint::set(VRTransformPtr t) { Pose = t->getWorldPose(); at = t->getAt(); updateGeo(); }
pose VRWaypoint::get() { return Pose; }
Expand Down
3 changes: 2 additions & 1 deletion src/core/tools/VRWaypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class VRWaypoint : public VRGeometry {
pose Floor;
Vec3f at;

void setup();
void updateGeo();

public:
VRWaypoint(string name);

static VRWaypointPtr create(string name);
static VRWaypointPtr create(string name = "None");
VRWaypointPtr ptr();

void set(pose p);
Expand Down
19 changes: 19 additions & 0 deletions src/core/utils/toString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,22 @@ void toValue(string s, OSG::Vec3i& v) {
ss >> v[1];
ss >> v[2];
}

string toString(OSG::pose po) {
return toString(po.pos()) + " " + toString(po.dir()) + " " + toString(po.up());
}

void toValue(string s, OSG::pose& po) {
OSG::Vec3f p,d,u;
stringstream ss(s);
ss >> p[0];
ss >> p[1];
ss >> p[2];
ss >> d[0];
ss >> d[1];
ss >> d[2];
ss >> u[0];
ss >> u[1];
ss >> u[2];
po.set(p,d,u);
}
5 changes: 4 additions & 1 deletion src/core/utils/toString.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <OpenSG/OSGVector.h>
#include "core/math/pose.h"

using namespace std;

Expand All @@ -21,6 +22,7 @@ string toString(OSG::Vec3f v);
string toString(OSG::Pnt3f v);
string toString(OSG::Vec4f v);
string toString(OSG::Vec3i v);
string toString(OSG::pose p);

// deprecated?
bool toBool(string s, int* N = 0);
Expand All @@ -41,6 +43,7 @@ void toValue(string s, float& f);
void toValue(string s, OSG::Vec2f& v);
void toValue(string s, OSG::Vec3f& v);
void toValue(string s, OSG::Vec4f& v);
void toValue(string s, OSG::Vec3i& v);
void toValue(string s, OSG::Vec3i& v);
void toValue(string s, OSG::pose& p);

#endif // TOSTRING_H_INCLUDED

0 comments on commit bc94b8b

Please sign in to comment.