Skip to content
Merged
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
79 changes: 79 additions & 0 deletions include/IECoreMaya/ToMayaCurveConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, 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.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IE_COREMAYA_TOMAYACURVECONVERTER_H
#define IE_COREMAYA_TOMAYACURVECONVERTER_H

#include "IECore/CurvesPrimitive.h"
#include "IECore/NumericParameter.h"

#include "IECoreMaya/ToMayaObjectConverter.h"

namespace IECoreMaya
{

class ToMayaCurveConverter;
IE_CORE_DECLAREPTR( ToMayaCurveConverter );

/// This class converts IECore::CurvesPrimitives to maya curve objects.
/// \ingroup conversionGroup
class ToMayaCurveConverter : public ToMayaObjectConverter
{
public:

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( ToMayaCurveConverter, ToMayaCurveConverterTypeId, ToMayaObjectConverter );

ToMayaCurveConverter( IECore::ConstObjectPtr object );

IECore::IntParameterPtr indexParameter();
IECore::ConstIntParameterPtr indexParameter() const;

protected:

/// Converts one of the curves in srcParameter() to a maya curve. The curve it converts
/// is specified by indexParameter() (named "index")
virtual bool doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const;

typedef ToMayaObjectConverterDescription<ToMayaCurveConverter> Description;
static Description g_curvesDataDescription;
static Description g_curvesDescription;

private:

IECore::IntParameterPtr m_indexParameter;
};

}

#endif // IE_COREMAYA_TOMAYACURVECONVERTER_H
1 change: 1 addition & 0 deletions include/IECoreMaya/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum TypeId
FromMayaProceduralHolderConverterTypeId = 109073,
FromMayaLocatorConverterTypeId = 109074,
ToMayaLocatorConverterTypeId = 109075,
ToMayaCurveConverterTypeId = 109076,
// Remember to update TypeIdBinding.cpp
LastTypeId = 109999
};
Expand Down
45 changes: 45 additions & 0 deletions include/IECoreMaya/bindings/ToMayaCurveConverterBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, 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.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECOREMAYA_TOMAYACURVECONVERTERBINDING_H
#define IECOREMAYA_TOMAYACURVECONVERTERBINDING_H

namespace IECoreMaya
{

void bindToMayaCurveConverter();

}

#endif // IECOREMAYA_TOMAYACURVECONVERTERBINDING_H
2 changes: 1 addition & 1 deletion src/IECoreMaya/FromMayaCurveConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2011, Image Engine Design Inc. All rights reserved.
// Copyright (c) 2008-2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down
175 changes: 175 additions & 0 deletions src/IECoreMaya/ToMayaCurveConverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, 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.
//
//////////////////////////////////////////////////////////////////////////

#include <cassert>

#include "boost/format.hpp"

#include "maya/MFnNurbsCurve.h"
#include "maya/MPointArray.h"
#include "maya/MDoubleArray.h"

#include "IECore/CurvesPrimitive.h"
#include "IECore/PrimitiveVariable.h"
#include "IECore/MessageHandler.h"
#include "IECore/CompoundParameter.h"

#include "IECoreMaya/Convert.h"
#include "IECoreMaya/ToMayaCurveConverter.h"

using namespace IECoreMaya;

ToMayaCurveConverter::Description ToMayaCurveConverter::g_curvesDataDescription( IECore::CurvesPrimitive::staticTypeId(), MFn::kNurbsCurveData );
ToMayaCurveConverter::Description ToMayaCurveConverter::g_curvesDescription( IECore::CurvesPrimitive::staticTypeId(), MFn::kNurbsCurve );

ToMayaCurveConverter::ToMayaCurveConverter( IECore::ConstObjectPtr object )
: ToMayaObjectConverter( "Converts IECore::CurvesPrimitive objects to a Maya object.", object)
{
m_indexParameter = new IECore::IntParameter( "index", "The index of the curve to be converted.", 0 );
parameters()->addParameter( m_indexParameter );
}


IECore::IntParameterPtr ToMayaCurveConverter::indexParameter()
{
return m_indexParameter;
}

IECore::ConstIntParameterPtr ToMayaCurveConverter::indexParameter() const
{
return m_indexParameter;
}

bool ToMayaCurveConverter::doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const
{
MStatus s;

IECore::ConstCurvesPrimitivePtr curves = IECore::runTimeCast<const IECore::CurvesPrimitive>( from );

assert( curves );

if ( !curves->arePrimitiveVariablesValid() || !curves->numCurves() )
{
return false;
}

int curveIndex = indexParameter()->getNumericValue();
if( curveIndex < 0 || curveIndex >= (int)curves->numCurves() )
{
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", boost::format( "Invalid curve index \"%d\"") % curveIndex );
return false;
}

IECore::ConstV3fVectorDataPtr p = curves->variableData< IECore::V3fVectorData >( "P", IECore::PrimitiveVariable::Vertex );
if( !p )
{
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", "Curve has no \"P\" data" );
return false;

}

const std::vector<int>& verticesPerCurve = curves->verticesPerCurve()->readable();
int curveBase = 0;
for( int i=0; i<curveIndex; ++i )
{
curveBase += verticesPerCurve[i];
}

MPointArray vertexArray;

int numVertices = verticesPerCurve[curveIndex];

const std::vector<Imath::V3f>& pts = p->readable();

// triple up the start points for cubic periodic curves:
if( curves->periodic() && curves->basis() != IECore::CubicBasisf::linear() )
{
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[curveBase] ) );
vertexArray.append( vertexArray[0] );
}

for( int i = 0; i < numVertices; ++i )
{
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[i + curveBase] ) );
}

// if the curve is periodic, the first N cvs must be identical to the last N cvs, where N is the degree
// of the curve:
if( curves->periodic() )
{
if( curves->basis() == IECore::CubicBasisf::linear() )
{
// linear: N = 1
vertexArray.append( vertexArray[0] );
}
else
{
// cubic: N = 3
vertexArray.append( vertexArray[0] );
vertexArray.append( vertexArray[1] );
vertexArray.append( vertexArray[2] );
}
}

MDoubleArray knotSequences;
if( curves->basis() == IECore::CubicBasisf::linear() )
{
for( unsigned i=0; i < vertexArray.length(); ++i )
{
knotSequences.append( i );
}
}
else
{
// first two cvs must have coincident knots if the curve's open, otherwise
// they must be spaced out
knotSequences.append( curves->periodic() ? -1 : 0 );
for( unsigned i=0; i < vertexArray.length(); ++i )
{
knotSequences.append( i );
}
// same with the last two:
knotSequences.append( curves->periodic() ? vertexArray.length() : vertexArray.length() - 1 );
}

MFnNurbsCurve fnCurve;
fnCurve.create( vertexArray, knotSequences, curves->basis() == IECore::CubicBasisf::linear() ? 1 : 3, curves->periodic() ? MFnNurbsCurve::kPeriodic : MFnNurbsCurve::kOpen, false, false, to, &s );
if (!s)
{
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", s.errorString().asChar() );
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/IECoreMaya/bindings/IECoreMaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include "IECoreMaya/bindings/FromMayaSkinClusterConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaSkinClusterConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaMeshConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaCurveConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaGroupConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaParticleConverterBinding.h"
#include "IECoreMaya/bindings/ToMayaImageConverterBinding.h"
Expand Down Expand Up @@ -153,6 +154,7 @@ BOOST_PYTHON_MODULE(_IECoreMaya)
bindFromMayaSkinClusterConverter();
bindToMayaSkinClusterConverter();
bindToMayaMeshConverter();
bindToMayaCurveConverter();
bindToMayaGroupConverter();
bindToMayaParticleConverter();
bindToMayaImageConverter();
Expand Down
51 changes: 51 additions & 0 deletions src/IECoreMaya/bindings/ToMayaCurveConverterBinding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, 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.
//
//////////////////////////////////////////////////////////////////////////

#include "boost/python.hpp"

#include "IECoreMaya/ToMayaCurveConverter.h"
#include "IECoreMaya/bindings/ToMayaCurveConverterBinding.h"

#include "IECorePython/RunTimeTypedBinding.h"

using namespace IECore;
using namespace IECoreMaya;
using namespace boost::python;

void IECoreMaya::bindToMayaCurveConverter()
{
IECorePython::RunTimeTypedClass<ToMayaCurveConverter>()
.def( init<IECore::ConstObjectPtr>() )
;
}
1 change: 1 addition & 0 deletions src/IECoreMaya/bindings/TypeIdBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void bindTypeId()
.value( "ToMayaConverter", ToMayaConverterTypeId )
.value( "ToMayaObjectConverter", ToMayaObjectConverterTypeId )
.value( "ToMayaNumericDataConverter", ToMayaNumericDataConverterTypeId )
.value( "ToMayaCurveConverter", ToMayaCurveConverterTypeId )
.value( "ToMayaMeshConverter", ToMayaMeshConverterTypeId )
.value( "ToMayaArrayDataConverter", ToMayaArrayDataConverterTypeId )
.value( "ToMayaPlugConverter", ToMayaPlugConverterTypeId )
Expand Down
Loading