Skip to content

Commit 6b7735a

Browse files
committedAug 31, 2016
Basic loading of nCache MCX files looks to be working
1 parent 724e929 commit 6b7735a

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed
 

‎houdini/mantra/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
INSTALL ( FILES VRAYprocedural
2+
DESTINATION ${HDK_HOME_HFS}
3+
)
4+
5+
ADD_SUBDIRECTORY ( nCache )

‎houdini/mantra/VRAYprocedural

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// VRAYprocedurals
3+
//
4+
// This file contains the definitions for procedural objects loaded
5+
// into mantra. The first column is the name of the procedure. The
6+
// second column is the location of the dynamic object which handles
7+
// the procedure. The dynamic object is loaded using path searching
8+
// on the HOUDINI_DSO_PATH variable (see hconfig for more
9+
// information)
10+
//
11+
12+
//
13+
// Since Windows dynamic objects have a different file extension than
14+
// most unix platforms, we define a macro which makes the correct
15+
// filename. We also simplify the path construction a little.
16+
//
17+
#if defined(WIN32)
18+
#define DSO_FILE(filename) mantra/filename.dll
19+
#elif defined(MBSD)
20+
#define DSO_FILE(filename) mantra/filename.dylib
21+
#else
22+
#define DSO_FILE(filename) mantra/filename.so
23+
#endif
24+
25+
nCache DSO_FILE(VRAY_nCache)
26+
27+
// Make sure to undefine the macro before doing any further includes
28+
#undef DSO_FILE
29+
30+
#include "$HFS/houdini/VRAYprocedural"

‎houdini/mantra/nCache/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HDK_ADD_LIBRARY ( VRAY_nCache SHARED
2+
VRAY_nCache.cpp
3+
)
4+
5+
TARGET_LINK_LIBRARIES ( VRAY_nCache
6+
${NCACHE_REQUIRED_LIBRARIES}
7+
)
8+
9+
INSTALL ( TARGETS VRAY_nCache
10+
DESTINATION ${HDK_HOME_HFS}/dso/mantra
11+
)

‎houdini/mantra/nCache/VRAY_nCache.cpp

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
3+
// #include <UT/UT_DSOVersion.h>
4+
#include <GU/GU_Detail.h>
5+
#include "VRAY_nCache.h"
6+
#include <MCXMemoryReader.h>
7+
#include <MCMemoryReader.h>
8+
9+
static VRAY_ProceduralArg theArgs[] = {
10+
VRAY_ProceduralArg("file", "string", ""),
11+
VRAY_ProceduralArg()
12+
};
13+
14+
VRAY_Procedural *
15+
allocProcedural(const char *)
16+
{
17+
return new VRAY_nCache();
18+
}
19+
20+
const VRAY_ProceduralArg *
21+
getProceduralArgs(const char *)
22+
{
23+
return theArgs;
24+
}
25+
26+
VRAY_nCache::VRAY_nCache()
27+
{
28+
myBox.initBounds(0, 0, 0);
29+
}
30+
31+
VRAY_nCache::~VRAY_nCache()
32+
{
33+
}
34+
35+
const char *
36+
VRAY_nCache::className() const
37+
{
38+
return "VRAY_nCache";
39+
}
40+
41+
int
42+
VRAY_nCache::initialize(const UT_BoundingBox *box)
43+
{
44+
// Import the filenames
45+
import("file", myFile);
46+
fprintf(stderr,"VRAY_nCache file = %s\n",myFile.c_str());
47+
48+
if (myFile.endsWith(".mcx"))
49+
_memory_reader_ptr.reset(new nCache::MCXMemoryReader(myFile.c_str()));
50+
else if (myFile.endsWith(".mc"))
51+
_memory_reader_ptr.reset(new nCache::MCMemoryReader(myFile.c_str()));
52+
else
53+
return 0;
54+
55+
// The user is required to specify the bounds of the geometry.
56+
// Alternatively, if the bounds aren't specified, we could forcibly load
57+
// the geometry at this point and compute the bounds ourselves.
58+
if (!box)
59+
{
60+
const nCache::ChannelDataContainer& channels_data = _memory_reader_ptr->get_channels_data();
61+
if (!channels_data.empty())
62+
{
63+
nCache::ChannelDataContainer::const_iterator iter;
64+
nCache::ChannelDataContainer::const_iterator eIter = channels_data.end();
65+
for (iter = channels_data.begin();iter!=eIter;++iter)
66+
{
67+
UT_StringHolder channel_name(iter->first.c_str());
68+
if (channel_name.endsWith("_position"))
69+
{
70+
size_t num_points = iter->second._fvca.size();
71+
for (size_t ptIndex=0;ptIndex<num_points;ptIndex++)
72+
{
73+
UT_Vector3F P(iter->second._fvca[ptIndex].x,iter->second._fvca[ptIndex].y,iter->second._fvca[ptIndex].z);
74+
_current_frame_points.append(P);
75+
myBox.enlargeBounds(P);
76+
}
77+
break; // Found, no need to continue
78+
}
79+
}
80+
}
81+
else
82+
return 0;
83+
}
84+
else
85+
// Stash away the box the user specified
86+
myBox = *box;
87+
88+
fpreal fps = 24.0, shutter[2] = {0};
89+
import("global:fps", &fps, 1);
90+
import("camera:shutter", shutter, 2);
91+
92+
return 1;
93+
}
94+
95+
void
96+
VRAY_nCache::getBoundingBox(UT_BoundingBox &box)
97+
{
98+
box = myBox;
99+
}
100+
101+
void VRAY_nCache::addSamples(const Vector3Container& i_points,
102+
VRAY_ProceduralGeo& o_geo)
103+
{
104+
GA_RWAttributeRef id_attrib = o_geo->addIntTuple(GA_ATTRIB_POINT, "id", 1);
105+
if (!id_attrib.isValid())
106+
{
107+
std::cerr << "Failed to add point id attribute" << std::endl;
108+
return;
109+
}
110+
GA_Offset ptoff = o_geo->appendPointBlock(i_points.entries());
111+
112+
UT_ValArray<int32> point_id;
113+
for (GA_Size i=0;i<i_points.entries();i++)
114+
{
115+
o_geo->setPos3(ptoff, i_points.getRawArray()[i]);
116+
point_id.append(i);
117+
ptoff++;
118+
}
119+
120+
o_geo->setAttributeFromArray(id_attrib,o_geo->getPointRange(), point_id);
121+
}
122+
void
123+
VRAY_nCache::render()
124+
{
125+
// Allocate geometry.
126+
// Warning: When allocating geometry for a procedural, do not simply
127+
// construct a GU_Detail, but call VRAY_Procedural::createGeometry().
128+
VRAY_ProceduralGeo g0 = createGeometry();
129+
130+
addSamples(this->_current_frame_points,g0);
131+
132+
VRAY_ProceduralChildPtr obj = createChild();
133+
obj->addGeometry(g0);
134+
}

‎houdini/mantra/nCache/VRAY_nCache.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <UT/UT_BoundingBox.h>
4+
#include <UT/UT_String.h>
5+
#include <VRAY/VRAY_Procedural.h>
6+
#include <AbstractMemoryReader.h>
7+
8+
/// @brief A procedural which does a deferred load of Maya nCache data from disk
9+
class VRAY_nCache : public VRAY_Procedural {
10+
protected:
11+
typedef boost::shared_ptr<nCache::AbstractMemoryReader> AbstractMemoryReaderSharedPtr;
12+
AbstractMemoryReaderSharedPtr _memory_reader_ptr;
13+
typedef UT_ValArray<UT_Vector3F> Vector3Container;
14+
public:
15+
VRAY_nCache();
16+
virtual ~VRAY_nCache();
17+
18+
virtual const char *className() const;
19+
virtual int initialize(const UT_BoundingBox *);
20+
virtual void getBoundingBox(UT_BoundingBox &box);
21+
virtual void render();
22+
protected:
23+
void addSamples(const Vector3Container& i_points,
24+
VRAY_ProceduralGeo& o_geo);
25+
26+
private:
27+
UT_BoundingBox myBox;
28+
UT_StringHolder myFile;
29+
Vector3Container _current_frame_points;
30+
};

0 commit comments

Comments
 (0)
Please sign in to comment.