Import Fix, funcs moved, refs updated, ocl rename

Changed all imports from absolute to relative: 
- instead of importing the module 'cam' now imports come from '.' the relative parent folder
- importing the module into itself resulted in a circular import error, relative imports avoid this

Moved Functions, refs updated:
- some functions  (and 2 variables) only existed on the base level of the module, in the init file, and could not otherwise be accessed, they were moved into the utils file with other similar functions
- these were primarily called as update functions for Properties scattered across the addon, these have all been updated to reflect the new location and import convention

opencamlib_version rename:
- in 2 files there was a local variable named 'opencamlib_version' that was defined by a function called 'opencamlib_version' that returned the opencamlib_version
- this seemed to confuse Blender into thinking that it was being called before it was defined, and simply changing the variable name to 'ocl_version' while keeping the function name as 'opencamlib_version' fixed the issue
pull/269/head
SpectralVectors 2024-03-22 17:54:04 -04:00 zatwierdzone przez GitHub
rodzic c0febee968
commit cd4856c3d0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 37 dodań i 24 usunięć

Wyświetl plik

@ -11,9 +11,9 @@ import tempfile
from io_mesh_stl import blender_utils
import mathutils
import math
from cam.simple import activate
from cam.exception import *
from cam.async_op import progress_async
from ..simple import activate
from ..exception import *
from ..async_op import progress_async
OCL_SCALE = 1000.0
@ -59,9 +59,11 @@ async def ocl_sample(operation, chunks, use_cached_mesh=False):
cutter = None
if op_cutter_type == 'END':
cutter = ocl.CylCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
cutter = ocl.CylCutter(
(op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
elif op_cutter_type == 'BALLNOSE':
cutter = ocl.BallCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
cutter = ocl.BallCutter(
(op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
elif op_cutter_type == 'VCARVE':
cutter = ocl.ConeCutter((op_cutter_diameter + operation.skin * 2)
* 1000, op_cutter_tip_angle, cutter_length)
@ -89,7 +91,8 @@ async def ocl_sample(operation, chunks, use_cached_mesh=False):
for chunk in chunks:
for coord in chunk.get_points_np():
bdc.appendPoint(ocl.CLPoint(coord[0] * 1000, coord[1] * 1000, op_minz * 1000))
bdc.appendPoint(ocl.CLPoint(
coord[0] * 1000, coord[1] * 1000, op_minz * 1000))
await progress_async("OpenCAMLib sampling")
bdc.run()

Wyświetl plik

@ -13,16 +13,17 @@ import tempfile
import numpy as np
from subprocess import call
from cam.collision import BULLET_SCALE
from cam import simple
from cam.chunk import camPathChunk
from cam.simple import *
from cam.async_op import progress_async
from ..collision import BULLET_SCALE
from .. import simple
from .. import utils
from ..chunk import camPathChunk
from ..simple import *
from ..async_op import progress_async
from shapely import geometry as sgeometry
from .oclSample import get_oclSTL
from cam import utils
from cam.opencamlib.oclSample import ocl_sample
from .oclSample import (
get_oclSTL,
ocl_sample
)
OCL_SCALE = 1000.0
@ -84,14 +85,17 @@ def exportModelsToSTL(operation):
bpy.ops.object.duplicate(linked=False)
# collision_object = bpy.context.scene.objects.active
# bpy.context.scene.objects.selected = collision_object
file_name = os.path.join(tempfile.gettempdir(), "model{0}.stl".format(str(file_number)))
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
file_name = os.path.join(
tempfile.gettempdir(), "model{0}.stl".format(str(file_number)))
bpy.ops.object.transform_apply(
location=True, rotation=True, scale=True)
bpy.ops.transform.resize(value=(OCL_SCALE, OCL_SCALE, OCL_SCALE), constraint_axis=(False, False, False),
orient_type='GLOBAL', mirror=False, use_proportional_edit=False,
proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False,
snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0),
texture_space=False, release_confirm=False)
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
bpy.ops.object.transform_apply(
location=True, rotation=True, scale=True)
bpy.ops.export_mesh.stl(check_existing=True, filepath=file_name, filter_glob="*.stl", use_selection=True,
ascii=False, use_mesh_modifiers=True, axis_forward='Y', axis_up='Z', global_scale=1.0)
bpy.ops.object.delete()
@ -119,7 +123,8 @@ async def oclResampleChunks(operation, chunks_to_resample, use_cached_mesh):
sample_index = 0
for chunk, i_start, i_length in chunks_to_resample:
z = np.array([p.z for p in samples[sample_index:sample_index+i_length]]) / OCL_SCALE
z = np.array(
[p.z for p in samples[sample_index:sample_index+i_length]]) / OCL_SCALE
pts = chunk.get_points_np()
pt_z = pts[i_start:i_start+i_length, 2]
pt_z = np.where(z > pt_z, z, pt_z)
@ -149,7 +154,8 @@ def oclGetMedialAxis(operation, chunks):
oclWaterlineHeightsToOCL(operation)
operationSettingsToOCL(operation)
curvesToOCL(operation)
call([PYTHON_BIN, os.path.join(bpy.utils.script_path_pref(), "addons", "cam", "opencamlib", "ocl.py")])
call([PYTHON_BIN, os.path.join(bpy.utils.script_path_pref(),
"addons", "cam", "opencamlib", "ocl.py")])
waterlineChunksFromOCL(operation, chunks)
@ -164,12 +170,15 @@ async def oclGetWaterline(operation, chunks):
op_cutter_tip_angle = operation['cutter_tip_angle']
cutter = None
cutter_length = 150 # TODO: automatically determine necessary cutter length depending on object size
# TODO: automatically determine necessary cutter length depending on object size
cutter_length = 150
if op_cutter_type == 'END':
cutter = ocl.CylCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
cutter = ocl.CylCutter(
(op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
elif op_cutter_type == 'BALLNOSE':
cutter = ocl.BallCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
cutter = ocl.BallCutter(
(op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
elif op_cutter_type == 'VCARVE':
cutter = ocl.ConeCutter((op_cutter_diameter + operation.skin * 2)
* 1000, op_cutter_tip_angle, cutter_length)
@ -192,7 +201,8 @@ async def oclGetWaterline(operation, chunks):
for l in wl_loops:
inpoints = []
for p in l:
inpoints.append((p.x / OCL_SCALE, p.y / OCL_SCALE, p.z / OCL_SCALE))
inpoints.append(
(p.x / OCL_SCALE, p.y / OCL_SCALE, p.z / OCL_SCALE))
inpoints.append(inpoints[0])
chunk = camPathChunk(inpoints=inpoints)
chunk.closed = True