void ShaderEditor::load() { char path[Lumix::MAX_PATH_LENGTH]; if (!PlatformInterface::getOpenFilename(path, Lumix::lengthOf(path), "Shader edit data\0*.sed\0", nullptr)) { return; } m_path = path; clear(); FILE* fp = fopen(path, "rb"); if (!fp) { Lumix::g_log_error.log("Editor") << "Failed to load shader " << path; return; } fseek(fp, 0, SEEK_END); int data_size = (int)ftell(fp); Lumix::Array<Lumix::uint8> data(m_allocator); data.resize(data_size); fseek(fp, 0, SEEK_SET); fread(&data[0], 1, data_size, fp); Lumix::InputBlob blob(&data[0], data_size); for (int i = 0; i < Lumix::lengthOf(m_textures); ++i) { blob.readString(m_textures[i], Lumix::lengthOf(m_textures[i])); } int size; blob.read(size); for(int i = 0; i < size; ++i) { loadNode(blob, ShaderType::VERTEX); } for(auto* node : m_vertex_nodes) { loadNodeConnections(blob, *node); m_last_node_id = Lumix::Math::maxValue(int(node->m_id + 1), int(m_last_node_id)); } blob.read(size); for (int i = 0; i < size; ++i) { loadNode(blob, ShaderType::FRAGMENT); } for (auto* node : m_fragment_nodes) { loadNodeConnections(blob, *node); m_last_node_id = Lumix::Math::maxValue(int(node->m_id + 1), int(m_last_node_id)); } fclose(fp); }
void QTodoList::loadNode(QTodoNode* node, unsigned int depth) { if(!node) return; for(QTodoNode::iterator it = node->begin(); it != node->end(); ++it) { if((*it)->section == true) { QTodoListViewItemSection* lists_item = new QTodoListViewItemSection(getTodoListWidget()->getListViewItem()); QTodoSectionWidget* section = new QTodoSectionWidget(vbox,lists_item); lists_item->setSection(section); section->setName((*it)->task); section->show(); continue; } QTodoItem* item = new QTodoItem(vbox); insertTodoAtBottom(item); item->setDepth(depth); item->setTask((*it)->task); item->setPriority((*it)->priority); item->setDeadline((*it)->deadline); item->setCreated((*it)->created); item->setDone((*it)->done); item->setStatus((*it)->status); item->setAgent((*it)->agent); item->show(); loadNode((*it)->sub,depth+1); } }
AnimNode::Pointer AnimNodeLoader::load(const QByteArray& contents, const QUrl& jsonUrl) { // convert string into a json doc QJsonParseError error; auto doc = QJsonDocument::fromJson(contents, &error); if (error.error != QJsonParseError::NoError) { qCCritical(animation) << "AnimNodeLoader, failed to parse json, error =" << error.errorString(); return nullptr; } QJsonObject obj = doc.object(); // version QJsonValue versionVal = obj.value("version"); if (!versionVal.isString()) { qCCritical(animation) << "AnimNodeLoader, bad string \"version\""; return nullptr; } QString version = versionVal.toString(); // check version // AJT: TODO version check if (version != "1.0" && version != "1.1") { qCCritical(animation) << "AnimNodeLoader, bad version number" << version << "expected \"1.0\""; return nullptr; } // root QJsonValue rootVal = obj.value("root"); if (!rootVal.isObject()) { qCCritical(animation) << "AnimNodeLoader, bad object \"root\""; return nullptr; } return loadNode(rootVal.toObject(), jsonUrl); }
void QTodoList::load(QTodoTopNode* top_node) { loadNode(top_node->top,0); show(); refreshSpacer(); }
/*! * See \ref Loader3ds::loadFromFile */ dcollide::Proxy* Loader3dsInternal::loadFromFile(dcollide::World* world, const char* fileName, dcollide::ProxyTypes proxyType) { mData->mProxy2Transformation.clear(); mData->mProxy2TextureInformation.clear(); if (!fileName) { // TODO: exception? return 0; } mFile = lib3ds_file_load(fileName); if (!mFile) { std::cout << dc_funcinfo << "unable to load " << fileName << std::endl; return 0; } // AB: some files don't store nodes and just want exactly one node per mesh. // atm we don't support that. if (!mFile->nodes) { std::cout << dc_funcinfo << "File " << fileName << " does not contain any nodes. mesh-only files not supported currently." << std::endl; lib3ds_file_free(mFile); mFile = 0; return 0; } // 3ds stores several frames, we want the first lib3ds_file_eval(mFile, 0); if (!checkUniqueMeshMaterial()) { std::cerr << dc_funcinfo << "the file " << fileName << " contains at least one mesh with different materials. this is not supported by this modelloader, only the first material will be used!" << std::endl; } dcollide::Proxy* topObject = world->createProxy(proxyType); mData->mProxy2Transformation.insert(std::make_pair(topObject, Loader3ds::TransformationNode())); Lib3dsMatrix identityMatrix; lib3ds_matrix_identity(identityMatrix); Lib3dsNode* node = mFile->nodes; while (node) { // node->type can be object, light, camera, ... // -> only object nodes are relevant to us if (node->type == LIB3DS_OBJECT_NODE) { if (!loadNode(world, topObject, node, &identityMatrix)) { std::cerr << dc_funcinfo << "Loading node from " << fileName << " failed" << std::endl; // TODO: is MyObjectNode::mProxy being deleted? delete topObject; lib3ds_file_free(mFile); mFile = 0; return 0; } } node = node->next; } lib3ds_file_free(mFile); mFile = 0; return topObject; }
Node* SystemClipboard::loadSubNode(Node* parent, const QString& name) { if (!xml->hasChild(name)) return nullptr; xml->beginLoadChildNode(name); LoadedNode ln = loadNode(parent); xml->endLoadChildNode(); return ln.node; }
void NodeInstanceView::nodeCreated(const ModelNode &createdNode) { NodeInstance instance = loadNode(createdNode); if (isSkippedNode(createdNode)) return; nodeInstanceServer()->createInstances(createCreateInstancesCommand(QList<NodeInstance>() << instance)); nodeInstanceServer()->changePropertyValues(createChangeValueCommand(createdNode.variantProperties())); nodeInstanceServer()->completeComponent(createComponentCompleteCommand(QList<NodeInstance>() << instance)); }
bool Root::loadFrom(std::string name) { auto xml = Kriti::ResourceRegistry::get<Kriti::XMLResource>("conv/" + name); if(!xml) return false; auto objects = xml->doc().first_element_by_path("/conversation/objects"); // First pass to create objects. for(auto c = objects.first_child(); c ; c = c.next_sibling()) { int id = c.attribute("id").as_int(); if(!std::strcmp(c.name(), "node")) { m_nodeMap[id] = boost::make_shared<Node>(); } else if(!std::strcmp(c.name(), "context")) { m_contextMap[id] = boost::make_shared<Context>(); } else if(!std::strcmp(c.name(), "link")) { m_linkMap[id] = boost::make_shared<Link>(); } else { Message3(Game, Debug, "Unknown object type " << c.name()); } } // Second pass to parse objects. for(auto c = objects.first_child(); c ; c = c.next_sibling()) { int id = c.attribute("id").as_int(); if(!std::strcmp(c.name(), "node")) { loadNode(id, c); } else if(!std::strcmp(c.name(), "context")) { loadContext(id, c); } else if(!std::strcmp(c.name(), "link")) { loadLink(id, c); } else { Message3(Game, Debug, "Unknown object type " << c.name()); } } if(!m_rootNode) { Message3(Game, Error, "Couldn't load conversation \"" << name << "\": no root node"); return false; } return true; }
//---------------------------------------------------------------------------------------------------------------------- void FileList::loadStructure(std::ifstream &_fname) { std::string read; while(!_fname.eof() ) { _fname>>read; if(trim(read) == "ROOT") { _fname>>read; loadNode(_fname); } }
void NodeInstanceView::nodeCreated(const ModelNode &createdNode) { NodeInstance instance = loadNode(createdNode); if (isSkippedNode(createdNode)) return; QList<VariantProperty> propertyList; propertyList.append(createdNode.variantProperty("x")); propertyList.append(createdNode.variantProperty("y")); updatePosition(propertyList); nodeInstanceServer()->createInstances(createCreateInstancesCommand(QList<NodeInstance>() << instance)); nodeInstanceServer()->changePropertyValues(createChangeValueCommand(createdNode.variantProperties())); nodeInstanceServer()->completeComponent(createComponentCompleteCommand(QList<NodeInstance>() << instance)); }
void Ambient::playCurrentNode(uint32 volume, uint32 fadeOutDelay) { if (!fadeOutDelay) fadeOutDelay = 1; uint32 node = _vm->_state->getLocationNode(); uint32 room = _vm->_state->getLocationRoom(); uint32 age = _vm->_state->getLocationAge(); // Load sound descriptors loadNode(node, room, age); // Adjust volume scaleVolume(volume); // Play sounds applySounds(fadeOutDelay); }
/*! * \internal * * The objects created as children of \p parent will \em not be rotated or * translated correctly. Instead the required transformations are stored and * provided to the user, see \ref Loader3ds::getTransformationNodes */ bool Loader3dsInternal::loadNode(dcollide::World* world, dcollide::Proxy* parent, Lib3dsNode* node, Lib3dsMatrix* parentTranslateRotateMatrix) { if (!parent || !node) { return false; } if (node->type != LIB3DS_OBJECT_NODE) { return false; } Lib3dsObjectData* data = &node->data.object; Lib3dsMatrix translateRotateMatrix; lib3ds_matrix_copy(translateRotateMatrix, *parentTranslateRotateMatrix); lib3ds_matrix_translate(translateRotateMatrix, data->pos); lib3ds_matrix_rotate(translateRotateMatrix, data->rot); dcollide::Shape* shape = createShape(node, &translateRotateMatrix); dcollide::Proxy* object = world->createProxy(shape); mData->mProxy2TextureInformation.insert(std::make_pair(object, loadTextureInformation(node))); dcollide::Vector3 scale(data->scl[0], data->scl[1], data->scl[2]); dcollide::Vector3 translation(data->pos[0], data->pos[1], data->pos[2]); Lib3dsMatrix lib3dsRotationMatrix; lib3ds_matrix_identity(lib3dsRotationMatrix); lib3ds_matrix_rotate(lib3dsRotationMatrix, data->rot); dcollide::Matrix rotation(&lib3dsRotationMatrix[0][0]); Loader3ds::TransformationNode transformation; transformation.translation = translation; transformation.rotation = rotation; mData->mProxy2Transformation.insert(std::make_pair(object, transformation)); for (Lib3dsNode* n = node->childs; n; n = n->next) { if (!loadNode(world, object, n, &translateRotateMatrix)) { std::cerr << "Failed loading node " << n->name << std::endl; // TODO: delete object->getProxy() ? delete object; return false; } } parent->addChild(object); return true; }
QList<LoadedNode> SystemClipboard::loadAllSubNodes(Node* parent) { QList<LoadedNode> result; if ( xml->hasChildren() ) { xml->goToFirstChild(); while ( true ) { LoadedNode ln = loadNode(parent); result.append(ln); if ( xml->hasNext() ) xml->loadNext(); else break; } xml->goToParent(); } return result; }
CoronaLoader::CoronaLoader(const FileName& fileName, const AffineSpace3fa& space) { path = fileName.path(); Ref<XML> xml = parseXML(fileName,"/.-",false); if (xml->name == "scene") { Ref<SceneGraph::GroupNode> group = new SceneGraph::GroupNode; for (size_t i=0; i<xml->children.size(); i++) { group->add(loadNode(xml->children[i])); } root = group.cast<SceneGraph::Node>(); } else THROW_RUNTIME_ERROR(xml->loc.str()+": invalid scene tag"); if (space == AffineSpace3fa(one)) return; root = new SceneGraph::TransformNode(space,root); }
NodePtr LazyGraph::getNode(NodeId id) { if (id.id == NULL_ID) { return NULL; } map<NodeId, Node *>::iterator i = nodes.find(id); if (i != nodes.end()) { // if the requested resource has already been loaded NodePtr r = i->second; nodeCache->remove(r);// we remove it from the unusedResources Cache //r->owner = this; // and we return the resource return r; } if (Logger::DEBUG_LOGGER != NULL) { ostringstream os; os << "Loading node '" << id.id << "'"; Logger::DEBUG_LOGGER->log("GRAPH", os.str()); } // otherwise the resource is not already loaded; we first load its descriptor NodePtr r = NULL; long int offset; map<NodeId, long int>::iterator j = nodeOffsets.find(id); if (j != nodeOffsets.end()) { offset = j->second; r = loadNode(offset, id); nodes[id] = r.get(); mapping->insert(make_pair(r->getPos(), r.get())); return r; } if (Logger::ERROR_LOGGER != NULL) { ostringstream os; os << "Loading : Missing or invalid node '" << id.id << "'"; Logger::ERROR_LOGGER->log("GRAPH", os.str()); } throw exception(); // return NULL; }
void xmlLoader::loadReaction(reaction &r, ofxXmlSettings &XML) { r.rType = XML.getValue("TYPE", "closeOutZone"); r.trig = XML.getValue("TRIG", "ON"); if(XML.tagExists("PRESET"))r.stringParams["PRESET"] = XML.getValue("PRESET","default"); if(XML.tagExists("P_CHILD")){ clamourNode temp = presetStore::nodePresets[XML.getValue("P_CHILD","defaultNode")]; loadNode(temp, XML); r.tempNode = ofPtr<clamourNode>(new clamourNode(temp)); } if(XML.tagExists("SCALE"))r.floatParams["SCALE"] = XML.getValue("SCALE", 1.0); if(XML.tagExists("ENV_INDEX"))r.intParams["ENV_INDEX"] = XML.getValue("ENV_INDEX", 1); if(XML.tagExists("DELAY_SECS"))r.floatParams["DELAY_SECS"] = XML.getValue("DELAY_SECS", 0.25); if(XML.tagExists("NAME"))r.stringParams["NAME"] = XML.getValue("NAME", ""); int numZs = XML.getNumTags("Z_TARGET"); for(int i = 0; i < numZs; i++){ r.zTargets.push_back(XML.getValue("Z_TARGET", "",i)); } }
/*! \brief Notifing the view that a node was created. A NodeInstance will be created for the new created ModelNode. \param createdNode New created ModelNode. */ void NodeInstanceView::nodeCreated(const ModelNode &createdNode) { loadNode(createdNode); }
static AnimNode::Pointer loadNode(const QJsonObject& jsonObj, const QUrl& jsonUrl) { auto idVal = jsonObj.value("id"); if (!idVal.isString()) { qCCritical(animation) << "AnimNodeLoader, bad string \"id\""; return nullptr; } QString id = idVal.toString(); auto typeVal = jsonObj.value("type"); if (!typeVal.isString()) { qCCritical(animation) << "AnimNodeLoader, bad object \"type\", id =" << id; return nullptr; } QString typeStr = typeVal.toString(); AnimNode::Type type = stringToAnimNodeType(typeStr); if (type == AnimNode::Type::NumTypes) { qCCritical(animation) << "AnimNodeLoader, unknown node type" << typeStr << ", id =" << id; return nullptr; } auto dataValue = jsonObj.value("data"); if (!dataValue.isObject()) { qCCritical(animation) << "AnimNodeLoader, bad string \"data\", id =" << id; return nullptr; } auto dataObj = dataValue.toObject(); std::vector<QString> outputJoints; auto outputJoints_VAL = dataObj.value("outputJoints"); if (outputJoints_VAL.isArray()) { QJsonArray outputJoints_ARRAY = outputJoints_VAL.toArray(); for (int i = 0; i < outputJoints_ARRAY.size(); i++) { outputJoints.push_back(outputJoints_ARRAY.at(i).toString()); } } assert((int)type >= 0 && type < AnimNode::Type::NumTypes); auto node = (animNodeTypeToLoaderFunc(type))(dataObj, id, jsonUrl); if (!node) { return nullptr; } auto childrenValue = jsonObj.value("children"); if (!childrenValue.isArray()) { qCCritical(animation) << "AnimNodeLoader, bad array \"children\", id =" << id; return nullptr; } auto childrenArray = childrenValue.toArray(); for (const auto& childValue : childrenArray) { if (!childValue.isObject()) { qCCritical(animation) << "AnimNodeLoader, bad object in \"children\", id =" << id; return nullptr; } AnimNode::Pointer child = loadNode(childValue.toObject(), jsonUrl); if (child) { node->addChild(child); } else { return nullptr; } } if ((animNodeTypeToProcessFunc(type))(node, dataObj, id, jsonUrl)) { for (auto&& outputJoint : outputJoints) { node->addOutputJoint(outputJoint); } return node; } else { return nullptr; } }