Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squashed nuke node #51

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@ ctlrender
-------------

Bill Elswick


Nuke_CTL

Developers:
-----------

Jonathan Grahamm

Contributors:
-------------

Ken Boreham

Joseph Goldstone
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 1.5.3:
* added Nuke_CTL

Version 1.5:
* added OpenEXR_CTL, ctlrender
* changed build system to Cmake
Expand Down
39 changes: 23 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project( CTL )

set( CTL_MAJOR_VERSION 1 )
set( CTL_MINOR_VERSION 5 )
set( CTL_PATCH_VERSION 0 )
set( CTL_PATCH_VERSION 3 )
set( CTL_VERSION ${CTL_MAJOR_VERSION}.${CTL_MINOR_VERSION}.${CTL_PATCH_VERSION} )

## Make install directories overrideable
Expand All @@ -18,21 +18,27 @@ else()
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Install directory for project CMake files" )

# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
#SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(CMAKE_MACOSX_RPATH TRUE)
# Don't set this at build time; set it at install time with each target's INSTALL_RPATH property
# (again, only on Darwin)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
ELSE()
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
#SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

## convert install paths to absolute
foreach( p LIB BIN INCLUDE CMAKE DOC)
Expand Down Expand Up @@ -63,6 +69,7 @@ add_subdirectory(doc)
add_subdirectory(lib)
add_subdirectory(ctlrender)
add_subdirectory(OpenEXR_CTL)
add_subdirectory(Nuke_CTL)
add_subdirectory(unittest EXCLUDE_FROM_ALL)

# Add all targets to the build-tree export set
Expand Down
57 changes: 57 additions & 0 deletions Nuke_CTL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

# NB: We use a fake component to indicate that we want to avoid
# the IlmBase / OpenEXR libraries in the Nuke folder itself
find_package(Nuke QUIET COMPONENTS AvoidNukeIlmBase)
if(NUKE_FOUND)
message( STATUS "NUKE API Version: ${NUKE_API_VERSION}" )
set( DEFAULT_PLUGIN_DIR "" )
if( "$ENV{NUKE_PATH}" STREQUAL "" )
set( DEFAULT_PLUGIN_DIR $ENV{HOME}/.nuke )
else()
set( DEFAULT_PLUGIN_DIR $ENV{NUKE_PATH} )
endif()

# The line below doesn't make sense for Nuke 8.0 or greater. The version-specific plugin dir is now
# /Library/Application Support/Nuke/8.0/plugins/ [for Mac OS X]
# /usr/local/Nuke/8.0/plugins/ [for linux]
# C:\Program Files\Common Files\Nuke\8.0\plugins or C:\Program Files (x86)\Common Files\Nuke\8.0\plugins [for Windows]
# set( DEFAULT_PLUGIN_DIR ${DEFAULT_PLUGIN_DIR}/plugins/${NUKE_API_VERSION} )

set( INSTALL_NUKE_PLUGIN_DIR ${DEFAULT_PLUGIN_DIR} CACHE PATH "Location to install Nuke plugins" )

if( NOT DEFINED INSTALL_NUKE_PLUGIN_DIR )
message(WARNING " No install path defined for nuke plugins
please define NUKE_PATH or INSTALL_NUKE_PLUGIN_DIR
skipping Nuke_CTL")
return()
else()
message(STATUS "Nuke plugins will be installed in ${INSTALL_NUKE_PLUGIN_DIR}")
message("Don't forget to add this path to your init.py file")
endif()

include_directories("${CMAKE_CURRENT_SOURCE_DIR}"
"${NUKE_INCLUDE_DIRS}"
"${PROJECT_SOURCE_DIR}/lib/IlmCtl"
"${PROJECT_SOURCE_DIR}/lib/IlmCtlMath"
"${PROJECT_SOURCE_DIR}/lib/IlmCtlSimd"
"${PROJECT_SOURCE_DIR}/lib/IlmImfCtl" )

add_library(NukeCtl SHARED
NukeCtl.cpp
NukeCtlUtils.cpp
NukeCtlChanArgMap.cpp
NukeCtlTransform.cpp
)

set_target_properties(NukeCtl PROPERTIES PREFIX "")
set_target_properties(NukeCtl PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

target_link_libraries( NukeCtl IlmCtl IlmCtlMath IlmCtlSimd IlmThread Half Iex )
target_link_libraries( NukeCtl ${IlmBase_LIBRARIES} ${IlmBase_LDFLAGS_OTHER} )
link_directories( ${NUKE_LIBRARY_DIR} )
target_link_libraries( NukeCtl ${NUKE_LIBRARIES} )

install( TARGETS NukeCtl DESTINATION ${INSTALL_NUKE_PLUGIN_DIR} )
else()
message( WARNING "NUKE not found, check NUKE_INSTALL_PATH setting or NDKDIR env. var, NukeCTL plugin disabled" )
endif()
235 changes: 235 additions & 0 deletions Nuke_CTL/NukeCtl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014 Academy of Motion Picture Arts and Sciences
// ("A.M.P.A.S."). Portions contributed by others as indicated.
// All rights reserved.
//
// A worldwide, royalty-free, non-exclusive right to copy, modify, create
// derivatives, and use, in source and binary forms, is hereby granted,
// subject to acceptance of this license. Performance of any of the
// aforementioned acts indicates acceptance to be bound by the following
// terms and conditions:
//
// * Copies of source code, in whole or in part, must retain the
// above copyright notice, this list of conditions and the
// Disclaimer of Warranty.
//
// * Use in binary form must retain the above copyright notice,
// this list of conditions and the Disclaimer of Warranty in the
// documentation and/or other materials provided with the distribution.
//
// * Nothing in this license shall be deemed to grant any rights to
// trademarks, copyrights, patents, trade secrets or any other
// intellectual property of A.M.P.A.S. or any contributors, except
// as expressly stated herein.
//
// * Neither the name "A.M.P.A.S." nor the name of any other
// contributors to this software may be used to endorse or promote
// products derivative of or based on this software without express
// prior written permission of A.M.P.A.S. or the contributors, as
// appropriate.
//
// This license shall be construed pursuant to the laws of the State of
// California, and any disputes related thereto shall be subject to the
// jurisdiction of the courts therein.
//
// Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO
// EVENT SHALL A.M.P.A.S., OR ANY CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, RESITUTIONARY,
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
// WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY
// SPECIFICALLY DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER
// RELATED TO PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY
// COLOR ENCODING SYSTEM, OR APPLICATIONS THEREOF, HELD BY PARTIES OTHER
// THAN A.M.P.A.S., WHETHER DISCLOSED OR UNDISCLOSED.
///////////////////////////////////////////////////////////////////////////

const char* const HELP =
"<p>Applies Ctl transforms onto an image.</p>";

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif

#include "DDImage/PixelIop.h"
#include "DDImage/Row.h"
#include "DDImage/Knobs.h"
#include "DDImage/NukeWrapper.h"

#include "NukeCtlUtils.h"
#include "NukeCtlTransform.h"

#include "Iex.h"

#ifdef __clang__
#pragma clang diagnostic pop
#endif

using namespace DD::Image;
using namespace Iex;
using namespace std;
using namespace NukeCtl;

static const char* const CLASS = "NukeCtl";

class NukeCtlIop : public PixelIop {

private:
DD::Image::Knob* modulePathEnabledKnob;
DD::Image::Knob* modulePathKnob;
DD::Image::Knob* readKnob;
bool modulePathEnabled;
const char *modulePath;
const char *ctlPath;
NukeCtl::Transform* transform;
int reloadCount;
public:

NukeCtlIop(Node* node) : PixelIop(node),
modulePathEnabled(false), modulePath(""), ctlPath(""),
transform(NULL), reloadCount(0) {
}

static const Iop::Description d;
void in_channels(int input_number, ChannelSet& channels) const {
channels = Mask_RGBA;
}

void append(Hash& h) {
h.append(__DATE__);
h.append(__TIME__);
}

void expand_ctl_path(std::string& file) {
if (script_expand(knob("ctl_path")->get_text(&outputContext())) && script_result())
file = script_result();
else
file = "";
script_unlock();
}

void pixel_engine(const Row &in, int y, int x, int r, ChannelMask, Row &);
void knobs(Knob_Callback);
void load_transform(const char* const modulePath, const char* const ctlPath);
int knob_changed(Knob*);
const char* Class() const { return CLASS; }
const char* node_help() const { return HELP; }
void _validate(bool);
};

void NukeCtlIop::_validate(bool for_real) {
set_out_channels(Mask_RGBA);
PixelIop::_validate(for_real);
}

// Called on each scanline
void NukeCtlIop::pixel_engine(const Row& in, int y, int x, int r, ChannelMask channels, Row& out) {
if (transform != NULL)
{
try {
transform->execute(in, x, r, out);
}
catch (const BaseExc& e) {
error("Could not execute CTL argument transform: %s", e.what());
}
catch (const exception& e) {
error("Could not execute CTL argument transform: %s", e.what());
}
catch (...) // Something wicked this way comes
{
error("Could not execute CTL argument transform");
}
}
else
{
out.copy(in, channels, x, r);
}
}

void NukeCtlIop::load_transform(const char* const modulePath, const char* const ctlPath)
{
try
{
if (transform != NULL)
{
delete transform;
transform = NULL;
}
transform = new NukeCtl::Transform(modulePath, ctlPath);
}
catch (const Iex::BaseExc& e)
{
error((string("Error instantiating CTL transform: ") + e.what()).c_str());
}
catch (const exception& e)
{
error((string("Error instantiating CTL transform: ") + e.what()).c_str());
}
catch (...)
{
error("Error instantiating CTL transform");
}
}

void NukeCtlIop::knobs(Knob_Callback f) {
Newline(f, "Module Path");
modulePathEnabledKnob = Bool_knob(f, &modulePathEnabled, "enable_module_path", "");
modulePathKnob = File_knob(f, &modulePath, "module_path", "");
ClearFlags(f, Knob::STARTLINE);
readKnob = File_knob(f, &ctlPath, "ctl_path", "CTL file Path");
SetFlags(f, Knob::EARLY_STORE);
SetFlags(f, Knob::KNOB_CHANGED_ALWAYS);
Script_knob(f, "knob reload_count [expr [value reload_count] + 1]", "reload");
Int_knob(f, &reloadCount, "reload_count", INVISIBLE);
SetFlags(f, Knob::DO_NOT_WRITE);
Divider(f);
}

// Knob state changed
int NukeCtlIop::knob_changed(Knob *k) {

if (k == &Knob::showPanel) {
knob("module_path")->enable(modulePathEnabled);
return 1;
}

// if the box is checked, enable or disable the set module knob
if (k->is("enable_module_path")) {
knob("module_path")->enable(modulePathEnabled);
return 1;
}

// if the module path is changed, make sure it is valid
if (k->is("module_path")) {
std::string file;
expand_ctl_path(file);
if (!file.empty())
load_transform(modulePath, file.c_str());
return 1;
}

if (k->is("ctl_path") || k->is("reload")) {
std::string file;
expand_ctl_path(file);
if (!file.empty())
load_transform(modulePath, file.c_str());
return 1;
}
return Iop::knob_changed(k);
}

static Iop* build(Node* node) {
return (new NukeWrapper(new NukeCtlIop(node)));
}

const Iop::Description NukeCtlIop::d(CLASS, "Color/NukeCtl", build);

Loading