Three.js: EdgesGeometry: Add serialization/ deserialization

Created on 16 Jun 2018  路  11Comments  路  Source: mrdoob/three.js

All my scene objects is created with a wireframe. When I export objects from the scene it works ok with the code bellow:

var objList = $this.getSceneObjects()
for (var i in objList) {
  $this.savefile.scene.objects.push(objList[i].toJSON())
}

Then I put all objects together, store some more needed information and save in a whatever file. So my program will open this file, it's not an importation at all, it's an opening to keep editing objects... But when I try to do it, I get a lot of errors. That's my opening code:

var fileJson = JSON.parse(fs.readFileSync(file))
var document = new App.Document(file)

// Load Scene saved objects
var loader = new THREE.ObjectLoader();
for (var obj in fileJson.scene.objects) {
  var item = fileJson.scene.objects[obj]
  document.getScene().add(loader.parse(item))
}

Note in the image attached that none of the objects could be rendered with that wireframe I said before... =/

Three.js version
  • [ ] Dev
  • [x] r93
  • [ ] ...
Browser
  • [ ] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
  • [x] Chromium
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS

captura de tela de 2018-06-14 20-54-25

Enhancement

All 11 comments

Seems like ObjectLoader can't process EdgesGeometry yet.

Does it work if you are not using EdgesGeometry in your app?

Even without a test I would answer 'Yes' because to work around it I'm removing that from the object children and creating again as following code bellow. So yes, I guess the only one problem is the EdgesGeometry:

// @todo: THREE.EdgesGeometry Fix
// Three js can not load EdgesGeometry for now
piece.children.splice(0, 1) // Remove wireframe
var edges = new THREE.EdgesGeometry(piece.geometry)
var wireframe = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({
  name: 'wireframe',
  color: App.getColorContrast(piece.material.color.getHex())
}))
piece.add(wireframe)

Serialization/ deserialization of EdgesGeometry is somewhat tricky since it has a geometry object as parameter. Let's label this issue as a feature request. For now, a workaround is to manually create EdgesGeometry in your app when you load a scene. I know it's not a nice solution but it should work.

Thanks a lot! I'll be waiting for it with no problems. =)

@marcobraghim Can you please check if #14357 solves your issue?

Let me check it out =D

Yeah!! It works just fine for me. Thank you very much =D

letItBePulledPlease

captura de tela de 2018-06-23 14-37-17
=D

Thanks for testing!

why it's not being merged? i think it works. Or u guys give me some advice to make use of worker.

Closing in favor of #16340.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexprut picture alexprut  路  3Comments

filharvey picture filharvey  路  3Comments

zsitro picture zsitro  路  3Comments

donmccurdy picture donmccurdy  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments