Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to create holes in a shape using begin and end contour #195

Closed
Salleyi75 opened this issue Jul 12, 2020 · 3 comments · Fixed by #197
Closed

Not able to create holes in a shape using begin and end contour #195

Salleyi75 opened this issue Jul 12, 2020 · 3 comments · Fixed by #197
Labels

Comments

@Salleyi75
Copy link

Describe the bug
An error is thrown ( hence p5 stops working ) when there are 2 or more vertex function calls between begin_contour and end_contour.

To Reproduce

from p5 import *

def draw():
	translate(50, 50)
	stroke(255, 0, 0)
	begin_shape()
	# Exterior part of shape, clockwise winding
	vertex(-40, -40)
	vertex(40, -40)
	vertex(40, 40)
	vertex(-40, 40)
	# # Interior part of shape, counter-clockwise winding
	begin_contour()
	vertex(-20, -20)
	vertex(-20, 20)
	vertex(20, 20)
	vertex(20, -20)
	end_contour()
	end_shape('CLOSE')

run(mode="P2D")

Run the above code

Expected behavior
A square that has a square hole in it is drawn.
image

Screenshots
If applicable, add screenshots to help explain your problem.
image

System information:

  • p5 release (version number or latest commit):0.6.0
  • Python version: Python 3.7.7
  • Operating system: Windows 10 (64 bit)

Additional context
The Error :

WARNING: Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\idlelib\run.py", line 155, in main
ret = method(*args, **kwargs)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\idlelib\run.py", line 548, in runcode
exec(code, self.locals)
File "C:\Users\Mubarak N Salley\Desktop\sd.py", line 20, in
run(mode="P2D")
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\sketch\userspace.py", line 159, in run
app.run()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app_default_app.py", line 62, in run
return default_app.run()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app\application.py", line 152, in run
return self._backend._vispy_run()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app\backends_glfw.py", line 194, in _vispy_run
self._vispy_process_events()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app\backends_glfw.py", line 183, in _vispy_process_events
timer._tick()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app\backends_glfw.py", line 516, in _tick
self._vispy_timer._timeout()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\app\timer.py", line 168, in _timeout
count=self.iter_count)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\util\event.py", line 455, in call
self._invoke_callback(cb, event)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback
self, cb_event=(cb, event))
<< caught exception here: >>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback
cb(event)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\sketch\base.py", line 104, in on_timer
self.draw_method()
File "C:\Users\Mubarak N Salley\Desktop\sd.py", line 18, in draw
end_shape('CLOSE')
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\core\primitives.py", line 69, in wrapped
draw_shape(s)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\core\primitives.py", line 583, in draw_shape
draw_shape(child_shape)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\core\primitives.py", line 581, in draw_shape
p5.renderer.render(shape)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\sketch\renderer2d.py", line 219, in render
vertices = shape._draw_vertices
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\core\shape.py", line 363, in _draw_vertices
self._retriangulate()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\p5\core\shape.py", line 328, in _retriangulate
n, _ = self.contour.shape
AttributeError: 'list' object has no attribute 'shape'
ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x24dc078c3c8>> for Event
ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x24dc078c3c8>> repeat 2
ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x24dc078c3c8>> repeat 4
ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x24dc078c3c8>> repeat 8

@ziyaointl
Copy link
Member

The tessellation part of p5py has been refactored. The newest version is not on p5py yet, but you can install from source to try it out!

Screenshot for the same scene using baac189:
Screen Shot 2020-07-12 at 3 26 36 PM

Notice that the contour isn't automatically closed. I'll fix it in a future PR.

@Salleyi75
Copy link
Author

Salleyi75 commented Jul 13, 2020

Thanks, it works now.
Tho it does not close I deal with that by adding one more vertex.

I saw this in the console, just FYI:

Unable to load numpy_formathandler accelerator from OpenGL_accelerate

And the bezier function creates a split curve when the following coords are inputted "bezier((85, 20), (10, 10), (90, 90), (15, 80))"for the python p5 baac189 commit version, should I create a new issue or should I post it here?
image

The point function is throwing an error, I will check if the issue has already been posted

I am going through the entire 2D portion of p5 so expect more issues from me
I am thinking of helping in the development of this library, what must I know?

@ziyaointl
Copy link
Member

Thanks, it works now.

You are welcome!

I saw this in the console, just FYI:

Unable to load numpy_formathandler accelerator from OpenGL_accelerate

Did a quick search and still not sure why this is happening... Probably a bug in PyOpenGL but I guess it's harmless if p5py can still run since we only use GLUTess from PyOpenGL and not anything else.

And the bezier function creates a split curve when the following coords are inputted "bezier((85, 20), (10, 10), (90, 90), (15, 80))"for the python p5 baac189 commit version, should I create a new issue or should I post it here?
image

I think this is a separate bug so please open another issue. Thanks for finding this out!

The point function is throwing an error, I will check if the issue has already been posted

Point rendering does seem to be broken as of now, and there has been a discussion in #186 on whether to rewrite it using the circle primitive.

I am going through the entire 2D portion of p5 so expect more issues from me

Thank you so much for doing this! Feel free to drop me an email if you could use some help.

I am thinking of helping in the development of this library, what must I know?

I don't think there are "must knows" about contributing to p5py. OpenGL knowledge is helpful, but there are still a lot of work that's either one or many abstraction levels higher than OpenGL. If there's something that you would like to change/discuss, feel free to open a PR/issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants