jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.69k stars 517 forks source link

OFF : create deserializer and serializer #753

Open z3dev opened 3 years ago

z3dev commented 3 years ago

Expected Behavior

Deserializer

Serializer

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 commented 3 years ago

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

gilboonet commented 3 years ago

@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.

z3dev commented 3 years ago

@gilboonet please try again.

To start...

And create a copy of the OBJ deserializer

Next, adjust the package information

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

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.

gilboonet commented 3 years ago

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 commented 3 years ago

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

z3dev commented 3 years ago

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.

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...

gilboonet commented 3 years ago

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

z3dev commented 3 years ago

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 commented 3 years ago

@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

gilboonet commented 3 years ago

@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

z3dev commented 3 years ago

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 commented 3 years ago

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

gilboonet commented 3 years ago

@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.

z3dev commented 3 years ago

@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?

gilboonet commented 3 years ago

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.