59 for (
auto *prop : node->properties) {
60 auto &val = prop->value;
61 if (qvariant_cast<QSSGSceneDesc::Node *>(val) == resource) {
63 val = QVariant::fromValue(replacement);
65 if (val.metaType().id() == qMetaTypeId<QSSGSceneDesc::NodeList *>()) {
66 const auto &list = *qvariant_cast<QSSGSceneDesc::NodeList *>(val);
67 for (
int i = 0, end = list.count; i != end; ++i) {
68 if (list.head[i] == resource) {
69 list.head[i] = replacement;
74 for (
auto *child : node->children)
75 replaceReferencesToResource(child, resource, replacement);
80 QSSGSceneDesc::Node::Type type,
QSSGSceneDesc::Node **parent =
nullptr)
82 if (!root || name.isEmpty())
85 if (root->name == name && root->nodeType == type)
88 for (
auto *child : root->children) {
89 if (
auto *ret = findNode(child, name, type, parent)) {
90 if (parent && !*parent)
129 auto isTargeted = [nodes](QSSGSceneDesc::Animation::Channel *channel) {
return nodes.contains(channel->target); };
130 const auto end_it = animation->channels.end();
131 auto remove_it = std::remove_if(animation->channels.begin(), end_it, isTargeted);
132 for (
auto it = remove_it; it != end_it; ++it)
134 animation->channels.erase(remove_it, end_it);
161 auto it = nodeRef.constBegin();
162 if (it == nodeRef.constEnd())
164 auto nodeType = nodeTypeFromName(it.key().toUtf8());
165 auto nodeName = it.value().toString().toUtf8();
166 auto *node = findResource(scene, nodeName, nodeType);
168 node = findNode(scene->root, nodeName, nodeType);
200 if (value.isArray()) {
201 var = QVariant::fromValue(nodeListFromJson(node->scene, value.toArray()));
202 }
else if (value.isObject()) {
203 auto obj = value.toObject();
204 if (obj.contains(u"url")) {
205 auto path = obj.value(u"url").toString();
206 var = QVariant::fromValue(QUrl(path));
209 var = QVariant::fromValue(n);
212 var = value.toVariant();
215 const auto name = propertyName.toUtf8();
216 removeProperty(node, name);
217 auto *property = QSSGSceneDesc::setProperty(*node, name, std::move(var));
220 QSSGRuntimeUtils::applyPropertyValue(node, node->obj, property);
226 auto name = addition.value(u"name").toString().toUtf8();
227 auto typeName = addition.value(u"type").toString().toUtf8();
228 if (name.isEmpty() || typeName.isEmpty()) {
229 qWarning(
"Can't create node without name or type");
234 QSSGSceneDesc::Node *prevResource = findResource(scene, name, nodeTypeFromName(typeName));
236 if (typeName ==
"Material") {
237 bool isSpecGlossy = addition.contains(u"albedoColor") || addition.contains(u"albedoMap")
238 || addition.contains(u"glossinessMap") || addition.contains(u"glossiness");
239 typeName = isSpecGlossy ?
"SpecularGlossyMaterial" :
"PrincipledMaterial";
242 if (typeName ==
"PrincipledMaterial") {
243 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Material,
244 QSSGRenderGraphObject::Type::PrincipledMaterial);
245 }
else if (typeName ==
"SpecularGlossyMaterial") {
246 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Material,
247 QSSGRenderGraphObject::Type::SpecularGlossyMaterial);
248 }
else if (typeName ==
"Texture") {
249 node =
new QSSGSceneDesc::Node(name, QSSGSceneDesc::Node::Type::Texture,
250 QSSGRenderGraphObject::Type::Image2D);
252 qWarning() <<
"Not supported. Don't know how to create" << typeName;
257 for (
auto it = addition.constBegin(); it != addition.constEnd(); ++it) {
258 const auto &propertyName = it.key();
259 if (propertyName == u"name" || propertyName == u"type" || propertyName == u"comment" || propertyName == u"command")
261 setProperty(node, it.key(), it.value());
265 replaceReferencesToResource(scene->root, prevResource, node);
266 scene->resources.removeOne(prevResource);
270 QSSGSceneDesc::addNode(*scene, *node);
276 auto doApply = [scene](
const QJsonObject &obj) {
277 QByteArray name = obj.value(u"name").toString().toUtf8();
278 QByteArray typeName = obj.value(u"type").toString().toUtf8();
279 auto command = obj.value(u"command").toString(u"edit"_s);
280 auto nodeType = nodeTypeFromName(typeName);
281 if (command == u"edit") {
282 auto *node = findNode(scene->root, name, nodeType);
284 node = findResource(scene, name, nodeType);
286 for (
auto it = obj.constBegin(); it != obj.constEnd(); ++it) {
287 const auto &propertyName = it.key();
288 if (propertyName == u"name" || propertyName == u"type" || propertyName == u"comment" || propertyName == u"command")
290 setProperty(node, it.key(), it.value());
293 }
else if (command == u"add") {
295 }
else if (command == u"delete") {
297 auto *node = findNode(scene->root, name, nodeType, &parent);
301 unlinkChild(node, parent);
303 qWarning(
"Delete: could not find parent for node");
308 const auto editList = changes.value(u"editList").toArray();
312 for (
auto edit : editList) {
313 auto obj = edit.toObject();
314 if (obj.value(u"command") == u"add"_s)
318 for (
auto edit : editList) {
319 auto obj = edit.toObject();
320 if (obj.value(u"command") != u"add"_s)