Skip to content

Commit

Permalink
Merge pull request #59 from MozillaReality/features/orphaned-nodes
Browse files Browse the repository at this point in the history
Enable orphaned nodes editing
  • Loading branch information
tony056 committed Jul 19, 2018
2 parents 1c3dffa + 2790fcb commit 737b41e
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 46 deletions.
230 changes: 230 additions & 0 deletions example/ArchitectureKit/Pillar1x3Rnd-copy.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
{
"asset": {
"generator": "Maya2glTF V0.9.7-BETA ab18f62",
"version": "2.0"
},
"scenes": [
{
"nodes": [
0
]
}
],
"scene": 0,
"nodes": [
{
"children": [
1, 2
],
"name": "Pillar1x3Rnd"
},
{
"mesh": 0,
"name": "Pillar1x3RndShape"
},
{
"mesh": 0,
"name": "Pillar1x3RndShape"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2,
"TANGENT": 3,
"TEXCOORD_0": 4
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "Pillar1x3RndShape"
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"count": 96,
"max": [
33
],
"min": [
0
],
"type": "SCALAR"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"count": 34,
"max": [
1.0,
0.0,
1.0
],
"min": [
-1.0,
0.0,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 408,
"componentType": 5126,
"count": 34,
"max": [
0.5,
2.875,
0.5
],
"min": [
-0.5,
-0.125,
-0.5
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 0,
"componentType": 5126,
"count": 34,
"max": [
1.0,
0.0,
1.0,
1.0
],
"min": [
-1.0,
-0.00004983339749742299,
-1.0,
1.0
],
"type": "VEC4"
},
{
"bufferView": 3,
"byteOffset": 0,
"componentType": 5126,
"count": 34,
"max": [
0.2951218783855438,
0.9983994364738464
],
"min": [
0.002477162284776569,
0.7171487808227539
],
"type": "VEC2"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
1.0,
1.0,
1.0,
1.0
],
"baseColorTexture": {
"index": 0
},
"metallicFactor": 1.0,
"roughnessFactor": 1.0,
"metallicRoughnessTexture": {
"index": 1
}
},
"emissiveFactor": [
0.0,
0.0,
0.0
],
"normalTexture": {
"index": 2
},
"occlusionTexture": {
"index": 2
}
}
],
"textures": [
{
"sampler": 0,
"source": 0
},
{
"sampler": 0,
"source": 1
},
{
"sampler": 0,
"source": 2
}
],
"images": [
{
"uri": "ArchModuleTex_Albedo.jpg"
},
{
"uri": "ArchModuleTex_NormalMap-ArchModuleTex_Metalness.jpg"
},
{
"uri": "ArchModuleTex_NormalMap.jpg"
}
],
"samplers": [
{
"magFilter": 9729,
"minFilter": 9987,
"wrapS": 10497,
"wrapT": 10497
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 1632,
"byteLength": 192,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 544,
"byteLength": 816,
"byteStride": 12,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 544,
"byteStride": 16,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 1360,
"byteLength": 272,
"byteStride": 8,
"target": 34962
}
],
"buffers": [
{
"byteLength": 1824,
"uri": "Pillar1x3Rnd0.bin"
}
]
}
Binary file added example/ArchitectureKit/Pillar1x3Rnd-copy0.bin
Binary file not shown.
37 changes: 37 additions & 0 deletions example/missing-n-duplicate.scene
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"entities": {
"New_Node1": {
"parent": "Pillar1x3RndShape",
"index": 0
},
"New_Node2": {
"parent": "Pillar1x3RndShape",
"index": 1
},
"New_Node3": {
"parent": "Pillar1x3Rnd1",
"index": 0
},
"New_Node4": {
"parent": "New_Node3",
"index": 0
},
"New_Node5": {
"parent": "New_Node4",
"index": 0
},
"New_Node6": {
"parent": "New_Node4",
"index": 0
},
"New_Node7": {
"parent": "New_Node6",
"index": 0
},
"New_Node8": {
"parent": "New_Node6",
"index": 0
}
},
"inherits": "./ArchitectureKit/Pillar1x3Rnd-copy.gltf"
}
25 changes: 25 additions & 0 deletions example/missing-node2.scene
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"entities": {
"New_Node1": {
"parent": "Wall2x3Win1x0_75HorzShape",
"index": 0
},
"New_Node2": {
"parent": "Wall2x3Win1x0_75HorzShape1",
"index": 1
},
"New_Node3": {
"parent": "Wall2x3Win1x0_75Horz",
"index": 1
},
"New_Node4": {
"parent": "New_Node5",
"index": 0
},
"New_Node6": {
"parent": "New_Node4",
"index": 0
}
},
"inherits": "./ArchitectureKit/Wall2x3Win1x0_75Horz.gltf"
}
96 changes: 96 additions & 0 deletions src/client/editor/ConflictHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
export default class ConflictHandler {
constructor() {
this._conflicts = {
missing: false,
duplicate: false
};
this._duplicateList = {};
}

findDuplicates = (node, layer, index) => {
if (node.userData._path) {
node.userData._path.push(index);
} else {
node.userData._path = [0];
}

const name = node.name;
this._duplicateList[name] = name in this._duplicateList ? this._duplicateList[name] + 1 : 1;
if (this._duplicateList[name] > 1) {
this.setDuplicateStatus(true);
}

if (node.children) {
node.children.forEach((child, i) => {
child.userData._path = node.userData._path.slice(0);
this.findDuplicates(child, layer + 1, i);
});
}
};

setDuplicateStatus = newStatus => {
this._conflicts.duplicate = newStatus;
};

setMissingStatus = newStatus => {
this._conflicts.missing = newStatus;
};

getDuplicateByName = name => {
if (!(name in this._duplicateList)) {
return false;
}
return this._duplicateList[name] > 1;
};

getConflictInfo = () => {
return this._conflicts;
};

updateAllDuplicateStatus = scene => {
scene.traverse(child => {
if (child === scene) {
return;
}
child.userData._duplicate = this.getDuplicateByName(child.name);
child.userData._isDuplicateRoot = child.userData._duplicate;
});
};

updateNodesMissingStatus = scene => {
this._updateNodesConflictInfoByProperty(scene, "_missing");
};

updateNodesDuplicateStatus = scene => {
this._updateNodesConflictInfoByProperty(scene, "_duplicate");
};

_updateNodesConflictInfoByProperty = (scene, propertyName) => {
scene.traverse(child => {
if (child === scene) {
return;
}
if (!child.userData._isMissingRoot && !child.userData._isDuplicateRoot) {
child.userData[propertyName] = child.parent ? child.parent.userData[propertyName] : false;
}
});
};

checkResolvedMissingRoot = scene => {
let newStatus = false;
const resolvedList = [];
scene.traverse(child => {
if (child.userData._isMissingRoot) {
if (child.children.length > 0) {
newStatus = true;
} else {
child.userData._isMissingRoot = false;
child.userData._missing = false;
resolvedList.push(child);
}
}
});
this.setMissingStatus(newStatus);
return resolvedList;
};
}
Loading

0 comments on commit 737b41e

Please sign in to comment.