OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

OFF : create deserializer and serializer

Open z3dev opened this issue 4 years ago • 15 comments

Expected Behavior

Deserializer

  • Drag-n-drop OFF file to web, and view 2D / 3D design
  • Convert OFF file to STL, etc.

Serializer

  • Export 2D / 3D design to OFF file
  • Convert STL file to OFF file

Actual Behavior

Not available

Steps to Reproduce the Problem

  1. Not available

Specifications

http://www.geomview.org/docs/html/OFF.html

https://people.sc.fsu.edu/~jburkardt/data/off/off.html

z3dev avatar Jan 04 '21 04:01 z3dev

@gilboonet might be interested in creating these now that V2 is functional. it should be slightly easier to create, test, and package now.

z3dev avatar Jan 04 '21 04:01 z3dev

@z3dev I'm not sure I am skilled enough for that (I know almost nothing about git, node package and when I tried, I was able to code serializer but when I started to test it, I never managed to debug properly), but I will give it a try.

gilboonet avatar Jan 04 '21 19:01 gilboonet

@gilboonet please try again.

To start...

  • git clone the repository
  • cd OpenJSCAD.org
  • git checkout V2

And create a copy of the OBJ deserializer

  • cd packages/io
  • cp -R obj-deserializer ./off-deserializer

Next, adjust the package information

  • cd off-deserializer
  • Edit package.json

Now, the package can be linked up with the other packages for development.

  • cd ../../..
  • npm install
  • npm run bootstrap

Once done, then development of the OFF deserializer can start. Of course, you will have to change the code in index.js

If you want, I can follow along. You will have to fork OpenJSCAD.org.

z3dev avatar Jan 05 '21 00:01 z3dev

I created a folder for this, followed the steps and for the moment it is all ok. I will start the deserializer and will get back to you for the next steps.

gilboonet avatar Jan 06 '21 16:01 gilboonet

I wrote the deserializer and now I need to test. Apparently the two files instantiate.test.js and translate.test.js need to be changed. What do I need to do to test ? It's the point where I was stopped last time, my test was not ok and I didn't knew how to debug. Capture d’écran de 2021-01-08 22-04-03

gilboonet avatar Jan 08 '21 21:01 gilboonet

I wrote the deserializer and now I need to test. Apparently the two files instantiate.test.js and translate.test.js need to be changed. What do I need to do to test ?

👍

Just start easy, and create a single test case.

  • Move instantiate.test.js and translate.test.js to another directory
  • Create a new translate.test.js with just one test case (cut and paste from the old)
  • In the first test case, pass a text string as input to deserialize()

The first test case is just to check logic, and verify the basic translation.

You can use console.log() to see the translation. And you can add console.log() to debug functions or logic if there are problems.

Expect a few issues at first. Fix bugs, and add more test cases. If working well then add some more functionality. ... repeat... repeat...

z3dev avatar Jan 08 '21 22:01 z3dev

I started the first test. Put together a simple test case into translate.test.js then run "npm test. The test failed but shows no difference between observed and expected, so I don't see how to resolve that. Capture d’écran de 2021-01-10 12-09-56

gilboonet avatar Jan 10 '21 11:01 gilboonet

Great!

I suggest using something like this for testing translation, as strings can be different across operating systems. (From AMF deserializer tests)

const countOf = (search, string) => {
  let count = 0
  let index = string.indexOf(search)
  while (index !== -1) {
    count++
    index = string.indexOf(search, index + 1)
  }
  return count
}

test('deserialize simple amf file to jscad script', (t) => {
  const inputPath = path.resolve(samplesPath, 'amf/Amf_Cube.amf')
  const inputFile = fs.readFileSync(inputPath)

  const observed = deserializer.deserialize({ output: 'script', addMetaData: false }, inputFile)
  t.is(countOf('poly3.fromPoints', observed), 12)
  t.is(countOf('polygon.color', observed), 12)
  t.is(countOf('geom3.create', observed), 1)
})

z3dev avatar Jan 10 '21 11:01 z3dev

@gilboonet How are you progressing on the testing? I hope that you are making some good test cases. 👍

By the way, I'm working the X3D deserializer. I added a new pull request that contains the initial code. This should help you to understand how packages are 'linked' together. #757

z3dev avatar Jan 13 '21 00:01 z3dev

@z3dev I replaced deepEqual() by a simpler : t.is(countOf('primitives.polyhedron', observed), 1) and the basic test is ok, but then I added a console.log(observed) and it didn't have any data fetched from the test file, so I'm not sure that I understand enough the mechanics of testing to be able to help. Capture d’écran de 2021-01-14 18-43-44

gilboonet avatar Jan 14 '21 17:01 gilboonet

The left hand view doesn’t look correct. This shows the output from console.log(observed).

There are no points or faces. So, there are some issues in the translation.

Now, you need to find out why... you can add console.log() statements to make sure data is correct, as well as check parameters being passed to functions.

z3dev avatar Jan 14 '21 22:01 z3dev

@gilboonet how goes the testing? Are you making progress?

z3dev avatar Jan 22 '21 12:01 z3dev

@z3dev I didn't make any progress, my code looks ok, so I didn't find what to check. I don't think I'm skilled enough for such development even if I wrote a node js off to jscad translator that works, it requires more to be able to do the same into such a big project.

gilboonet avatar Jan 22 '21 18:01 gilboonet

@z3dev I didn't make any progress, my code looks ok, so I didn't find what to check. I don't think I'm skilled enough for such development even if I wrote a node js off to jscad translator that works, it requires more to be able to do the same into such a big project.

@gilboonet ok. it might be easier if i can comment on the code. have you created a fork of OpenJSCAD.org?

z3dev avatar Jan 23 '21 01:01 z3dev

Such project deals with too many tools/libraries/technologies and I don't feel I could be helpful and instead will make others lose time to help me. I think I could provide feedback and use cases, but not contribute efficiently to the code.

gilboonet avatar Jan 25 '21 14:01 gilboonet