Beispiel #1
0
boolean PostScriptView::Emit (ostream& out) {
    SetPSFonts();

    Graphic* g = GetGraphicComp()->GetGraphic();
    Transformer* t = SaveTransformer(g);
    ScaleToPostScriptCoords(g);

    Comments(out);
    Prologue(out);
    Version(out);
    GridSpacing(out);

    out << "\n\n%%Page: 1 1\n\n";
    out << "Begin\n";
    FullGS(out);
    out << "/originalCTM matrix currentmatrix def\n\n";

    boolean status = Definition(out);

    out << "End " << MARK << " eop\n\n";
    out << "showpage\n\n";

    Trailer(out);
    RestoreTransformer(g, t);

    return status;
}
Beispiel #2
0
Definition& Definition::operator[](LPCWSTR type)
{
    Definition* pRetDef = NULL;
    if(m_type2def.Lookup(type, pRetDef))
        return *pRetDef;

    pRetDef = DNew Definition(m_pnf, L"");
    pRetDef->m_priority = PLow;
    pRetDef->m_type = type;
    m_type2def[type] = pRetDef;

    CAtlList<Definition*> l;
    GetChildDefs(l, type);

    while(!l.IsEmpty())
    {
        Definition* pDef = l.RemoveHead();

        pRetDef->m_priority = pDef->m_priority;
        pRetDef->m_parent = pDef->m_parent;

        if(pDef->IsValue())
        {
            pRetDef->SetAsValue(pDef->m_status, pDef->m_value, pDef->m_unit);
        }
        else
        {
            pRetDef->m_status = node;
            pRetDef->m_nodes.AddTailList(&pDef->m_nodes);
        }
    }

    return *pRetDef;
}
Beispiel #3
0
	Definition* NodeFactory::CreateDef(Reference* pParentRef, CStringW type, CStringW name, NodePriority priority)
	{
		Definition* pDef = NULL;

		if(name.IsEmpty())
		{
			name = GenName();
		}
		else 
		{
			pDef = GetDefByName(name);

			if(pDef)
			{
				if(!pDef->m_predefined)
				{
					throw Exception(_T("redefinition of '%s' is not allowed"), CString(name));
				}

				if(!pDef->IsTypeUnknown() && !pDef->IsType(type))
				{
					throw Exception(_T("cannot redefine type of %s to %s"), CString(name), CString(type));
				}
			}
		}

		if(!pDef)
		{
			pDef = DNew Definition(this, name);

			m_nodes.SetAt(name, pDef);
			m_newnodes.AddTail(name);

			if(pParentRef)
			{
				pParentRef->AddTail(pDef);
				pDef->m_parent = pParentRef;
			}
		}

		pDef->m_type = type;
		pDef->m_priority = priority;
		pDef->m_predefined = m_predefined;

		return pDef;
	}
Beispiel #4
0
	Material::Material(const std::string& filename)
	{
		Definition currMaterial;
		std::string currMaterialName = "";
		std::ifstream file;
		file.open(filename.c_str(), std::ios_base::in);
	
		if(!file.is_open())
			return;

		while(!file.eof())
		{
			// Read first line of file.
			std::string line;
			std::getline(file, line);

			// Copy line to a stringstream and copy first word into string key
			std::stringstream streamLine;
			std::string key;

			streamLine.str(line);
			streamLine >> key;

			if(key == "newmtl")
			{
				if(currMaterialName != "") // It is not the first material read
				{
					// Save previous material, making sure the material does not already exist in Materials
					assert(Materials.find(currMaterialName) == Materials.end());
					Materials[currMaterialName] = currMaterial;
				}

				// Set new material name and clear current material
				streamLine >> currMaterialName;
				currMaterial = Definition();
			}
			else if(key == "Ka") // Ambient color
			{
				streamLine >> currMaterial.Ambient.x;
				streamLine >> currMaterial.Ambient.y;
				streamLine >> currMaterial.Ambient.z;
			}
PhysicsCollisionShape::Definition PhysicsCollisionShape::Definition::create(Node* node, Properties* properties)
{
    GP_ASSERT(node);

    // Check if the properties is valid and has a valid namespace.
    if (!properties || !(strcmp(properties->getNamespace(), "collisionObject") == 0))
    {
        GP_ERROR("Failed to load physics collision shape from properties object: must be non-null object and have namespace equal to 'collisionObject'.");
        return Definition();
    }

    // Set values to their defaults.
    PhysicsCollisionShape::Type type = PhysicsCollisionShape::SHAPE_BOX;
    Vector3 extents, center;
    bool extentsSpecified = false;
    bool centerSpecified = false;
    float radius = -1.0f;
    float width = -1.0f;
    float height = -1.0f;
    bool centerIsAbsolute = false;
    const char* imagePath = NULL;
    float maxHeight = 0;
    float minHeight = 0;
    bool shapeSpecified = false;

    // Load the defined properties.
    properties->rewind();
    const char* name;
    while (name = properties->getNextProperty())
    {
        if (strcmp(name, "shape") == 0)
        {
            std::string shapeStr = properties->getString();
            if (shapeStr == "BOX")
                type = SHAPE_BOX;
            else if (shapeStr == "SPHERE")
                type = SHAPE_SPHERE;
            else if (shapeStr == "MESH")
                type = SHAPE_MESH;
            else if (shapeStr == "HEIGHTFIELD")
                type = SHAPE_HEIGHTFIELD;
            else if (shapeStr == "CAPSULE")
                type = SHAPE_CAPSULE;
            else
            {
                GP_ERROR("Could not create physics collision shape; unsupported value for collision shape type: '%s'.", shapeStr.c_str());
                return Definition();
            }

            shapeSpecified = true;
        }
        else if (strcmp(name, "image") == 0)
        {
            imagePath = properties->getString();
        }
        else if (strcmp(name, "maxHeight") == 0)
        {
            maxHeight = properties->getFloat();
        }
        else if (strcmp(name, "minHeight") == 0)
        {
            minHeight = properties->getFloat();
        }
        else if (strcmp(name, "radius") == 0)
        {
            radius = properties->getFloat();
        }
        else if (strcmp(name, "width") == 0)
        {
            width = properties->getFloat();
        }
        else if (strcmp(name, "height") == 0)
        {
            height = properties->getFloat();
        }
        else if (strcmp(name, "extents") == 0)
        {
            properties->getVector3("extents", &extents);
            extentsSpecified = true;
        }
        else if (strcmp(name, "center") == 0)
        {
            properties->getVector3("center", &center);
            centerSpecified = true;
        }
        else if (strcmp(name, "centerAbsolute") == 0)
        {
            centerIsAbsolute = properties->getBool();
        }
        else
        {
            // Ignore this case (these are the properties for the rigid body, character, or ghost object that this collision shape is for).
        }
    }

    if (!shapeSpecified)
    {
        GP_ERROR("Missing 'shape' specifier for collision shape definition.");
        return Definition();
    }

    // Create the collision shape.
    Definition shape;
    switch (type)
    {
    case SHAPE_BOX:
        if (extentsSpecified)
        {
            if (centerSpecified)
            {
                shape = box(extents, center, centerIsAbsolute);
            }
            else
            {
                shape = box(extents);
            }
        }
        else
        {
            shape = box();
        }
        break;

    case SHAPE_SPHERE:
        if (radius != -1.0f)
        {
            if (centerSpecified)
            {
                shape = sphere(radius, center, centerIsAbsolute);
            }
            else
            {
                shape = sphere(radius);
            }
        }
        else
        {
            shape = sphere();
        }
        break;

    case SHAPE_CAPSULE:
        if (radius != -1.0f && height != -1.0f)
        {
            if (centerSpecified)
            {
                shape = capsule(radius, height, center, centerIsAbsolute);
            }
            else
            {
                shape = capsule(radius, height);
            }
        }
        else
        {
            shape = capsule();
        }
        break;

    case SHAPE_MESH:
        {
            // Mesh is required on node.
            Mesh* nodeMesh = node->getModel() ? node->getModel()->getMesh() : NULL;
            if (nodeMesh == NULL)
            {
                GP_ERROR("Cannot create mesh collision object for node without model/mesh.");
            }
            else
            {
                // Check that the node's mesh's primitive type is supported.
                switch (nodeMesh->getPrimitiveType())
                {
                case Mesh::TRIANGLES:
                    shape = mesh(nodeMesh);
                    break;
                case Mesh::LINES:
                case Mesh::LINE_STRIP:
                case Mesh::POINTS:
                case Mesh::TRIANGLE_STRIP:
                    GP_ERROR("Mesh collision objects are currently only supported on meshes with primitive type equal to TRIANGLES.");
                    break;
                }
            }
        }
        break;

    case SHAPE_HEIGHTFIELD:
        {
            if (imagePath == NULL)
            {
                // Node requires a valid terrain
                if (node->getTerrain() == NULL)
                {
                    GP_ERROR("Heightfield collision objects can only be specified on nodes that have a valid terrain, or that specify an image path.");
                }
                else
                {
                    shape = PhysicsCollisionShape::heightfield();
                }
            }
            else
            {
                std::string ext = FileSystem::getExtension(imagePath);
                HeightField* heightfield = NULL;
                if (ext == ".PNG")
                    heightfield = HeightField::createFromImage(imagePath, minHeight, maxHeight);
                else if (ext == ".RAW" || ext == ".R16")
                    heightfield = HeightField::createFromRAW(imagePath, (unsigned int)width, (unsigned int)height, minHeight, maxHeight);

                if (heightfield)
                {
                    shape = PhysicsCollisionShape::heightfield(heightfield);
                    SAFE_RELEASE(heightfield);
                }
            }
        }
        break;

    default:
        GP_ERROR("Unsupported physics collision shape type (%d).", type);
        break;
    }

    return shape;
}
Beispiel #6
0
OGLPLUS_LIB_FUNC
std::string BlendFileStructField::Name(void) const
{
	return _sdna->_field_name_from_def(Definition());
}
boolean ExternView::Emit (ostream& out) { return Definition(out); }
Beispiel #8
0
	Material::Material()
	{
		Materials["default"] = Definition();
	}