From 29e6831fa7348e9f63c7fac8e1a505936d9a8586 Mon Sep 17 00:00:00 2001 From: Sergen Eren Date: Sun, 5 Jan 2020 17:02:59 +0300 Subject: [PATCH] point light instance writer for instancer_hda --- instancer_hda/ROP_VPT_Instance.cpp | 13 ++++++++--- instancer_hda/ROP_VPT_Instance.h | 2 ++ instancer_hda/file_IO.cpp | 37 ++++++++++++++++++++++++++++++ instancer_hda/file_IO.h | 1 + 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/instancer_hda/ROP_VPT_Instance.cpp b/instancer_hda/ROP_VPT_Instance.cpp index 5495677..5eab595 100644 --- a/instancer_hda/ROP_VPT_Instance.cpp +++ b/instancer_hda/ROP_VPT_Instance.cpp @@ -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 }; @@ -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]; @@ -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); @@ -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)) { diff --git a/instancer_hda/ROP_VPT_Instance.h b/instancer_hda/ROP_VPT_Instance.h index 324545e..9855551 100644 --- a/instancer_hda/ROP_VPT_Instance.h +++ b/instancer_hda/ROP_VPT_Instance.h @@ -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, @@ -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); } diff --git a/instancer_hda/file_IO.cpp b/instancer_hda/file_IO.cpp index cddaced..9fa0917 100644 --- a/instancer_hda/file_IO.cpp +++ b/instancer_hda/file_IO.cpp @@ -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; + + } + } \ No newline at end of file diff --git a/instancer_hda/file_IO.h b/instancer_hda/file_IO.h index 081090c..76fdf21 100644 --- a/instancer_hda/file_IO.h +++ b/instancer_hda/file_IO.h @@ -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); }