ArticulatedModel::Instruction::Identifier::Identifier(const Any& a) {
    switch (a.type()) {
    case Any::NUMBER:
        id = ID(iRound(a.number()));
        a.verify(id >= 0, "Illegal ID");
        break;

    case Any::STRING:
        name = a.string();
        break;

    case Any::ARRAY:
        a.verifySize(0);
        if (a.name() == "root") {
            *this = root();
        } else if (a.name() == "all") {
            *this = all();
        } else {
            a.verify(false, "Illegal function call: " + a.name());
        }
        break;

    default:
        a.verify(false, "Expected a name, integer ID, root(), or all()");
    }
}
Texture::Specification::Specification(const Any& any, bool assumesRGBForAuto, Dimension defaultDimension) {
    *this = Specification();
    assumeSRGBSpaceForAuto = assumesRGBForAuto;
    dimension              = defaultDimension;

    if (any.type() == Any::STRING) {
        filename = any.string();
        if (filename == "<whiteCube>") {
            filename = "<white>";
            dimension = Texture::DIM_CUBE_MAP;
        }

        if (! beginsWith(filename, "<")) {
            filename = any.resolveStringAsFilename();
            if (FilePath::containsWildcards(filename)) {

                // Assume this is a cube map
                dimension = Texture::DIM_CUBE_MAP;
            }
        }
    } else if ((any.type() == Any::NUMBER) ||
               any.nameBeginsWith("Color4") || 
			   anyNameIsColor3Variant(any)) {
        filename = "<white>";
        encoding.readMultiplyFirst = Color4(any);
    } else {

        any.verifyNameBeginsWith("Texture::Specification");
        AnyTableReader r(any);
        r.getFilenameIfPresent("filename", filename);
        r.getFilenameIfPresent("alphaFilename", alphaFilename);
        r.getIfPresent("encoding", encoding);
        r.getIfPresent("assumeSRGBSpaceForAuto", assumeSRGBSpaceForAuto);
        {
            Any a;
            if (r.getIfPresent("dimension", a)) {
                dimension = toDimension(a);
            }
        }
        r.getIfPresent("generateMipMaps", generateMipMaps);
        r.getIfPresent("preprocess", preprocess);
        r.getIfPresent("visualization", visualization);
        r.getIfPresent("cachable", cachable);
        r.verifyDone();

        if (! any.containsKey("dimension") && FilePath::containsWildcards(filename)) {
            // Assume this is a cube map
            dimension = Texture::DIM_CUBE_MAP;
        }
    }
}
Exemple #3
0
void VisibleEntity::init
   (AnyTableReader&    propertyTable,
    const ModelTable&  modelTable) {

    bool visible = true;
    propertyTable.getIfPresent("visible", visible);

    ArticulatedModel::Pose artPose;
    propertyTable.getIfPresent("articulatedModelPose", artPose);

    ArticulatedModel::PoseSpline artPoseSpline;
    propertyTable.getIfPresent("poseSpline", artPoseSpline);

	MD3Model::PoseSequence md3PoseSequence;
	propertyTable.getIfPresent("md3Pose", md3PoseSequence);

    Surface::ExpressiveLightScatteringProperties expressiveLightScatteringProperties;
    propertyTable.getIfPresent("expressiveLightScatteringProperties", expressiveLightScatteringProperties);
    
    if (propertyTable.getIfPresent("castsShadows", expressiveLightScatteringProperties.castsShadows)) {
        debugPrintf("Warning: castsShadows field is deprecated.  Use expressiveLightScatteringProperties");
    }    

    const lazy_ptr<Model>* model = NULL;
    Any modelNameAny;
    if (propertyTable.getIfPresent("model", modelNameAny)) {
        const String& modelName     = modelNameAny.string();
    
        modelNameAny.verify(modelTable.containsKey(modelName), 
                        "Can't instantiate undefined model named " + modelName + ".");
        model = modelTable.getPointer(modelName);
    }

    Any ignore;
    if (propertyTable.getIfPresent("materialTable", ignore)) {
        ignore.verify(false, "'materialTable' is deprecated. Specify materials on the articulatedModelPose field of VisibleEntity.");
    }

    init(notNull(model) ? model->resolve() : shared_ptr<Model>(), visible, expressiveLightScatteringProperties, artPoseSpline, md3PoseSequence, artPose);
}
Exemple #4
0
shared_ptr<Entity::Track> Entity::Track::create(Entity* entity, Scene* scene, const Any& a, const VariableTable& variableTable) {
    if (a.type() == Any::STRING) {
        // This must be an id
        const shared_ptr<Entity::Track>& c = variableTable[a.string()];
        if (isNull(c)) {
            a.verify(false, "");
        }
        return c;
    }

    if ((beginsWith(a.name(), "PhysicsFrameSpline")) ||
        (beginsWith(a.name(), "PFrameSpline")) ||
        (beginsWith(a.name(), "Point3")) || 
        (beginsWith(a.name(), "Vector3")) || 
        (beginsWith(a.name(), "Matrix3")) || 
        (beginsWith(a.name(), "Matrix4")) || 
        (beginsWith(a.name(), "CFrame")) || 
        (beginsWith(a.name(), "PFrame")) || 
        (beginsWith(a.name(), "UprightSpline")) || 
        (beginsWith(a.name(), "CoordinateFrame")) || 
        (beginsWith(a.name(), "PhysicsFrame"))) {

        return Entity::SplineTrack::create(a);

    } else if (a.name() == "entity") {

        // Name of an Entity
        const std::string& targetName = a[0].string();
        alwaysAssertM(notNull(scene) && notNull(entity), "entity() Track requires non-NULL Scene and Entity");
        debugAssert(targetName != "");
        scene->setOrder(entity->name(), targetName);
        return shared_ptr<Entity::Track>(new TrackEntityTrack(targetName, scene));

    } else if (a.name() == "transform") {

        return shared_ptr<Entity::Track>
            (new TransformTrack(create(entity, scene, a[0], variableTable), 
                                create(entity, scene, a[1], variableTable)));

    } else if (a.name() == "follow") {

        a.verify(false, "follow Tracks are unimplemented");
        return shared_ptr<Entity::Track>();
        // return shared_ptr<Entity::Track>(new TransformTrack(create(a[0]), create(a[1])));

	} else if (a.name() == "orbit") {

        return shared_ptr<Entity::Track>(new OrbitTrack(a[0], a[1]));

    } else if (a.name() == "combine") {

        return shared_ptr<Entity::Track>
            (new CombineTrack(create(entity, scene, a[0], variableTable), 
                                   create(entity, scene, a[1], variableTable)));

    } else if (a.name() == "lookAt") {

        return shared_ptr<Entity::Track>
            (new LookAtTrack(create(entity, scene, a[0], variableTable), 
                                  create(entity, scene, a[1], variableTable), (a.size() > 2) ? Vector3(a[2]) : Vector3::unitY()));

    } else if (a.name() == "timeShift") {

        shared_ptr<Track> p = create(entity, scene, a[0], variableTable);
        a.verify(notNull(dynamic_pointer_cast<SplineTrack>(p)) || notNull(dynamic_pointer_cast<OrbitTrack>(p)), "timeShift() requires a PhysicsFrameSpline or orbit");
        return shared_ptr<Entity::Track>(new TimeShiftTrack(p, a[1].number()));

    } else if (a.name() == "with") {

        // Create a new variable table and recurse
        VariableTable extendedTable(&variableTable);

        const Any& vars = a[0];
        for (Table<std::string, Any>::Iterator it = vars.table().begin(); it.isValid(); ++it) {
            // Note that if Any allowed iteration through its table in definition order, then
            // we could implement Scheme LET* instead of LET here.
            extendedTable.set(it->key, create(entity, scene, it->value, variableTable));
        }

        return create(entity, scene, a[1], extendedTable);

    } else {

        // Some failure
        a.verify(false, "Unrecognized Entity::Track type");
        return shared_ptr<Entity::Track>();

    }
}