void Loader::setupPropertyKeysJson(TransformProperty& prop, const ofJson& json) { setupPropertyKeysJson(*prop.getTranslation(), json["Position"], ofVec3f(1,1,-1)); setupPropertyKeysJson(*prop.getScale(), json["Scale"], ofVec3f(0.01f,0.01f,0.01f)); setupPropertyKeysJson(*prop.getRotation(), json["Rotation"], ofVec3f(-1,-1,1)); if(json.find("AnchorPoint") != end(json)) { setupPropertyKeysJson(*prop.getAnchorPoint(), json["AnchorPoint"], ofVec3f(1,1,-1)); } setupPropertyKeysJson(*prop.getOrientation(), json["Orientation"], ofVec3f(-1,-1,1)); }
void Scene::readJson(const ofJson &obj) { _name = JsonUtil::fromJsonField<std::string>(obj, "name", "scene"); _nodes.clear(); auto iter = obj.find("nodes"); if (iter != obj.end() && !iter.value().is_null()) { const auto& nodesArray = iter.value(); JsonUtil::assertIsArray(nodesArray); for (const auto& nodeObj : nodesArray) { JsonUtil::assertIsObject(nodeObj); std::string typeName = nodeObj["type"]; auto node = createNode(typeName); if (!node) { continue; } _nodes.insert(std::make_pair(node->id(), node)); } } }
void Loader::setupLayerJson(Layer& layer, const ofJson& json) { layer.name_ = json.value("name", "noname"); layer.frame_offset_ = json.value("frameOffset", 0); layer.frame_in_ = json.value("inFrame", 0); layer.frame_out_ = json.value("outFrame", 0); layer.setParamByComment(json.value("comment", "")); const ofJson& properties = json["property"]; setupPropertyKeysJson(*layer.getActiveProperty(), properties["active"]); setupPropertyKeysJson(*layer.getOpacityProperty(), properties["Opacity"], 0.01f); setupPropertyKeysJson(*layer.getTransformProperty(), properties); // Markers auto markers = json.find("marker"); if(markers != end(json) && markers->is_array()) { int marker_count = markers->size(); for(int i = 0; i < marker_count; ++i) { setupMarkerJson(*layer.addNewMarker(), (*markers)[i]); } } }
void Loader::setupCompositionJson(Composition& comp, const ofJson& json) { // Basics comp.name_ = json.value("name", "noname"); comp.allocate(json.value("width", 1), json.value("height", 1)); comp.setLength(json.value("length", 0)); comp.setFrameRate(json.value("frameRate", 0)); // Layers const ofJson& layers = json["layer"]; if(layers.is_array()) { map<shared_ptr<Layer>, int> all; map<shared_ptr<Layer>, int> children; int layer_count = layers.size(); for(int i = layer_count; i--;) { // reverse iterate for draw priority const ofJson& layer = layers[i]; const string& type_name = layer.value("layerType", "unknown"); shared_ptr<Layer> l = nullptr; shared_ptr<LayerCap> c = nullptr; if(type_name == "composition") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<CompositionCap>(); setupCompositionJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "solid") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<PlaneCap>(); setupPlaneJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "sequence") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<SequenceCap>(); setupSequenceJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "image") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<ImageCap>(); setupImageJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "movie") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<MovieCap>(); setupMovieJson(*cap, layer); cap->setComposition(&comp); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "camera") { auto ll = make_shared<CameraLayer>(); setupCameraLayerJson(*ll, layer, comp); comp.camera_.push_back(ll); l = ll; } else if(type_name == "shape") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<ShapeCap>(); setupShapeJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } if(!l) { continue; } if(c) { l->setCap(c); } all.insert(pair<shared_ptr<Layer>,int>(l, layer.value("index", 0))); auto parent = layer.find("parent"); if(parent != end(layer)) { children.insert(pair<shared_ptr<Layer>,int>(l, *parent)); } } // search parent for(auto &child : children) { for(auto &parent : all) { if(child.second == parent.second) { child.first->setParent(parent.first); } } } } // Markers auto markers = json.find("marker"); if(markers != end(json) && markers->is_array()) { int marker_count = markers->size(); for(int i = 0; i < marker_count; ++i) { setupMarkerJson(*comp.addNewMarker(), (*markers)[i]); } } comp.setFrame(0); }
void Loader::setupShapeContentsJson(ShapeCap &cap, const ofJson& contents, shared_ptr<ShapeContentGroup> parent) { int content_count = contents.size(); for(int i = 0; i < content_count; ++i) { const ofJson& content = contents[i]; const string& type = content.value("type", ""); if(type == "group") { auto target = make_shared<ShapeContentGroup>(); auto content = contents.find("contents"); if(content != end(contents)) { setupShapeContentsJson(cap, *content, target); } if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "ellipse") { auto target = make_shared<ShapeContentEllipse>(); setupPropertyKeysJson(*target->getPositionProperty(), content["Position"]); setupPropertyKeysJson(*target->getSizeProperty(), content["Size"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "rect") { auto target = make_shared<ShapeContentRect>(); setupPropertyKeysJson(*target->getPositionProperty(), content["Position"]); setupPropertyKeysJson(*target->getSizeProperty(), content["Size"]); setupPropertyKeysJson(*target->getRoundnessProperty(), content["Roundness"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "path") { auto target = make_shared<ShapeContentPath>(); { auto prop = target->getPathProperty(); prop->setSize(cap.getSize()); setupPropertyKeysJson(*prop, content["path"]); } if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "stroke") { auto target = make_shared<ShapeContentStroke>(); setupPropertyKeysJson(*target->getColorProperty(), content["Color"]); setupPropertyKeysJson(*target->getOpacityProperty(), content["Opacity"], 0.01f); setupPropertyKeysJson(*target->getStrokeWidthProperty(), content["StrokeWidth"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "fill") { auto target = make_shared<ShapeContentFill>(); setupPropertyKeysJson(*target->getColorProperty(), content["Color"]); setupPropertyKeysJson(*target->getOpacityProperty(), content["Opacity"], 0.01f); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "transform") { { auto prop = parent->getTransformProperty(); setupPropertyKeysJson(*prop->getTranslation(), content["Position"]); setupPropertyKeysJson(*prop->getAnchorPoint(), content["AnchorPoint"]); setupPropertyKeysJson(*prop->getScale(), content["Scale"], ofVec3f(0.01f,0.01f,0), ofVec3f(0,0,1)); } setupPropertyKeysJson(*parent->getRotationZProperty(), content["Rotation"]); setupPropertyKeysJson(*parent->getOpacityProperty(), content["Opacity"], 0.01f); setupPropertyKeysJson(*parent->getSkewProperty(), content["Skew"]); setupPropertyKeysJson(*parent->getSkewAxisProperty(), content["SkewAxis"]); } } }