PhysicsFrame::PhysicsFrame(const Any& a) {
    const std::string& n = toLower(a.name());
    *this = PhysicsFrame();

    if (beginsWith(n, "vector3")) {
        *this = PhysicsFrame(Vector3(a));
    } else if (beginsWith(n, "matrix3")) {        
        *this = PhysicsFrame(Matrix3(a));
    } else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) {        
        *this = PhysicsFrame(CoordinateFrame(a));
    } else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) {
        if (a.type() == Any::ARRAY) {
            a.verifySize(2);
            rotation    = a[0];
            translation = a[1];
        } else {
            for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) {
                const std::string& n = toLower(it->key);
                if (n == "translation") {
                    translation = it->value;
                } else if (n == "rotation") {
                    rotation = it->value;
                } else {
                    a.verify(false, "Illegal table key: " + it->key);
                }
            }
        }
    }
}
BumpMapPreprocess::BumpMapPreprocess(const Any& any) {
    *this = BumpMapPreprocess();
    for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
        const std::string& key = toLower(it->key);
        if (key == "lowpassfilter") {
            lowPassFilter = it->value;
        } else if (key == "zextentpixels") {
            zExtentPixels = it->value;
        } else if (key == "scalezbynz") {
            scaleZByNz = it->value;
        } else {
            any.verify(false, "Illegal key: " + it->key);
        }
    }
}
Exemple #3
0
BumpMap::Settings::Settings(const Any& any) {
    *this = Settings();
    any.verifyName("BumpMap::Settings");
    for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
        const std::string& key = toLower(it->key);
        if (key == "iterations") {
            iterations = iMax(0, iRound(it->value.number()));
        } else if (key == "scale") {
            scale = it->value;
        } else if (key == "bias") {
            bias = it->value;
        } else {
            any.verify(false, "Illegal key: " + it->key);
        }
    }
}
CoordinateFrame::CoordinateFrame(const Any& any) {
    *this = CFrame();

    const std::string& n = toUpper(any.name());

    if (beginsWith(n, "VECTOR3")) {
        translation = any;
    } else if (beginsWith(n, "MATRIX3")) {
        rotation = any;
    } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) {
        any.verifyType(Any::TABLE, Any::ARRAY);
        if (any.type() == Any::ARRAY) {
            any.verifySize(2);
            rotation    = any[0];
            translation = any[1];
        } else {
            for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
                const std::string& n = toLower(it->key);
                if (n == "translation") {
                    translation = Vector3(it->value);
                } else if (n == "rotation") {
                    rotation = Matrix3(it->value);
                } else {
                    any.verify(false, "Illegal table key: " + it->key);
                }
            }
        }
    } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) {
        *this = PhysicsFrame(any);
    } else {
        any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees");
        any.verifyType(Any::ARRAY);
        any.verifySize(3, 6);

        int s = any.size();

        *this = fromXYZYPRDegrees(any[0], any[1], any[2],
                                  (s > 3) ? any[3].number() : 0.0f,
                                  (s > 4) ? any[4].number() : 0.0f,
                                  (s > 5) ? any[5].number() : 0.0f);
    }
}
PhysicsFrameSpline& PhysicsFrameSpline::operator=(const Any& any) {
    const std::string& n = toLower(any.name());
    *this = PhysicsFrameSpline();

    if (n == "physicsframespline" || n == "pframespline") {
        any.verifyName("PhysicsFrameSpline", "PFrameSpline");
        
        for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
            const std::string& k = toLower(it->key);
            if (k == "cyclic") {
                cyclic = it->value;
            } else if (k == "control") {
                const Any& v = it->value;
                v.verifyType(Any::ARRAY);
                control.resize(v.size());
                for (int i = 0; i < control.size(); ++i) {
                    control[i] = v[i];
                }
                if (! any.containsKey("time")) {
                    time.resize(control.size());
                    for (int i = 0; i < time.size(); ++i) {
                        time[i] = i;
                    }
                }
            } else if (k == "finalinterval") {
                finalInterval = it->value;
            } else if (k == "time") {
                const Any& v = it->value;
                v.verifyType(Any::ARRAY);
                time.resize(v.size());
                for (int i = 0; i < time.size(); ++i) {
                    time[i] = v[i];
                }
            }
        }
    } else {
        // Must be a PhysicsFrame constructor of some kind
        append(any);
    }
    return *this;
}
Exemple #6
0
BumpMap::Specification::Specification(const Any& any) {
    if (any.type() == Any::STRING) {
        // Treat as a filename
        texture.filename = any.resolveStringAsFilename();
        texture.preprocess = Texture::Preprocess::normalMap();
    } else {
        for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
            const std::string& key = toLower(it->key);
            if (key == "texture") {
                texture = it->value;
                if (it->value.type() == Any::STRING) {
                    // Set bump map defaults
                    texture.preprocess = Texture::Preprocess::normalMap();
                }
            } else if (key == "settings") {
                settings = it->value;
            } else {
                any.verify(false, "Illegal key: " + it->key);        
            }
        }
    }
}
Exemple #7
0
GLight::GLight(const Any& any) {
    any.verifyName("GLight");

    if (any.type() == Any::TABLE) {
        *this = GLight();
        Vector3 spotTarget;
        bool hasSpotTarget = false;
        for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
            const std::string& key = toLower(it->key);
            if (key == "position") {
                position = it->value;
            } else if (key == "rightdirection") {
                rightDirection = it->value;
            } else if (key == "spotdirection") {
                spotDirection = Vector3(it->value).directionOrZero();
            } else if (key == "spottarget") {
                spotTarget = it->value;
                hasSpotTarget = true;
            } else if (key == "spotcutoff") {
                spotCutoff = it->value.number();
            } else if (key == "spotsquare") {
                spotSquare = it->value.boolean();
            } else if (key == "attenuation") {
                attenuation[0] = it->value[0].number();
                attenuation[1] = it->value[1].number();
                attenuation[2] = it->value[2].number();
            } else if (key == "color") {
                color = it->value;
            } else if (key == "enabled") {
                enabled = it->value.boolean();
            } else if (key == "specular") {
                specular = it->value.boolean();
            } else if (key == "diffuse") {
                diffuse = it->value.boolean();
            } else {
                any.verify(false, "Illegal key: " + it->key);
            }
        }
        if (hasSpotTarget) {
            spotDirection = (spotTarget - position.xyz()).direction();
        }
    } else if (toLower(any.name()) == "glight::directional") {

        *this = directional(any[0], any[1], 
            (any.size() > 2) ? any[2] : Any(true), 
            (any.size() > 3) ? any[3] : Any(true));

    } else if (toLower(any.name()) == "glight::point") {

        *this = point(any[0], any[1], 
            (any.size() > 2) ? any[2] : Any(1), 
            (any.size() > 3) ? any[3] : Any(0), 
            (any.size() > 4) ? any[4] : Any(0.5f), 
            (any.size() > 5) ? any[5] : Any(true), 
            (any.size() > 6) ? any[6] : Any(true));

    } else if (toLower(any.name()) == "glight::spot") {

        *this = spot(any[0], any[1], any[2], any[3],
            (any.size() > 4) ? any[4] : Any(1), 
            (any.size() > 5) ? any[5] : Any(0), 
            (any.size() > 6) ? any[6] : Any(0), 
            (any.size() > 7) ? any[7] : Any(true), 
            (any.size() > 8) ? any[8] : Any(true));
    } else {
        any.verify(false, "Unrecognized name");
    }
}
Exemple #8
0
Scene::Ref Scene::create(const std::string& scene, GCamera& camera) 
{
	if (scene == "") 
	{
		return NULL;
	}

	Scene::Ref s = new Scene();

	const std::string* f = filenameTable().getPointer(scene);
	if (f == NULL) 
	{
		throw "No scene with name '" + scene + "' found in (" + 
			stringJoin(filenameTable().getKeys(), ", ") + ")";
	}
	const std::string& filename = *f;

	Any any;
	any.load(filename);

	// Load the lighting
	s->m_lighting = Lighting::create(any.get("lighting", Lighting::Specification()));

	// Load the models
	Any models = any["models"];
	typedef ReferenceCountedPointer<ReferenceCountedObject> ModelRef;
	Table< std::string, ModelRef > modelTable;
	for (Any::AnyTable::Iterator it = models.table().begin(); it.hasMore(); ++it) {
		ModelRef m;
		Any v = it->value;
		if (v.nameBeginsWith("ArticulatedModel")) {
			m = ArticulatedModel::create(v);
		} else if (v.nameBeginsWith("MD2Model")) {
			m = MD2Model::create(v);
		} else if (v.nameBeginsWith("MD3Model")) {
			m = MD3Model::create(v);
		} else {
			debugAssertM(false, "Unrecognized model type: " + v.name());
		}

		modelTable.set(it->key, m);        
	}

	// Instance the models
	Any entities = any["entities"];
	for (Table<std::string, Any>::Iterator it = entities.table().begin(); it.hasMore(); ++it) {
		const std::string& name = it->key;
		const Any& modelArgs = it->value;

		modelArgs.verifyType(Any::ARRAY);
		const ModelRef* model = modelTable.getPointer(modelArgs.name());
		modelArgs.verify((model != NULL), 
			"Can't instantiate undefined model named " + modelArgs.name() + ".");

		PhysicsFrameSpline frameSpline;
		ArticulatedModel::PoseSpline poseSpline;
		if (modelArgs.size() >= 1) {
			frameSpline = modelArgs[0];
			if (modelArgs.size() >= 2) {
				// Poses 
				poseSpline = modelArgs[1];
			}
		}

		ArticulatedModel::Ref artModel = model->downcast<ArticulatedModel>();
		MD2Model::Ref         md2Model = model->downcast<MD2Model>();
		MD3Model::Ref         md3Model = model->downcast<MD3Model>();

		if (artModel.notNull()) {
			s->m_entityArray.append(Entity::create(name, frameSpline, artModel, poseSpline));
		} else if (md2Model.notNull()) {
			s->m_entityArray.append(Entity::create(name, frameSpline, md2Model));
		} else if (md3Model.notNull()) {
			s->m_entityArray.append(Entity::create(name, frameSpline, md3Model));
		}
	}

	// Load the camera
	camera = any["camera"];

	if (any.containsKey("skybox")) {
		Any sky = any["skyBox"];
		s->m_skyBoxConstant = sky.get("constant", 1.0f);
		if (sky.containsKey("texture")) {
			s->m_skyBoxTexture = Texture::create(sky["texture"]);
		}
	} else {
		s->m_skyBoxTexture = s->m_lighting->environmentMapTexture;
		s->m_skyBoxConstant = s->m_lighting->environmentMapConstant;
	}

	// Default to using the skybox as an environment map if none is specified.
	if (s->m_skyBoxTexture.notNull() && s->m_lighting->environmentMapTexture.isNull()) {
		s->m_lighting->environmentMapTexture  = s->m_skyBoxTexture;
		s->m_lighting->environmentMapConstant = s->m_skyBoxConstant;
	}

	return s;
}