kopia lustrzana https://github.com/vilemduha/blendercam
OpenCAMLib waterline fixes
rodzic
4ac35a73f8
commit
48e8b9fb7b
|
@ -1,12 +1,13 @@
|
|||
import ocl
|
||||
import tempfile
|
||||
import pyocl
|
||||
import camvtk
|
||||
|
||||
stl = camvtk.STLSurf("./model0.stl")
|
||||
stl = camvtk.STLSurf(tempfile.gettempdir()+"/model0.stl")
|
||||
stl_polydata = stl.src.GetOutput()
|
||||
stl_surf = ocl.STLSurf()
|
||||
camvtk.vtkPolyData2OCLSTL(stl_polydata, stl_surf)
|
||||
csv_file = open('ocl_settings.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_settings.txt','r')
|
||||
op_cutter_type = csv_file.readline().split()[0]
|
||||
op_cutter_diameter = float( csv_file.readline() )
|
||||
op_minz = float( csv_file.readline() )
|
||||
|
@ -27,7 +28,7 @@ bdc = ocl.BatchDropCutter()
|
|||
bdc.setSTL(stl_surf)
|
||||
bdc.setCutter(cutter)
|
||||
|
||||
csv_file = open('ocl_chunks.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunks.txt','r')
|
||||
for text_line in csv_file:
|
||||
sample_point = [ float(coord) for coord in text_line.split() ]
|
||||
bdc.appendPoint( ocl.CLPoint( sample_point[0]*1000, sample_point[1]*1000, op_minz * 1000 ) )
|
||||
|
@ -37,7 +38,7 @@ bdc.run()
|
|||
|
||||
cl_points = bdc.getCLPoints()
|
||||
|
||||
csv_file = open('ocl_chunk_samples.txt', 'w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunk_samples.txt', 'w')
|
||||
for point in cl_points:
|
||||
csv_file.write( str(point.z) + '\n' )
|
||||
csv_file.close()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import ocl
|
||||
import tempfile
|
||||
import camvtk
|
||||
|
||||
stl = camvtk.STLSurf("./model0.stl")
|
||||
stl = camvtk.STLSurf(tempfile.gettempdir()+"/model0.stl")
|
||||
stl_polydata = stl.src.GetOutput()
|
||||
stl_surf = ocl.STLSurf()
|
||||
camvtk.vtkPolyData2OCLSTL(stl_polydata, stl_surf)
|
||||
csv_file = open('ocl_settings.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_settings.txt','r')
|
||||
op_cutter_type = csv_file.readline().split()[0]
|
||||
op_cutter_diameter = float( csv_file.readline() )
|
||||
op_minz = float( csv_file.readline() )
|
||||
|
@ -21,7 +22,7 @@ elif op_cutter_type == 'VCARVE':
|
|||
else:
|
||||
print "Cutter unsupported: " + op_cutter_type + '\n'
|
||||
quit()
|
||||
wl_height_file = open( 'ocl_wl_heights.txt', 'r' )
|
||||
wl_height_file = open( tempfile.gettempdir()+'/ocl_wl_heights.txt', 'r' )
|
||||
waterline_heights = []
|
||||
for line in wl_height_file:
|
||||
waterline_heights.append( float( line.split()[0] ) )
|
||||
|
@ -36,7 +37,7 @@ for height in waterline_heights:
|
|||
waterline.setSampling(0.3)
|
||||
waterline.run()
|
||||
wl_loops = waterline.getLoops()
|
||||
wl_file = open( 'oclWaterline' + str(wl_index) + '.txt', 'w')
|
||||
wl_file = open( tempfile.gettempdir()+'/oclWaterline' + str(wl_index) + '.txt', 'w')
|
||||
for l in wl_loops:
|
||||
wl_file.write( 'l\n' )
|
||||
for p in l:
|
||||
|
|
|
@ -1,34 +1,38 @@
|
|||
#used by OpenCAMLib sampling
|
||||
|
||||
import bpy
|
||||
import os
|
||||
import tempfile
|
||||
from subprocess import call
|
||||
from cam.collision import BULLET_SCALE
|
||||
from cam import simple
|
||||
from cam.chunk import camPathChunk
|
||||
from cam.simple import *
|
||||
|
||||
OCL_SCALE = 1000
|
||||
|
||||
def operationSettingsToCSV(operation):
|
||||
csv_file = open('ocl_settings.txt','w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_settings.txt','w')
|
||||
csv_file.write( str(operation.cutter_type) + '\n')
|
||||
csv_file.write( str(operation.cutter_diameter) + '\n' )
|
||||
csv_file.write( str(operation.minz) + '\n' )
|
||||
csv_file.close()
|
||||
|
||||
def pointsToCSV(operation, points):
|
||||
csv_file = open('ocl_chunks.txt','w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunks.txt','w')
|
||||
for point in points:
|
||||
csv_file.write( str(point[0]) + ' ' + str(point[1]) + '\n')
|
||||
csv_file.close()
|
||||
|
||||
def pointSamplesFromCSV(points):
|
||||
csv_file = open('ocl_chunk_samples.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunk_samples.txt','r')
|
||||
for point in points:
|
||||
point[2] = float(csv_file.readline()) / BULLET_SCALE;
|
||||
point[2] = float(csv_file.readline()) / OCL_SCALE;
|
||||
#print(str(point[2]))
|
||||
csv_file.close()
|
||||
|
||||
def chunkPointsToCSV(operation, chunks):
|
||||
csv_file = open('ocl_chunks.txt','w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunks.txt','w')
|
||||
for ch in chunks:
|
||||
p_index = 0;
|
||||
for point in ch.points:
|
||||
|
@ -40,12 +44,12 @@ def chunkPointsToCSV(operation, chunks):
|
|||
csv_file.close()
|
||||
|
||||
def chunkPointSamplesFromCSV(chunks):
|
||||
csv_file = open('ocl_chunk_samples.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunk_samples.txt','r')
|
||||
for ch in chunks:
|
||||
p_index = 0;
|
||||
for point in ch.points:
|
||||
if( len(point) == 2 or point[2] != 2 ):
|
||||
z_sample = float(csv_file.readline()) / BULLET_SCALE;
|
||||
z_sample = float(csv_file.readline()) / OCL_SCALE;
|
||||
ch.points[p_index] = ( point[0], point[1], z_sample )
|
||||
#print(str(point[2]))
|
||||
else:
|
||||
|
@ -54,17 +58,17 @@ def chunkPointSamplesFromCSV(chunks):
|
|||
csv_file.close()
|
||||
|
||||
def resampleChunkPointsToCSV(operation, chunks_to_resample):
|
||||
csv_file = open('ocl_chunks.txt','w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunks.txt','w')
|
||||
for chunk, i_start, i_length in chunks_to_resample:
|
||||
for p_index in range(i_start, i_start+i_length):
|
||||
csv_file.write( str(chunk.points[p_index][0]) + ' ' + str(chunk.points[p_index][1]) + '\n')
|
||||
csv_file.close()
|
||||
|
||||
def chunkPointsResampleFromCSV(chunks_to_resample):
|
||||
csv_file = open('ocl_chunk_samples.txt','r')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_chunk_samples.txt','r')
|
||||
for chunk, i_start, i_length in chunks_to_resample:
|
||||
for p_index in range(i_start, i_start+i_length):
|
||||
z = float(csv_file.readline()) / BULLET_SCALE;
|
||||
z = float(csv_file.readline()) / OCL_SCALE;
|
||||
if z > chunk.points[p_index][2]:
|
||||
chunk.points[p_index][2] = z
|
||||
csv_file.close()
|
||||
|
@ -76,34 +80,43 @@ 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 = "model"+str(file_number)+".stl"
|
||||
file_name = tempfile.gettempdir()+"/model"+str(file_number)+".stl"
|
||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||
bpy.ops.transform.resize(value=(BULLET_SCALE, BULLET_SCALE, BULLET_SCALE), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', 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.transform.resize(value=(OCL_SCALE, OCL_SCALE, OCL_SCALE), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', 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.export_mesh.stl(check_existing=True, filepath=file_name, filter_glob="*.stl", ascii=False, use_mesh_modifiers=True, axis_forward='Y', axis_up='Z', global_scale=1.0)
|
||||
bpy.ops.object.delete()
|
||||
file_number += 1
|
||||
|
||||
def oclSamplePoints(operation, points):
|
||||
print("oclSamplePoints\n")
|
||||
print(tempfile.gettempdir()+"/oclSamplePoints\n")
|
||||
operationSettingsToCSV(operation)
|
||||
pointsToCSV(operation, points)
|
||||
exportModelsToSTL(operation)
|
||||
call([ "python2.7", "2.70/scripts/addons/cam/opencamlib/oclSample.py"])
|
||||
if os.path.isdir(bpy.utils.script_path_pref()+"/addons/cam/opencamlib"):
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
else:
|
||||
call([ "python2.7", py.utils.script_path_user()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
pointSamplesFromCSV(points)
|
||||
|
||||
def oclSample(operation, chunks):
|
||||
operationSettingsToCSV(operation)
|
||||
chunkPointsToCSV(operation, chunks)
|
||||
exportModelsToSTL(operation)
|
||||
call([ "python2.7", "2.70/scripts/addons/cam/opencamlib/oclSample.py"])
|
||||
if os.path.isdir(bpy.utils.script_path_pref()+"/addons/cam/opencamlib"):
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
else:
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
chunkPointSamplesFromCSV(chunks)
|
||||
|
||||
def oclResampleChunks(operation, chunks_to_resample):
|
||||
operationSettingsToCSV(operation)
|
||||
resampleChunkPointsToCSV(operation, chunks_to_resample)
|
||||
#exportModelsToSTL(operation)
|
||||
call([ "python2.7", "2.70/scripts/addons/cam/opencamlib/oclSample.py"])
|
||||
if os.path.isdir(bpy.utils.script_path_pref()+"/addons/cam/opencamlib"):
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
else:
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclSample.py"])
|
||||
chunkPointsResampleFromCSV(chunks_to_resample)
|
||||
def oclWaterlineLayerHeights( operation ):
|
||||
layers = []
|
||||
|
@ -119,7 +132,7 @@ def oclWaterlineLayerHeights( operation ):
|
|||
|
||||
def oclWaterlineHeightsToCSV( operation ):
|
||||
layers = oclWaterlineLayerHeights( operation )
|
||||
csv_file = open('ocl_wl_heights.txt', 'w')
|
||||
csv_file = open(tempfile.gettempdir()+'/ocl_wl_heights.txt', 'w')
|
||||
for layer in layers:
|
||||
csv_file.write( str(layer*1000)+'\n')
|
||||
csv_file.close()
|
||||
|
@ -128,12 +141,12 @@ def waterlineChunksFromCSV( operation, chunks ):
|
|||
layers = oclWaterlineLayerHeights( operation )
|
||||
wl_index = 0
|
||||
for layer in layers:
|
||||
csv_file = open( 'oclWaterline' + str(wl_index) + '.txt', 'r')
|
||||
csv_file = open(tempfile.gettempdir() + '/oclWaterline' + str(wl_index) + '.txt', 'r')
|
||||
for line in csv_file:
|
||||
if( line[0] == 'l'):
|
||||
chunks.append( camPathChunk( inpoints = [] ) )
|
||||
else:
|
||||
point = [ float(coord)/BULLET_SCALE for coord in line.split() ]
|
||||
point = [ float(coord)/OCL_SCALE for coord in line.split() ]
|
||||
chunks[-1].points.append( (point[0], point[1], point[2] ) )
|
||||
wl_index += 1
|
||||
csv_file.close()
|
||||
|
@ -142,14 +155,17 @@ def oclGetMedialAxis(operation, chunks):
|
|||
oclWaterlineHeightsToCSV( operation )
|
||||
operationSettingsToCSV( operation )
|
||||
curvesToCSV( operation )
|
||||
call([ "python2.7", "2.70/scripts/addons/cam/opencamlib/ocl.py"])
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/ocl.py"])
|
||||
waterlineChunksFromCSV( operation, chunks )
|
||||
|
||||
def oclGetWaterline(operation, chunks):
|
||||
oclWaterlineHeightsToCSV( operation )
|
||||
operationSettingsToCSV( operation )
|
||||
exportModelsToSTL( operation )
|
||||
call([ "python2.7", "2.70/scripts/addons/cam/opencamlib/oclWaterline.py"])
|
||||
if os.path.isdir(bpy.utils.script_path_pref()+"/addons/cam/opencamlib"):
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclWaterline.py"])
|
||||
else:
|
||||
call([ "python2.7", bpy.utils.script_path_pref()+"/addons/cam/opencamlib/oclWaterline.py"])
|
||||
waterlineChunksFromCSV( operation, chunks )
|
||||
|
||||
#def oclFillMedialAxis(operation):
|
||||
|
|
|
@ -8,6 +8,5 @@ Known issues:
|
|||
|
||||
To use OpenCAMLib, you will need Python 2.7 installation, with "python2.7" executable added to your path and OpenCAMLib library installed.
|
||||
|
||||
OpenCAMLib and its installation instructions can be found at:
|
||||
https://github.com/aewallin/opencamlib
|
||||
|
||||
OpenCAMLib installation instructions can be found at:
|
||||
https://github.com/vilemnovak/blendercam/wiki/Using-BlenderCAM-with-OpenCAMLib
|
||||
|
|
Ładowanie…
Reference in New Issue