|
|
|
@ -18,10 +18,13 @@ class AHB_Render:
|
|
|
|
|
for obj in doc.Objects: |
|
|
|
|
if obj.TypeId == 'Part::Feature': |
|
|
|
|
if 'AssemblyHandbook_Stage' in obj.PropertiesList: |
|
|
|
|
if 'AssemblyHandbook_RenderLines' in obj.PropertiesList and not obj.AssemblyHandbook_RenderLines: |
|
|
|
|
obj.ViewObject.LineColor = background_color |
|
|
|
|
else: |
|
|
|
|
obj.ViewObject.LineColor = line_color |
|
|
|
|
obj.ViewObject.DisplayMode = 'Flat Lines' |
|
|
|
|
obj.ViewObject.ShapeMaterial.AmbientColor = (0.0, 0.0, 0.0, 0.0) |
|
|
|
|
obj.ViewObject.ShapeMaterial.EmissiveColor = background_color |
|
|
|
|
obj.ViewObject.LineColor = line_color |
|
|
|
|
|
|
|
|
|
def set_render_outlines(self): |
|
|
|
|
doc = App.activeDocument() |
|
|
|
@ -49,7 +52,7 @@ class AHB_Render:
|
|
|
|
|
b = step |
|
|
|
|
|
|
|
|
|
def Activated(self): |
|
|
|
|
resolution = (512, 512) |
|
|
|
|
resolution = (1024, 1024) |
|
|
|
|
|
|
|
|
|
self.set_render_lines() |
|
|
|
|
Gui.ActiveDocument.ActiveView.saveImage("/home/youen/dev_linux/vhelio-render/vhelio.png", resolution[0], resolution[1], "#ffffff") |
|
|
|
@ -62,25 +65,41 @@ class AHB_Render:
|
|
|
|
|
lines = Image.open("/home/youen/dev_linux/vhelio-render/vhelio.png") |
|
|
|
|
lines = lines.convert("L") |
|
|
|
|
shapes = Image.open("/home/youen/dev_linux/vhelio-render/vhelio-shapes.png") |
|
|
|
|
|
|
|
|
|
cacheWidth = 8 |
|
|
|
|
cacheHalfWidth = int(cacheWidth/2) |
|
|
|
|
cache = [] |
|
|
|
|
for y in range(0, 4): |
|
|
|
|
cacheLine = [] |
|
|
|
|
for x in range(0, cacheWidth + 2): |
|
|
|
|
cacheLine.append((0.0,0.0,0.0)) |
|
|
|
|
cache.append(cacheLine) |
|
|
|
|
|
|
|
|
|
startTime = time.perf_counter() |
|
|
|
|
for xb in range(1, lines.size[0]-1): |
|
|
|
|
for xb in range(1, lines.size[0]-cacheHalfWidth, cacheHalfWidth): |
|
|
|
|
for yb in range(1, lines.size[1]-1): |
|
|
|
|
outline_color = 1.0 |
|
|
|
|
for x in range(xb*2, xb*2+2): |
|
|
|
|
for y in range(yb*2, yb*2+2): |
|
|
|
|
c = shapes.getpixel((x, y)) |
|
|
|
|
border = False |
|
|
|
|
if c != shapes.getpixel((x - 1, y - 1)): border = True |
|
|
|
|
if c != shapes.getpixel((x, y - 1)): border = True |
|
|
|
|
if c != shapes.getpixel((x + 1, y - 1)): border = True |
|
|
|
|
if c != shapes.getpixel((x - 1, y)): border = True |
|
|
|
|
if c != shapes.getpixel((x, y)): border = True |
|
|
|
|
if c != shapes.getpixel((x + 1, y)): border = True |
|
|
|
|
if c != shapes.getpixel((x - 1, y + 1)): border = True |
|
|
|
|
if c != shapes.getpixel((x, y + 1)): border = True |
|
|
|
|
if c != shapes.getpixel((x + 1, y + 1)): border = True |
|
|
|
|
if border: outline_color = outline_color - 0.25 |
|
|
|
|
lines.putpixel((xb, yb), min(lines.getpixel((xb, yb)), int(outline_color * 255.0))) |
|
|
|
|
for y in range(0, 4): |
|
|
|
|
cacheLine = cache[y] |
|
|
|
|
for x in range(0, cacheWidth + 2): |
|
|
|
|
cacheLine[x] = shapes.getpixel((xb*2+x-1, yb*2+y-1)) |
|
|
|
|
|
|
|
|
|
for xa in range(0, cacheHalfWidth): |
|
|
|
|
outline_color = 1.0 |
|
|
|
|
for xaa in range(0, 2): |
|
|
|
|
x = xa*2 + xaa |
|
|
|
|
for y in range(0, 2): |
|
|
|
|
c = cache[y+1][x+1] |
|
|
|
|
border = False |
|
|
|
|
if c != cache[y][x]: border = True |
|
|
|
|
if c != cache[y][x+1]: border = True |
|
|
|
|
if c != cache[y][x+2]: border = True |
|
|
|
|
if c != cache[y+1][x]: border = True |
|
|
|
|
if c != cache[y+1][x+2]: border = True |
|
|
|
|
if c != cache[y+2][x]: border = True |
|
|
|
|
if c != cache[y+2][x+1]: border = True |
|
|
|
|
if c != cache[y+2][x+2]: border = True |
|
|
|
|
if border: outline_color = outline_color - 0.25 |
|
|
|
|
lines.putpixel((xb+xa, yb), min(lines.getpixel((xb+xa, yb)), int(outline_color * 255.0))) |
|
|
|
|
endTime = time.perf_counter() |
|
|
|
|
print("Outline detection: " + str(round((endTime - startTime)*1000)/1000) + "s") |
|
|
|
|
lines.save("/home/youen/dev_linux/vhelio-render/vhelio-final.png") |
|
|
|
|