Skip to content

Commit 31de945

Browse files
committed
Merge pull request #199 from davidsminor/toMayaCurvesConverter
added ToMayaCurvesConverter
2 parents d642035 + c644cd5 commit 31de945

File tree

10 files changed

+538
-1
lines changed

10 files changed

+538
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IE_COREMAYA_TOMAYACURVECONVERTER_H
36+
#define IE_COREMAYA_TOMAYACURVECONVERTER_H
37+
38+
#include "IECore/CurvesPrimitive.h"
39+
#include "IECore/NumericParameter.h"
40+
41+
#include "IECoreMaya/ToMayaObjectConverter.h"
42+
43+
namespace IECoreMaya
44+
{
45+
46+
class ToMayaCurveConverter;
47+
IE_CORE_DECLAREPTR( ToMayaCurveConverter );
48+
49+
/// This class converts IECore::CurvesPrimitives to maya curve objects.
50+
/// \ingroup conversionGroup
51+
class ToMayaCurveConverter : public ToMayaObjectConverter
52+
{
53+
public:
54+
55+
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( ToMayaCurveConverter, ToMayaCurveConverterTypeId, ToMayaObjectConverter );
56+
57+
ToMayaCurveConverter( IECore::ConstObjectPtr object );
58+
59+
IECore::IntParameterPtr indexParameter();
60+
IECore::ConstIntParameterPtr indexParameter() const;
61+
62+
protected:
63+
64+
/// Converts one of the curves in srcParameter() to a maya curve. The curve it converts
65+
/// is specified by indexParameter() (named "index")
66+
virtual bool doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const;
67+
68+
typedef ToMayaObjectConverterDescription<ToMayaCurveConverter> Description;
69+
static Description g_curvesDataDescription;
70+
static Description g_curvesDescription;
71+
72+
private:
73+
74+
IECore::IntParameterPtr m_indexParameter;
75+
};
76+
77+
}
78+
79+
#endif // IE_COREMAYA_TOMAYACURVECONVERTER_H

include/IECoreMaya/TypeIds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ enum TypeId
120120
FromMayaProceduralHolderConverterTypeId = 109073,
121121
FromMayaLocatorConverterTypeId = 109074,
122122
ToMayaLocatorConverterTypeId = 109075,
123+
ToMayaCurveConverterTypeId = 109076,
123124
// Remember to update TypeIdBinding.cpp
124125
LastTypeId = 109999
125126
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREMAYA_TOMAYACURVECONVERTERBINDING_H
36+
#define IECOREMAYA_TOMAYACURVECONVERTERBINDING_H
37+
38+
namespace IECoreMaya
39+
{
40+
41+
void bindToMayaCurveConverter();
42+
43+
}
44+
45+
#endif // IECOREMAYA_TOMAYACURVECONVERTERBINDING_H

src/IECoreMaya/FromMayaCurveConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2008-2011, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2008-2013, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#include <cassert>
36+
37+
#include "boost/format.hpp"
38+
39+
#include "maya/MFnNurbsCurve.h"
40+
#include "maya/MPointArray.h"
41+
#include "maya/MDoubleArray.h"
42+
43+
#include "IECore/CurvesPrimitive.h"
44+
#include "IECore/PrimitiveVariable.h"
45+
#include "IECore/MessageHandler.h"
46+
#include "IECore/CompoundParameter.h"
47+
48+
#include "IECoreMaya/Convert.h"
49+
#include "IECoreMaya/ToMayaCurveConverter.h"
50+
51+
using namespace IECoreMaya;
52+
53+
ToMayaCurveConverter::Description ToMayaCurveConverter::g_curvesDataDescription( IECore::CurvesPrimitive::staticTypeId(), MFn::kNurbsCurveData );
54+
ToMayaCurveConverter::Description ToMayaCurveConverter::g_curvesDescription( IECore::CurvesPrimitive::staticTypeId(), MFn::kNurbsCurve );
55+
56+
ToMayaCurveConverter::ToMayaCurveConverter( IECore::ConstObjectPtr object )
57+
: ToMayaObjectConverter( "Converts IECore::CurvesPrimitive objects to a Maya object.", object)
58+
{
59+
m_indexParameter = new IECore::IntParameter( "index", "The index of the curve to be converted.", 0 );
60+
parameters()->addParameter( m_indexParameter );
61+
}
62+
63+
64+
IECore::IntParameterPtr ToMayaCurveConverter::indexParameter()
65+
{
66+
return m_indexParameter;
67+
}
68+
69+
IECore::ConstIntParameterPtr ToMayaCurveConverter::indexParameter() const
70+
{
71+
return m_indexParameter;
72+
}
73+
74+
bool ToMayaCurveConverter::doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const
75+
{
76+
MStatus s;
77+
78+
IECore::ConstCurvesPrimitivePtr curves = IECore::runTimeCast<const IECore::CurvesPrimitive>( from );
79+
80+
assert( curves );
81+
82+
if ( !curves->arePrimitiveVariablesValid() || !curves->numCurves() )
83+
{
84+
return false;
85+
}
86+
87+
int curveIndex = indexParameter()->getNumericValue();
88+
if( curveIndex < 0 || curveIndex >= (int)curves->numCurves() )
89+
{
90+
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", boost::format( "Invalid curve index \"%d\"") % curveIndex );
91+
return false;
92+
}
93+
94+
IECore::ConstV3fVectorDataPtr p = curves->variableData< IECore::V3fVectorData >( "P", IECore::PrimitiveVariable::Vertex );
95+
if( !p )
96+
{
97+
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", "Curve has no \"P\" data" );
98+
return false;
99+
100+
}
101+
102+
const std::vector<int>& verticesPerCurve = curves->verticesPerCurve()->readable();
103+
int curveBase = 0;
104+
for( int i=0; i<curveIndex; ++i )
105+
{
106+
curveBase += verticesPerCurve[i];
107+
}
108+
109+
MPointArray vertexArray;
110+
111+
int numVertices = verticesPerCurve[curveIndex];
112+
113+
const std::vector<Imath::V3f>& pts = p->readable();
114+
115+
// triple up the start points for cubic periodic curves:
116+
if( curves->periodic() && curves->basis() != IECore::CubicBasisf::linear() )
117+
{
118+
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[curveBase] ) );
119+
vertexArray.append( vertexArray[0] );
120+
}
121+
122+
for( int i = 0; i < numVertices; ++i )
123+
{
124+
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[i + curveBase] ) );
125+
}
126+
127+
// if the curve is periodic, the first N cvs must be identical to the last N cvs, where N is the degree
128+
// of the curve:
129+
if( curves->periodic() )
130+
{
131+
if( curves->basis() == IECore::CubicBasisf::linear() )
132+
{
133+
// linear: N = 1
134+
vertexArray.append( vertexArray[0] );
135+
}
136+
else
137+
{
138+
// cubic: N = 3
139+
vertexArray.append( vertexArray[0] );
140+
vertexArray.append( vertexArray[1] );
141+
vertexArray.append( vertexArray[2] );
142+
}
143+
}
144+
145+
MDoubleArray knotSequences;
146+
if( curves->basis() == IECore::CubicBasisf::linear() )
147+
{
148+
for( unsigned i=0; i < vertexArray.length(); ++i )
149+
{
150+
knotSequences.append( i );
151+
}
152+
}
153+
else
154+
{
155+
// first two cvs must have coincident knots if the curve's open, otherwise
156+
// they must be spaced out
157+
knotSequences.append( curves->periodic() ? -1 : 0 );
158+
for( unsigned i=0; i < vertexArray.length(); ++i )
159+
{
160+
knotSequences.append( i );
161+
}
162+
// same with the last two:
163+
knotSequences.append( curves->periodic() ? vertexArray.length() : vertexArray.length() - 1 );
164+
}
165+
166+
MFnNurbsCurve fnCurve;
167+
fnCurve.create( vertexArray, knotSequences, curves->basis() == IECore::CubicBasisf::linear() ? 1 : 3, curves->periodic() ? MFnNurbsCurve::kPeriodic : MFnNurbsCurve::kOpen, false, false, to, &s );
168+
if (!s)
169+
{
170+
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", s.errorString().asChar() );
171+
return false;
172+
}
173+
174+
return true;
175+
}

src/IECoreMaya/bindings/IECoreMaya.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "IECoreMaya/bindings/FromMayaSkinClusterConverterBinding.h"
8686
#include "IECoreMaya/bindings/ToMayaSkinClusterConverterBinding.h"
8787
#include "IECoreMaya/bindings/ToMayaMeshConverterBinding.h"
88+
#include "IECoreMaya/bindings/ToMayaCurveConverterBinding.h"
8889
#include "IECoreMaya/bindings/ToMayaGroupConverterBinding.h"
8990
#include "IECoreMaya/bindings/ToMayaParticleConverterBinding.h"
9091
#include "IECoreMaya/bindings/ToMayaImageConverterBinding.h"
@@ -153,6 +154,7 @@ BOOST_PYTHON_MODULE(_IECoreMaya)
153154
bindFromMayaSkinClusterConverter();
154155
bindToMayaSkinClusterConverter();
155156
bindToMayaMeshConverter();
157+
bindToMayaCurveConverter();
156158
bindToMayaGroupConverter();
157159
bindToMayaParticleConverter();
158160
bindToMayaImageConverter();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#include "boost/python.hpp"
36+
37+
#include "IECoreMaya/ToMayaCurveConverter.h"
38+
#include "IECoreMaya/bindings/ToMayaCurveConverterBinding.h"
39+
40+
#include "IECorePython/RunTimeTypedBinding.h"
41+
42+
using namespace IECore;
43+
using namespace IECoreMaya;
44+
using namespace boost::python;
45+
46+
void IECoreMaya::bindToMayaCurveConverter()
47+
{
48+
IECorePython::RunTimeTypedClass<ToMayaCurveConverter>()
49+
.def( init<IECore::ConstObjectPtr>() )
50+
;
51+
}

src/IECoreMaya/bindings/TypeIdBinding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void bindTypeId()
6565
.value( "ToMayaConverter", ToMayaConverterTypeId )
6666
.value( "ToMayaObjectConverter", ToMayaObjectConverterTypeId )
6767
.value( "ToMayaNumericDataConverter", ToMayaNumericDataConverterTypeId )
68+
.value( "ToMayaCurveConverter", ToMayaCurveConverterTypeId )
6869
.value( "ToMayaMeshConverter", ToMayaMeshConverterTypeId )
6970
.value( "ToMayaArrayDataConverter", ToMayaArrayDataConverterTypeId )
7071
.value( "ToMayaPlugConverter", ToMayaPlugConverterTypeId )

0 commit comments

Comments
 (0)