57 for (
auto *prop : node->properties) {
58 auto &val = prop->value;
59 if (qvariant_cast<QSSGSceneDesc::Node *>(val) == resource) {
61 val = QVariant::fromValue(replacement);
63 if (val.metaType().id() == qMetaTypeId<QSSGSceneDesc::NodeList *>()) {
64 const auto &list = *qvariant_cast<QSSGSceneDesc::NodeList *>(val);
65 for (
int i = 0, end = list.count; i != end; ++i) {
66 if (list.head[i] == resource) {
67 list.head[i] = replacement;
72 for (
auto *child : node->children)
73 replaceReferencesToResource(child, resource, replacement);
78 QSSGSceneDesc::Node::Type type,
QSSGSceneDesc::Node **parent =
nullptr)
80 if (!root || name.isEmpty())
83 if (root->name == name && root->nodeType == type)
86 for (
auto *child : root->children) {
87 if (
auto *ret = findNode(child, name, type, parent)) {
88 if (parent && !*parent)
127 auto isTargeted = [nodes](QSSGSceneDesc::Animation::Channel *channel) {
return nodes.contains(channel->target); };
128 const auto end_it = animation->channels.end();
129 auto remove_it = std::remove_if(animation->channels.begin(), end_it, isTargeted);
130 for (
auto it = remove_it; it != end_it; ++it)
132 animation->channels.erase(remove_it, end_it);
159 auto it = nodeRef.constBegin();
160 if (it == nodeRef.constEnd())
162 auto nodeType = nodeTypeFromName(it.key().toUtf8());
163 auto nodeName = it.value().toString().toUtf8();
164 auto *node = findResource(scene, nodeName, nodeType);
166 node = findNode(scene->root, nodeName, nodeType);
198 if (value.isArray()) {
199 var = QVariant::fromValue(nodeListFromJson(node->scene, value.toArray()));
200 }
else if (value.isObject()) {
201 auto obj = value.toObject();
202 if (obj.contains(u"url")) {
203 auto path = obj.value(u"url").toString();
204 var = QVariant::fromValue(QUrl(path));
207 var = QVariant::fromValue(n);
210 var = value.toVariant();
213 const auto name = propertyName.toUtf8();
214 removeProperty(node, name);
215 auto *property = QSSGSceneDesc::setProperty(*node, name, std::move(var));
218 QSSGRuntimeUtils::applyPropertyValue(node, node->obj, property);
224 auto name = addition.value(u"name").toString().toUtf8();
225 auto typeName = addition.value(u"type").toString().toUtf8();
226 if (name.isEmpty() || typeName.isEmpty()) {
227 qWarning(
"Can't create node without name or type");
232 QSSGSceneDesc::Node *prevResource = findResource(scene, name, nodeTypeFromName(typeName));
234 if (typeName ==
"Material") {
235 bool isSpecGlossy = addition.contains(u"albedoColor") || addition.contains(u"albedoMap")
236 || addition.contains(u"glossinessMap") || addition.contains(u"glossiness");
237 typeName = isSpecGlossy ?
"SpecularGlossyMaterial" :
"PrincipledMaterial";
240 if (typeName ==
"PrincipledMaterial") {
241 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Material,
242 QSSGRenderGraphObject::Type::PrincipledMaterial);
243 }
else if (typeName ==
"SpecularGlossyMaterial") {
244 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Material,
245 QSSGRenderGraphObject::Type::SpecularGlossyMaterial);
246 }
else if (typeName ==
"Texture") {
247 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Texture,
248 QSSGRenderGraphObject::Type::Image2D);
250 qWarning() <<
"Not supported. Don't know how to create" << typeName;
255 for (
auto it = addition.constBegin(); it != addition.constEnd(); ++it) {
256 const auto &propertyName = it.key();
257 if (propertyName == u"name" || propertyName == u"type" || propertyName == u"comment" || propertyName == u"command")
259 setProperty(node, it.key(), it.value());
263 replaceReferencesToResource(scene->root, prevResource, node);
264 scene->resources.removeOne(prevResource);
268 QSSGSceneDesc::addNode(*scene, *node);
274 auto doApply = [scene](
const QJsonObject &obj) {
275 QByteArray name = obj.value(u"name").toString().toUtf8();
276 QByteArray typeName = obj.value(u"type").toString().toUtf8();
277 auto command = obj.value(u"command").toString(u"edit"_s);
278 auto nodeType = nodeTypeFromName(typeName);
279 if (command == u"edit") {
280 auto *node = findNode(scene->root, name, nodeType);
282 node = findResource(scene, name, nodeType);
284 for (
auto it = obj.constBegin(); it != obj.constEnd(); ++it) {
285 const auto &propertyName = it.key();
286 if (propertyName == u"name" || propertyName == u"type" || propertyName == u"comment" || propertyName == u"command")
288 setProperty(node, it.key(), it.value());
291 }
else if (command == u"add") {
293 }
else if (command == u"delete") {
295 auto *node = findNode(scene->root, name, nodeType, &parent);
299 unlinkChild(node, parent);
301 qWarning(
"Delete: could not find parent for node");
306 const auto editList = changes.value(u"editList").toArray();
310 for (
auto edit : editList) {
311 auto obj = edit.toObject();
312 if (obj.value(u"command") == u"add"_s)
316 for (
auto edit : editList) {
317 auto obj = edit.toObject();
318 if (obj.value(u"command") != u"add"_s)