Ejemplo n.º 1
0
		//
		// Write out all of the connections in the scene.
		//
		protected void writeConnections(FileStream f)
		{
			//
			// If the scene has broken any connections which were made in referenced
			// files, handle those first so that the attributes are free for any new
			// connections which may come along.
			//
			writeBrokenRefConnections(f);

			//
			// We're about to write out the scene's connections in three parts: DAG
			// nodes, non-DAG non-default nodes, then default nodes.
			//
			// It's really not necessary that we group them like this and would in
			// fact be more efficient to do them all in one MItDependencyNodes
			// traversal.  However, this is the order in which the normal MayaAscii
			// translator does them, so this makes it easier to compare the output
			// of this translator to Maya's output.
			//

			//
			// Write out connections for the DAG nodes first.
			//
			MItDag	dagIter = new MItDag();
			dagIter.traverseUnderWorld(true);

			for (dagIter.next(); !dagIter.isDone; dagIter.next())
			{
				MObject		node = dagIter.item();
				MFnDagNode	dagNodeFn = new MFnDagNode(node);

				if (!dagNodeFn.isFlagSet(fConnectionFlag)
				&&	dagNodeFn.canBeWritten
				&&	!dagNodeFn.isDefaultNode)
				{
					writeNodeConnections(f, dagIter.item());
					dagNodeFn.setFlag(fConnectionFlag, true);
				}
			}

			//
			// Now do the non-DAG, non-default nodes.
			//
			MItDependencyNodes	nodeIter = new MItDependencyNodes();

			for (; !nodeIter.isDone; nodeIter.next())
			{
				MFnDependencyNode	nodeFn = new MFnDependencyNode(nodeIter.item);

				if (!nodeFn.isFlagSet(fConnectionFlag)
				&&	nodeFn.canBeWritten
				&&	!nodeFn.isDefaultNode)
				{
					writeNodeConnections(f, nodeIter.item);
					nodeFn.setFlag(fConnectionFlag, true);
				}
			}

			//
			// And finish up with the default nodes.
			//
			uint numNodes = fDefaultNodes.length;
			int i;

			for (i = 0; i < numNodes; i++)
			{
				MFnDependencyNode	nodeFn = new MFnDependencyNode(fDefaultNodes[i]);

				if (!nodeFn.isFlagSet(fConnectionFlag)
				&&	nodeFn.canBeWritten
				&&	nodeFn.isDefaultNode)
				{
					writeNodeConnections(f, fDefaultNodes[i]);
					nodeFn.setFlag(fConnectionFlag, true);
				}
			}
		}
Ejemplo n.º 2
0
		protected void writeDagNodes(FileStream f)
		{
			fParentingRequired.clear();

			MItDag	dagIter = new MItDag();

			dagIter.traverseUnderWorld(true);

			MDagPath worldPath = new MDagPath();

			dagIter.getPath(worldPath);

			//
			// We step over the world node before starting the loop, because it
			// doesn't get written out.
			//
			for (dagIter.next(); !dagIter.isDone; dagIter.next())
			{
				MDagPath	path = new MDagPath();
				dagIter.getPath(path);

				//
				// If the node has already been written, then all of its descendants
				// must have been written, or at least checked, as well, so prune
				// this branch of the tree from the iteration.
				//
				MFnDagNode	dagNodeFn = new MFnDagNode(path);

				if (dagNodeFn.isFlagSet(fCreateFlag))
				{
					dagIter.prune();
					continue;
				}

				//
				// If this is a default node, it will be written out later, so skip
				// it.
				//
				if (dagNodeFn.isDefaultNode) continue;

				//
				// If this node is not writable, and is not a shared node, then mark
				// it as having been written, and skip it.
				//
				if (!dagNodeFn.canBeWritten && !dagNodeFn.isShared)
				{
					dagNodeFn.setFlag(fCreateFlag, true);
					continue;
				}

				uint numParents = dagNodeFn.parentCount;

				if (dagNodeFn.isFromReferencedFile)
				{
					//
					// We don't issue 'creatNode' commands for nodes from referenced
					// files, but if the node has any parents which are not from
					// referenced files, other than the world, then make a note that
					// we'll need to issue extra 'parent' commands for it later on.
					//
					uint i;

					for (i = 0; i < numParents; i++)
					{
						MObject		altParent = dagNodeFn.parent(i);
						MFnDagNode	altParentFn = new MFnDagNode(altParent);

						if (!altParentFn.isFromReferencedFile
						&&	(altParentFn.objectProperty.notEqual(worldPath.node)))
						{
							fParentingRequired.append(path);
							break;
						}
					}
				}
				else
				{
					//
					// Find the node's parent.
					//
					MDagPath parentPath = new MDagPath(worldPath);

					if (path.length > 1)
					{
						//
						// Get the parent's path.
						//
						parentPath.assign(path);
						parentPath.pop();

						//
						// If the parent is in the underworld, then find the closest
						// ancestor which is not.
						//
						if (parentPath.pathCount > 1)
						{
							//
							// The first segment of the path contains whatever
							// portion of the path exists in the world.  So the closest
							// worldly ancestor is simply the one at the end of that
							// first path segment.
							//
							path.getPath(parentPath, 0);
						}
					}

					MFnDagNode	parentNodeFn = new MFnDagNode(parentPath);

					if (parentNodeFn.isFromReferencedFile)
					{
						//
						// We prefer to parent to a non-referenced node.  So if this
						// node has any other parents, which are not from referenced
						// files and have not already been processed, then we'll
						// skip this instance and wait for an instance through one
						// of those parents.
						//
						uint i;

						for (i = 0; i < numParents; i++)
						{
							if (dagNodeFn.parent(i).notEqual(parentNodeFn.objectProperty))
							{
								MObject		altParent = dagNodeFn.parent(i);
								MFnDagNode	altParentFn = new MFnDagNode(altParent);

								if (!altParentFn.isFromReferencedFile
								&&	!altParentFn.isFlagSet(fCreateFlag))
								{
									break;
								}
							}
						}

						if (i < numParents) continue;

						//
						// This node only has parents within referenced files, so
						// create it without a parent and note that we need to issue
						// 'parent' commands for it later on.
						//
						writeCreateNode(f, path, worldPath);

						fParentingRequired.append(path);
					}
					else
					{
						writeCreateNode(f, path, parentPath);

						//
						// Let's see if this node has any parents from referenced
						// files, or any parents other than this one which are not
						// from referenced files.
						//
						uint i;
						bool hasRefParents = false;
						bool hasOtherNonRefParents = false;

						for (i = 0; i < numParents; i++)
						{
							if (dagNodeFn.parent(i).notEqual(parentNodeFn.objectProperty))
							{
								MObject		altParent = dagNodeFn.parent(i);
								MFnDagNode	altParentFn = new MFnDagNode(altParent);

								if (altParentFn.isFromReferencedFile)
									hasRefParents = true;
								else
									hasOtherNonRefParents = true;

								//
								// If we've already got positives for both tests,
								// then there's no need in continuing.
								//
								if (hasRefParents && hasOtherNonRefParents) break;
							}
						}

						//
						// If this node has parents from referenced files, then
						// make note that we will have to issue 'parent' commands
						// later on.
						//
						if (hasRefParents) fParentingRequired.append(path);

						//
						// If this node has parents other than this one which are
						// not from referenced files, then make note that the
						// parenting for the other instances still has to be done.
						//
						if (hasOtherNonRefParents)
						{
							fInstanceChildren.append(path);
							fInstanceParents.append(parentPath);
						}
					}

					//
					// Write out the node's 'addAttr', 'setAttr' and 'lockNode'
					// commands.
					//
					writeNodeAttrs(f, path.node, true);
					writeLockNode(f, path.node);
				}

				//
				// Mark the node as having been written.
				//
				dagNodeFn.setFlag(fCreateFlag, true);
			}

			//
			// Write out the parenting for instances.
			//
			writeInstances(f);
		}