Esempio n. 1
0
PyObject *CachedObjectMgr::GetCachedObject(const std::string &objectID)
{
    //this is sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
    PyString *str = new PyString( objectID );
    PyObject* obj = GetCachedObject(str);
    PyDecRef(str);
    return obj;
}
Esempio n. 2
0
/*!
	@function	NodeV2ToObject
	
	@abstract	Attempt to convert a VRML 2 node to a Quesa object.
	
	@discussion	The reason that the node is not passed as a const reference is
				that whenever we successfully produce a Quesa object from a
				node, we cache that object in the node.  This is not only a
				speed optimization, it is also necessary to guarantee that we
				will have multiple Quesa references whenever there are multiple
				references to a VRML node.
	
	@param		ioNode		Node to convert.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	NodeV2ToObject( PolyValue& ioNode, CVRMLReader& inReader )
{
	CQ3ObjectRef	theObject;
	
	if (ioNode.GetType() == PolyValue::kDataTypeDictionary)
	{
		theObject = GetCachedObject( ioNode );
		
		if (not theObject.isvalid())
		{
			PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
			const PolyValue&	nodeTypeValue( theDict["[type]"] );
			const std::string&	nodeType( nodeTypeValue.GetString() );
			
			if (nodeType == "Shape")
			{
				theObject = ShapeV2ToObject( ioNode, inReader );
			}
			else if (nodeType == "Transform")
			{
				theObject = TransformV2ToObject( ioNode, inReader );
			}
			else if ( (nodeType == "Group") or (nodeType == "Anchor") )
			{
				theObject = GroupV2ToObject( ioNode, inReader );
			}
			else if (nodeType == "Switch")
			{
				theObject = SwitchV2ToObject( ioNode, inReader );
			}
			else if (inReader.GetDebugStream() != NULL)
			{
				*inReader.GetDebugStream() << "No handler for node of type '" <<
					nodeType << "'." << std::endl;
			}
		}
	}
	
	return theObject;
}
PyObject *CachedObjectMgr::GetCachedObject(const std::string &objectID) {
    //this is sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
    PyString str( objectID );
    return(GetCachedObject(&str));
}
Esempio n. 4
0
/*!
	@function	ShapeV2ToObject
	
	@abstract	Attempt to convert a VRML 2 Shape node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	ShapeV2ToObject( PolyValue& ioNode, CVRMLReader& inReader )
{
	CQ3ObjectRef	theObject;
	
	PolyValue::Dictionary&	nodeDict( ioNode.GetDictionary() );
	PolyValue&	theGeom( nodeDict["geometry"] );
	
	if (theGeom.GetType() == PolyValue::kDataTypeDictionary)
	{
		CQ3ObjectRef	geomObject( GetCachedObject( theGeom ) );
		
		if (not geomObject.isvalid())
		{
			PolyValue::Dictionary	geomDict( theGeom.GetDictionary() );
			const PolyValue&	nodeTypeValue( geomDict["[type]"] );
			const std::string&	geomType( nodeTypeValue.GetString() );
			
			if (geomType == "Cylinder")
			{
				geomObject = CylinderV2ToObject( theGeom );
			}
			else if (geomType == "Cone")
			{
				geomObject = ConeV2ToObject( theGeom );
			}
			else if (geomType == "Sphere")
			{
				geomObject = SphereV2ToObject( theGeom );
			}
			else if (geomType == "Box")
			{
				geomObject = BoxV2ToObject( theGeom );
			}
			else if (geomType == "PointSet")
			{
				geomObject = PointSetV2ToObject( theGeom );
			}
			else if (geomType == "IndexedFaceSet")
			{
				geomObject = IndexedFaceSetV2ToObject( theGeom, inReader );
			}
			else if (geomType == "IndexedLineSet")
			{
				geomObject = IndexedLineSetV2ToObject( theGeom );
			}
			else if (inReader.GetDebugStream() != NULL)
			{
				*inReader.GetDebugStream() << "No handler for geometry node '" <<
					geomType << "'." << std::endl;
			}
			
			if (geomObject.isvalid())
			{
				// If this geometry was named with DEF, set that as the name of the
				// Quesa object.
				if (IsKeyPresent( geomDict, "[name]" ))
				{
					PolyValue&	nameValue( geomDict["[name]"] );
					const std::string&	theName( nameValue.GetString() );
					::CENameElement_SetData( geomObject.get(), theName.c_str() );
				}
			}
		}
		
		if (geomObject.isvalid())
		{
			CQ3ObjectRef	appearanceObject;
			PolyValue&	theAppearanceNode( nodeDict["appearance"] );
			
			if (theAppearanceNode.GetType() == PolyValue::kDataTypeDictionary)
			{
				appearanceObject = GetCachedObject( theAppearanceNode );
				
				if (not appearanceObject.isvalid())
				{
					appearanceObject = MakeDefaultAttSet();
					AppearanceV2ToObject( theAppearanceNode, inReader, appearanceObject );
				}
			}
			else	// no Appearance node
			{
				appearanceObject = MakeDefaultAttSet();
			}
			
			theObject = CQ3ObjectRef( Q3Object_Duplicate( geomObject.get() ) );
			
			if (theObject.isvalid() and appearanceObject.isvalid())
			{
				if (Q3Object_IsType( theObject.get(), kQ3ShapeTypeGeometry ))
				{
					Q3Geometry_SetAttributeSet( theObject.get(), appearanceObject.get() );
				}
				else if (Q3Object_IsType( theObject.get(), kQ3ShapeTypeGroup ))
				{
					PrependObjectToGroup( appearanceObject, theObject );
				}
			}
		}
	}
	
	if (theObject.isvalid())
	{
		// If the Shape was named with a DEF, use that as the name ofthe object.
		if (IsKeyPresent( nodeDict, "[name]" ))
		{
			PolyValue&	nameValue( nodeDict["[name]"] );
			const std::string&	theName( nameValue.GetString() );
			::CENameElement_SetData( theObject.get(), theName.c_str() );
		}
	
		SetCachedObject( ioNode, theObject );
	}
	
	return theObject;
}