Skip to content

Commit

Permalink
point light instance writer for instancer_hda
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeneren committed Jan 5, 2020
1 parent d5292e0 commit 29e6831
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
13 changes: 10 additions & 3 deletions instancer_hda/ROP_VPT_Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ using namespace vpt_instance;

static PRM_Name names[] = {
PRM_Name("outputFile", "Output File"),
PRM_Name("soppath", "SOP Path")
PRM_Name("soppath", "SOP Path"),
PRM_Name("render_light", "Render Light Instances")
};

static PRM_Default theFileDefault(0, "$HIP/Outputs/VPT/defgeo.ins");

PRM_Template VPT_INS_ROP::myTemplateList[] = {
PRM_Template(PRM_FILE_E, 1, &names[0], &theFileDefault , 0, 0 , 0 , &PRM_SpareData::fileChooserModeWrite), // file Output
PRM_Template(PRM_STRING, PRM_TYPE_DYNAMIC_PATH, 1, &names[1], 0, 0, 0, 0, &PRM_SpareData::sopPath), // sop path
PRM_Template(PRM_STRING, PRM_TYPE_DYNAMIC_PATH, 1, &names[1], 0, 0, 0, 0, &PRM_SpareData::sopPath), // sop path
PRM_Template(PRM_TOGGLE, 0, &names[2], PRMzeroDefaults), // render Light instance
PRM_Template() // placeholder
};

Expand Down Expand Up @@ -79,6 +81,7 @@ static PRM_Template * getTemplates()
prmTemplate[ROP_VPT_TAKE] = theRopTemplates[ROP_TAKENAME_TPLATE];
prmTemplate[ROP_VPT_SOPOUTPUT] = VPT_INS_ROP::myTemplateList[0];
prmTemplate[ROP_VPT_SOPPATH] = VPT_INS_ROP::myTemplateList[1];
prmTemplate[ROP_VPT_LIGHT] = VPT_INS_ROP::myTemplateList[2];

prmTemplate[ROP_VPT_TPRERENDER] = theRopTemplates[ROP_TPRERENDER_TPLATE];
prmTemplate[ROP_VPT_PRERENDER] = theRopTemplates[ROP_PRERENDER_TPLATE];
Expand Down Expand Up @@ -159,6 +162,7 @@ ROP_RENDER_CODE VPT_INS_ROP::renderFrame(fpreal time, UT_Interrupt *)

SOP_Node *sop;
UT_String soppath, savepath, name;
bool render_light;

OUTPUT(savepath, time);

Expand Down Expand Up @@ -212,7 +216,10 @@ ROP_RENDER_CODE VPT_INS_ROP::renderFrame(fpreal time, UT_Interrupt *)
ROP_Node::makeFilePathDirs(savepath);
}

file_save(gdp, (const char *)savepath);
render_light = LIGHT();

if (render_light) light_save(gdp, (const char*)savepath);
else file_save(gdp, (const char *)savepath);

if (ALFPROGRESS() && (endTime != startTime))
{
Expand Down
2 changes: 2 additions & 0 deletions instancer_hda/ROP_VPT_Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace vpt_instance {
ROP_VPT_TRANGE,
ROP_VPT_FRANGE,
ROP_VPT_TAKE,
ROP_VPT_LIGHT,
ROP_VPT_SOPPATH,
ROP_VPT_SOPOUTPUT,

Expand Down Expand Up @@ -130,6 +131,7 @@ namespace vpt_instance {
virtual ROP_RENDER_CODE endRender();

private:
int LIGHT() { return evalInt("render_light", 0 , 0 ); }
void OUTPUT(UT_String &str, fpreal t) { return evalString(str, "outputFile", 0, t); }
void SOPPATH(UT_String &str, fpreal t) { return evalString(str, "soppath", 0, t); }
int INITSIM() { return evalInt("initsim", 0, 0); }
Expand Down
37 changes: 37 additions & 0 deletions instancer_hda/file_IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,42 @@ namespace vpt_instance {

}

GA_Detail::IOStatus light_save(const GU_Detail *gdp, const char *file_name) {

UT_OFStream file(file_name);

GA_ROHandleV3 pos_h(gdp, GA_ATTRIB_POINT, "P");
UT_Vector3F pos_val(0, 0, 0);
GA_ROHandleV3 Cd_h(gdp, GA_ATTRIB_POINT, "Cd");
GA_ROHandleF power_h(gdp, GA_ATTRIB_POINT, "power");


file << "light" << std::endl;

GA_Offset lcl_start, lcl_end, ptoff;
for (GA_Iterator lcl_it(gdp->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) {
for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff) {

pos_val = pos_h.get(ptoff);

file << pos_val.x() << " " << pos_val.y() << " " << pos_val.z() << " ";
if (Cd_h.isValid()) {
UT_Vector3F Cd = Cd_h.get(ptoff);
file << Cd.r() << " " << Cd.g() << " " << Cd.b() << " ";
}else file << 1 << " " << 1 << " " << 1 << " ";

if (power_h.isValid()) {
file << power_h.get(ptoff) << std::endl;
}else file << 100 << std::endl;

}
}


file.close();
return true;

}


}
1 change: 1 addition & 0 deletions instancer_hda/file_IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace vpt_instance {


GA_Detail::IOStatus file_save(const GU_Detail *gdp, const char *file_name);
GA_Detail::IOStatus light_save(const GU_Detail *gdp, const char *file_name);


}
Expand Down

0 comments on commit 29e6831

Please sign in to comment.