void EndChunck() // fonction pour écrire une longueur par rapport à position actuelle dans le fichier
{

	


		int temp = posfichier.length()-1;
		info = "end position : ";
		info += temp;
		
		
				info += " address : ";
		info += posfichier[temp];

	

		//EndChunck(posfichier[temp-1]);
			int pos_new = ::output.tellp();//retient la position actuelle
	int size = pos_new - posfichier[temp];// détermine la longueur
	size -= 4 ; // pour les 4 premiers octets
	::output.seekp(posfichier[temp]);// se place à la position indiqué
	write_int(size);// écrit la longueur
	::output.seekp(pos_new);// se repositionne à la position transmise
		
		info += " taille : ";
		info += size;

		//MGlobal::displayInfo(info);
		
		
		posfichier.remove(temp);

}
Exemple #2
0
//
// Intersect the current face list with the one provided, keep only the common elements
// 
void meshMapUtils::intersectArrays( MIntArray& selection, MIntArray& moreFaces )
{
	int j = selection.length() - 1;
	while ( j >= 0 )
	{
		bool found = false;;

		// For each item in moreFaces, try find it in fSelectedFaces
		for( unsigned int i = 0 ; i < moreFaces.length(); i++ )
		{
			if( selection[j] == moreFaces[i] )
			{
				found = true;
				break;
			}
		}	

		if( !found )
		{
			selection.remove(j);
		}

		j--;
	}
}
// ----------------------------------------
bool GeometryPolygonExporter::getPolygonVertexCount(
    MItMeshPolygon &meshPolygonsIter,
    unsigned long &numVertices )
{
    bool addVertexCount = false;

    // Establish the number of vertexes in the polygon.
    // We don't need the vertex count list for triangulation
    if ( triangulated ) return addVertexCount;

    // The number of vertices
    numVertices = 0;

    // Retrieve the vertices and increment polygon count
    // Get the number of vertices in the current mesh's polygon
    unsigned long polygonVertexCount = meshPolygonsIter.polygonVertexCount();
    if ( polygonVertexCount >= 3 )
    {
#ifdef VALIDATE_DATA
        // Skip over any duplicate vertices in this face.
        // Very rarely, a cunning user manages to corrupt
        // a face entry on the mesh and somehow configure
        // a face to include the same vertex multiple times.
        // This will cause the read-back of this data to
        // reject the face, and can crash other COLLADA
        // consumers, so better to lose the data here
        MIntArray vertexIndices;
        vertexIndices.setLength ( polygonVertexCount );
        for ( int pv = 0; pv < polygonVertexCount; ++pv )
        {
            vertexIndices[pv] = pv;
        }

        for ( uint n = 0; n < vertexIndices.length() - 1; ++n )
        {
            for ( uint m = n + 1; m < vertexIndices.length(); )
            {
                if ( vertexIndices[n] == vertexIndices[m] )
                {
                    vertexIndices.remove ( m );
                }
                else ++m;
            }
        }
        // Get the number of vertices of the current polygon.
        numVertices = vertexIndices.length();
#else
        // Get the number of vertices of the current polygon.
        numVertices = polygonVertexCount;
#endif

        addVertexCount = true;
    }

    return addVertexCount;
}
MStatus SelectRingToolCmd2::redoIt()
{	
	//MGlobal::displayInfo( "redoIt" );

	MItMeshPolygon polyIter( selEdgeObject );
	MItMeshEdge edgeIter( selEdgeObject, selEdgeComp );

	//MFnSingleIndexedComponent si( selEdgeComp );
	//MGlobal::displayInfo( MString("doing stuff on ") + selEdgeObject.fullPathName() + " " + si.element(0) );
	
	MFnSingleIndexedComponent indexedCompFn;
	MObject newComponent;		
	MSelectionList newSel;
	MIntArray edges;
	MIntArray faces;
	unsigned int i;
	const int initEdgeIndex = edgeIter.index();
	int initFaceIndex;
	int prevIndex, lastIndex;
	int faceIndex, edgeIndex;
	int newFaceIndex, newEdgeIndex;
	int nInitEdgeVisits;
	
	MIntArray remainFaces;
	MIntArray remainEdges;
	
	if( selType == RING )
	{
		nInitEdgeVisits = 0;
		
		// Push the face+edge combo on both sides 
		// of the current edge onto the stack
		edgeIter.getConnectedFaces( faces );
		if( faces.length() > 1 )
		{
			remainFaces.append( faces[1] );
			remainEdges.append( initEdgeIndex );
		}
		initFaceIndex = faces[0];
		remainFaces.append( initFaceIndex );
		remainEdges.append( initEdgeIndex );
		
		while( remainFaces.length() )
		{
			// Pop the face and edge indices
			lastIndex = remainFaces.length() - 1;
			faceIndex = remainFaces[ lastIndex ];
			edgeIndex = remainEdges[ lastIndex ];
			remainFaces.remove( lastIndex );
			remainEdges.remove( lastIndex );
			
			// If the current edge the initial edge
			if( faceIndex == initFaceIndex && 
				edgeIndex == initEdgeIndex )
			{
				// Reached back to the initial edge, so the loop is closed
				if( ++nInitEdgeVisits == 2 )
					break;
			}
			
			// Add edge to the new selection list
			if( selEdges )
			{
				newComponent = indexedCompFn.create( MFn::kMeshEdgeComponent );
				indexedCompFn.addElement( edgeIndex );
				newSel.add( selEdgeObject, newComponent );
			}
			
			// Add vertices to the new selection list
			if( selVertices )
			{
				newComponent = indexedCompFn.create( MFn::kMeshVertComponent );
				edgeIter.setIndex( edgeIndex, prevIndex );
				indexedCompFn.addElement( edgeIter.index(0) );
				indexedCompFn.addElement( edgeIter.index(1) );
				newSel.add( selEdgeObject, newComponent );
			}
			
			if( faceIndex != -1 ) // Not a boundary edge
			{
				// Add face to the new selection list
				if( selFaces )
				{
					newComponent = indexedCompFn.create( MFn::kMeshPolygonComponent );
					indexedCompFn.addElement( faceIndex );
					newSel.add( selEdgeObject, newComponent );		
				}
				
				// Get edge opposite the current edge
				//
				newEdgeIndex = navigateFace( selEdgeObject, faceIndex, 
											 edgeIndex, OPPOSITE );
				
				// Get the face on the other side of the opposite edge
				//
				edgeIter.setIndex( newEdgeIndex, prevIndex );
				edgeIter.getConnectedFaces( faces );
				
				newFaceIndex = -1; // Initialize to a boundary edge
				if( faces.length() > 1 )
					newFaceIndex = (faceIndex == faces[0]) ? 
									faces[1] : faces[0];
									
				// Push face and edge onto list
				remainFaces.append( newFaceIndex );
				remainEdges.append( newEdgeIndex );
			}
		}
	}
	else // Ring
	{
		int reflEdgeIndex;
		int newReflEdgeIndex;
		int initReflEdgeIndex;
		MIntArray remainReflEdges;
		
		nInitEdgeVisits = 0;
		
		// Push the face+edge+reflect combo on both sides 
		// of the current edge onto the stack
		//edgeIter.setIndex( initEdgeIndex, prevIndex );
		edgeIter.getConnectedFaces( faces );
		initFaceIndex = faces[0];
		for( i=0; i < 2; i++ )
		{
			remainFaces.append( initFaceIndex );
			remainEdges.append( initEdgeIndex );
			remainReflEdges.append(
				navigateFace( selEdgeObject, initFaceIndex, initEdgeIndex, 
							(i == 0) ? PREVIOUS : NEXT ) );
		}				
		initReflEdgeIndex = remainReflEdges[1];
				
		while( remainFaces.length() )
		{
			// Pop the face, edge, and reflEdge indices
			lastIndex = remainFaces.length() - 1;
			faceIndex = remainFaces[ lastIndex ];
			edgeIndex = remainEdges[ lastIndex ];
			reflEdgeIndex = remainReflEdges[ lastIndex ];
			remainFaces.remove( lastIndex );
			remainEdges.remove( lastIndex );
			remainReflEdges.remove( lastIndex );
									
			//MGlobal::displayInfo( MString("Face: ") + faceIndex + " edge: " + edgeIndex + " reflEdgeIndex: " + reflEdgeIndex );
		
			// If the current edge the initial edge
			if( faceIndex == initFaceIndex && 
				edgeIndex == initEdgeIndex &&
				reflEdgeIndex == initReflEdgeIndex )
			{
				// Reached back to the initial edge, so the ring is closed
				if( ++nInitEdgeVisits == 2 )
					break;
			}
										
			// Add edge to the new selection list
			if( selEdges )
			{
				newComponent = indexedCompFn.create( MFn::kMeshEdgeComponent );
				indexedCompFn.addElement( edgeIndex );
				newSel.add( selEdgeObject, newComponent );
			}
			
			// Add vertices to the new selection list
			if( selVertices )
			{
				newComponent = indexedCompFn.create( MFn::kMeshVertComponent );
				edgeIter.setIndex( edgeIndex, prevIndex );
				indexedCompFn.addElement( edgeIter.index(0) );
				indexedCompFn.addElement( edgeIter.index(1) );
				newSel.add( selEdgeObject, newComponent );
			}
			
			// Add face to the new selection list
			if( selFaces )
			{
				newComponent = indexedCompFn.create( MFn::kMeshPolygonComponent );
				indexedCompFn.addElement( faceIndex );
				newSel.add( selEdgeObject, newComponent );		
			}
			
			// Get the face on opposite side of reflEdge
			edgeIter.setIndex( reflEdgeIndex, prevIndex );
			edgeIter.getConnectedFaces( faces );

			// Only if there are two faces can their be an opposite face
			if( faces.length() > 1 )
			{
				newFaceIndex = (faceIndex == faces[0]) ?
								faces[1] : faces[0];			

				int edgePrev = navigateFace( selEdgeObject, newFaceIndex, reflEdgeIndex, PREVIOUS );
				int edgeNext = navigateFace( selEdgeObject, newFaceIndex, reflEdgeIndex, NEXT );
				
				// Determine which of the edges touches the original edge
				//
				edgeIter.setIndex( edgeIndex, prevIndex );
				if( edgeIter.connectedToEdge( edgePrev ) )
				{
					newEdgeIndex = edgePrev;
					newReflEdgeIndex = navigateFace( selEdgeObject, newFaceIndex, newEdgeIndex, PREVIOUS );
				}
				else
				{
					newEdgeIndex = edgeNext;
					newReflEdgeIndex = navigateFace( selEdgeObject, newFaceIndex, newEdgeIndex, NEXT );
				}
				
				// Push face, edge, and reflEdge onto list
				remainFaces.append( newFaceIndex );
				remainEdges.append( newEdgeIndex );
				remainReflEdges.append( newReflEdgeIndex );
			}
			
		}
	}	
		
	// Set the active selection to the one previous to edge loop selection
	MGlobal::setActiveSelectionList( prevSel, MGlobal::kReplaceList );

	// Update this selection based on the list adjustment setting
	MGlobal::selectCommand( newSel, listAdjust );

	return MS::kSuccess;	
}
// --------------------------------------------------------
void GeometryPolygonExporter::retrieveVertexIndices (
    MIntArray &vertexIndices,
    MItMeshPolygon &meshPolygonsIter,
    uint &numPolygons,
    uint &numVertices )
{
    // Get the number of vertices in the current mesh's polygon
    int polygonVertexCount = meshPolygonsIter.polygonVertexCount();
    if ( triangulated && polygonVertexCount > 3 )
    {
        int numTriangles;
        meshPolygonsIter.numTriangles ( numTriangles );
        if ( numTriangles > 0 )
        {
            numVertices = 3;
            MPointArray vertexPositions;
            MIntArray meshVertexIndices;
            meshPolygonsIter.getTriangles ( vertexPositions, meshVertexIndices );
            vertexIndices.setLength ( meshVertexIndices.length() );
            numPolygons = meshVertexIndices.length() / numVertices;

            // Map the vertex indices to iterator vertex indices so that we can
            // get information from the iterator about normals and such.
            uint meshVertexIndexCount = meshVertexIndices.length();
            for ( uint mvi = 0; mvi < meshVertexIndexCount; ++mvi )
            {
                int meshVertexIndex = meshVertexIndices[mvi];
                int polygonVertexCount = meshPolygonsIter.polygonVertexCount();
                int iteratorVertexIndex = 0;
                for ( int pv = 0; pv < polygonVertexCount; ++pv )
                {
                    if ( ( int ) meshPolygonsIter.vertexIndex ( pv ) == meshVertexIndex )
                    {
                        iteratorVertexIndex = pv;
                    }
                }
                vertexIndices[mvi] = iteratorVertexIndex;
            }
        }
        else numPolygons = 0;
    }
    else if ( polygonVertexCount >= 3 )
    {
        numPolygons = 1;
        vertexIndices.setLength ( polygonVertexCount );
        for ( int pv = 0; pv < polygonVertexCount; ++pv )
        {
            vertexIndices[pv] = pv;
        }

#ifdef VALIDATE_DATA
        // Skip over any duplicate vertices in this face.
        // Very rarely, a cunning user manages to corrupt
        // a face entry on the mesh and somehow configure
        // a face to include the same vertex multiple times.
        // This will cause the read-back of this data to
        // reject the face, and can crash other COLLADA
        // consumers, so better to lose the data here
        for ( uint n = 0; n < vertexIndices.length() - 1; ++n )            {
            for ( uint m = n + 1; m < vertexIndices.length(); )
            {
                if ( vertexIndices[n] == vertexIndices[m] )
                {
                    vertexIndices.remove ( m );
                }
                else ++m;
            }
        }
        // Get the number of vertices of the current polygon.
        numVertices = vertexIndices->length();
#else
        // Get the number of vertices of the current polygon.
        numVertices = polygonVertexCount;
#endif
    }
}
MStatus ColorSplineParameterHandler<S>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	assert( parameter );
	typename IECore::TypedParameter< S >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter< S > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MRampAttribute fnRAttr( plug );
	if ( !fnRAttr.isColorRamp() )
	{
		return MS::kFailure;
	}

	const S &spline = p->getTypedValue();

	MStatus s;
	MIntArray indicesToReuse;
	plug.getExistingArrayAttributeIndices( indicesToReuse, &s );
	assert( s );

	int nextNewLogicalIndex = 0;
	if( indicesToReuse.length() )
	{
		nextNewLogicalIndex = 1 + *std::max_element( MArrayIter<MIntArray>::begin( indicesToReuse ), MArrayIter<MIntArray>::end( indicesToReuse ) );
	}
	
	assert( indicesToReuse.length() == fnRAttr.getNumEntries() );

	size_t pointsSizeMinus2 = spline.points.size() - 2;
	unsigned pointIndex = 0;
	unsigned numExpectedPoints = 0;
	for ( typename S::PointContainer::const_iterator it = spline.points.begin(); it != spline.points.end(); ++it, ++pointIndex )
	{
		// we commonly double up the endpoints on cortex splines to force interpolation to the end.
		// maya does this implicitly, so we skip duplicated endpoints when passing the splines into maya.
		// this avoids users having to be responsible for managing the duplicates, and gives them some consistency
		// with the splines they edit elsewhere in maya.
		if( ( pointIndex==1 && *it == *spline.points.begin() ) || ( pointIndex==pointsSizeMinus2 && *it == *spline.points.rbegin() ) )
		{
			continue;
		}

		MPlug pointPlug;
		if( indicesToReuse.length() )
		{
			pointPlug = plug.elementByLogicalIndex( indicesToReuse[0] );
			indicesToReuse.remove( 0 );
		}
		else
		{
			pointPlug = plug.elementByLogicalIndex( nextNewLogicalIndex++ );		
		}
		
		s = pointPlug.child( 0 ).setValue( it->first ); assert( s );
		MPlug colorPlug = pointPlug.child( 1 );
		colorPlug.child( 0 ).setValue( it->second[0] );
		colorPlug.child( 1 ).setValue( it->second[1] );
		colorPlug.child( 2 ).setValue( it->second[2] );
		// hardcoding interpolation of 3 (spline) because the MRampAttribute::MInterpolation enum values don't actually
		// correspond to the necessary plug values at all.
		s = pointPlug.child( 2 ).setValue( 3 ); assert( s );

		numExpectedPoints++;
	}

	// delete any of the original indices which we didn't reuse. we can't use MRampAttribute::deleteEntries
	// here as it's utterly unreliable.
	if( indicesToReuse.length() )
	{
		MString plugName = plug.name();
		MObject node = plug.node();
		MFnDagNode fnDAGN( node );
		if( fnDAGN.hasObj( node ) )
		{
			plugName = fnDAGN.fullPathName() + "." + plug.partialName();
		}
		for( unsigned i=0; i<indicesToReuse.length(); i++ )
		{
			// using mel because there's no equivalant api method as far as i know.
			MString command = "removeMultiInstance -b true \"" + plugName + "[" + indicesToReuse[i] + "]\"";
			s = MGlobal::executeCommand( command );
			assert( s );
			if( !s )
			{
				return s;
			}
		}
	}

#ifndef NDEBUG
	{
		assert( fnRAttr.getNumEntries() == numExpectedPoints );

		MIntArray indices;
		MFloatArray positions;
		MColorArray colors;
		MIntArray interps;
		fnRAttr.getEntries( indices, positions, colors, interps, &s );
		assert( s );
		assert( numExpectedPoints == positions.length() );
		assert( numExpectedPoints == colors.length() );
		assert( numExpectedPoints == interps.length() );
		assert( numExpectedPoints == indices.length() );

		for ( unsigned i = 0; i < positions.length(); i++ )
		{
			float position = positions[ i ];
			const MVector color( colors[ i ][ 0 ], colors[ i ][ 1 ], colors[ i ][ 2 ] );

			bool found = false;

			for ( typename S::PointContainer::const_iterator it = spline.points.begin(); it != spline.points.end() && !found; ++it )
			{
				MVector color2( it->second[0], it->second[1], it->second[2] );
				if ( fabs( it->first - position ) < 1.e-3f && ( color2 - color ).length() < 1.e-3f )
				{
					found = true;
				}
			}
			assert( found );
		}
	}
#endif

	return MS::kSuccess;
}