Changeset 1307 for blender-povray-animation
- Timestamp:
- 05/31/24 03:08:59 (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
blender-povray-animation/frams-pov-import.py
r630 r1307 2 2 "name": "Framsticks POV import & camera manipulator", 3 3 "author": "Szymon Ulatowski, jm soler", 4 "blender": (2, 70, 0), 4 "version": (1, 0, 1), 5 "blender": (2, 80, 0), 5 6 "location": "File > Import-Export", 6 7 "category": "Import-Export", … … 140 141 # create an object containing reference to blender cylinder object 141 142 class cylindre: 142 def __init__(self,nom='cylinderModel',type='cyl',r1=0.1, r2=0.1,h=1.0, n=8,smooth=1): 143 me=bpy.data.meshes.new(name=nom) 144 r=[r1,r2] 145 verts=[] 146 for i in range(0,2): 147 for j in range(0,n): 148 z=math.sin(j*math.pi*2/(n))*r[i] 149 y=math.cos(j*math.pi*2/(n))*r[i] 150 x=float(i)*h 151 verts.append((x,y,z)) 152 153 vlist=[v for v in range(n)] 154 vlist.append(0) 155 faces=[] 156 for i in range(n): 157 faces.append((vlist[i],vlist[i+1],vlist[i+1]+n,vlist[i]+n)) 158 159 if type=='cyl': 160 pos=[[0.0,0.0,0.0],[0.0,0.0,h]] 161 verts.append((pos[0][0],pos[0][1],pos[0][2])) 162 verts.append((pos[1][0],pos[1][1],pos[1][2])) 163 164 for i in range(n): 165 faces.append((vlist[i],vlist[i+1],len(vlist)-2)) 166 faces.append((vlist[i],vlist[i+1],len(vlist)-1)) 167 168 me.from_pydata(verts,[],faces) 169 me.update() 170 self.objet=bpy.data.objects.new(nom,me) 171 bpy.context.scene.objects.link(self.objet) 143 def __init__(self, name='cylinderModel', r1=0.1, r2=0.1, h=1.0, n=8, caps=True): 144 self.mesh=bpy.data.meshes.new(name=name) 145 r=[r1,r2] 146 verts=[] 147 for i in range(0,2): 148 for j in range(0,n): 149 z=math.sin(j*math.pi*2/(n))*r[i] 150 y=math.cos(j*math.pi*2/(n))*r[i] 151 x=float(i)*h 152 verts.append((x,y,z)) 153 154 vlist=[v for v in range(n)] 155 vlist.append(0) 156 faces=[] 157 for i in range(n): 158 faces.append((vlist[i],vlist[i+1],vlist[i+1]+n,vlist[i]+n)) 159 160 if caps: 161 faces.append(tuple(range(n-1,-1,-1))) 162 faces.append(tuple(range(n,2*n))) 163 164 self.mesh.from_pydata(verts,[],faces) 165 self.mesh.update() 166 167 def makeObject(self, name): 168 o = bpy.data.objects.new(name, self.mesh) 169 bpy.context.collection.objects.link(o) 170 return o 172 171 173 172 # build or update blender objects from a POV file 174 173 def updateBlender(SceneParent,num): 175 global Folder, Files, Current, RecentlyCreated, RecentlyDisappeared 174 global Folder, Files, Current, RecentlyCreated, RecentlyDisappeared, CylinderMesh, LinkedMesh 176 175 Incoming=analysePOV(os.path.join(Folder,Files[num])) 177 176 RecentlyCreated=[] … … 186 185 # create new blender objects 187 186 bcrea=bpy.data.objects.new(oname,None) 188 bpy.context. scene.objects.link(bcrea)187 bpy.context.collection.objects.link(bcrea) 189 188 bcrea.parent=SceneParent 190 189 newobj.append(bcrea) 191 190 for j in obj['joints']: 192 cyl=cylindre(oname+'_j','tube',0.1,0.1,1.0,6) 193 cyl.objet.parent=bcrea 194 newobj.append(cyl.objet) 191 if not LinkedMesh: 192 CylinderMesh = None 193 if not CylinderMesh: 194 CylinderMesh = cylindre(name = 'linked cylinder' if LinkedMesh else oname+'_j', r1=0.1, r2=0.1, h=1.0, n=6) 195 o = CylinderMesh.makeObject(oname+'_j') 196 o.parent=bcrea 197 newobj.append(o) 195 198 196 199 # update blender loc/rot/scale … … 224 227 print('Creature disappeared:',oname) 225 228 229 def setHideWithKeyframe(o,hide): 230 o.hide_render = hide 231 o.hide_viewport = hide 232 o.keyframe_insert(data_path="hide_viewport",frame=bpy.context.scene.frame_current) 233 o.keyframe_insert(data_path="hide_render",frame=bpy.context.scene.frame_current) 234 226 235 # import a sequence of POV files, create object hiererchy, animate 227 236 def framsImport(startfile): … … 232 241 global SceneParent 233 242 global SkipFrames 243 global CylinderMesh 234 244 235 245 scanDir(startfile) … … 241 251 bpy.context.scene.frame_end=max(bpy.context.scene.frame_end,FirstFrame+FrameCount-1) 242 252 253 CylinderMesh = None 243 254 SceneParent=bpy.data.objects.new("Framsticks_"+str(FirstFrame),None) 244 bpy.context. scene.objects.link(SceneParent)255 bpy.context.collection.objects.link(SceneParent) 245 256 SceneParent.framspov_file=startfile 246 257 SceneParent.framspov_frame=FirstFrame … … 263 274 obj=Current[oname] 264 275 for bo in obj: 265 bo.hide=True 266 bo.keyframe_insert(data_path="hide",frame=bpy.context.scene.frame_current) 276 setHideWithKeyframe(bo,True) 267 277 for oname in RecentlyDisappeared: 268 278 obj=Current[oname] 269 279 for bo in obj: 270 bo.hide=False 271 bo.keyframe_insert(data_path="hide",frame=bpy.context.scene.frame_current) 280 setHideWithKeyframe(bo,False) 272 281 bpy.context.scene.frame_set(FirstFrame-FirstPOV+k) 273 282 for oname in RecentlyCreated: 274 283 obj=Current[oname] 275 284 for bo in obj: 276 bo.hide=False 277 bo.keyframe_insert(data_path="hide",frame=bpy.context.scene.frame_current) 285 setHideWithKeyframe(bo,False) 278 286 for oname in RecentlyDisappeared: 279 287 obj=Current[oname] 280 288 for bo in obj: 281 bo.hide=True 282 bo.keyframe_insert(data_path="hide",frame=bpy.context.scene.frame_current) 289 setHideWithKeyframe(bo,True) 283 290 Current.pop(oname) 284 291 … … 356 363 bl_options = {'UNDO'} 357 364 358 files =CollectionProperty(name="File Path",365 files: CollectionProperty(name="File Path", 359 366 description="File path used for importing", 360 367 type=bpy.types.OperatorFileListElement) 361 directory = StringProperty() 362 363 framspov_skip = bpy.props.IntProperty(name="Frame step",min=1,max=100) 368 directory: StringProperty() 369 370 framspov_skip: bpy.props.IntProperty(name="Frame step",min=1,max=100) 371 372 framspov_linkedmesh: bpy.props.BoolProperty(name="Linked cylinder mesh", description="Use a single shared cylinder mesh for all sticks", default=True) 364 373 365 374 filename_ext = ".pov" 366 filter_glob =StringProperty(default="*.pov", options={'HIDDEN'})375 filter_glob: StringProperty(default="*.pov", options={'HIDDEN'}) 367 376 368 377 def execute(self, context): 369 global FirstFrame, FrameCount,FileName,SkipFrames 378 global FirstFrame, FrameCount,FileName,SkipFrames,LinkedMesh 370 379 FirstFrame = bpy.context.scene.frame_current 371 380 FrameCount = 9999 372 381 SkipFrames = self.framspov_skip 382 LinkedMesh = self.framspov_linkedmesh 373 383 framsImport(os.path.join(self.directory, self.files[0].name)) 374 384 return {'FINISHED'} … … 421 431 bpy.utils.register_class(VIEW3D_OT_WritePOVCameraPath) 422 432 bpy.utils.register_class(OBJECT_PT_framspov) 423 bpy.types. INFO_MT_file_import.append(menu_func_import)433 bpy.types.TOPBAR_MT_file_import.append(menu_func_import) 424 434 425 435 def unregister(): … … 428 438 bpy.utils.unregister_class(VIEW3D_OT_WritePOVCameraPath) 429 439 bpy.utils.unregister_class(OBJECT_PT_framspov) 430 bpy.types.INFO_MT_file_import.remove(menu_func_import) 431 440 bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
Note: See TracChangeset
for help on using the changeset viewer.