動いてくれないようです。。。
なんだかなぁ。。といった感じなので、ブログを引っ越す予定です。
引っ越しが完了したら、このブログは更新されなくなります。
(今までもあまり更新されてないですけどね。。笑)
新しいブログは
http://bl4etc.blog.fc2.com/
です。
Bloggerに越してきてあまり投稿してないのに。。残念。。
BlenderとかLinuxとか、そのほかにもPythonとか。。 日々気になったことや、試したことなどを記録していきます。
#!/usr/bin/env python ''' SimpleSpriteSheet This script help to generate sprite sheet for game texture. When you use this script, all images size must be the same. Otherwize, you could not get the good result. Option help: 1. Sprite cell width Set the width of individual Sprite. The width of Sprite should be the same as the height of the image. When the width of the image is bigger, the image is trimmed. 2. Sprite cell height Set the height of individual Sprite. The height of Sprite should be the same as the height of the image. When the height of the image is bigger, the image is trimmed. 3. Columns per row Set the number of the lateral cells. 4. Image source When "Layers" is chosen, this script use the layer of current image from the top. If "Directory" is chosen, this script use the image files in a directory. 5. Acive layers only This option becomes effective when the image source is "Layers". If this option is "Yes", script ignores the invisible layers. 6. Directory This option becomes effective when the image source is "Directory". Script use the image in this directory. 7. Image filter This option becomes effective when the image source is "Directory". Script processes ignores other image types. ''' import os from gimpfu import * IMG_SOURCE_LAYER = 0 IMG_SOURCE_DIRECTORY = 1 IMG_FILTER_PNG = 0 IMG_FILTER_JPG = 1 SOURCE_FILTER_DICT = { IMG_FILTER_PNG: ('.png', '.PNG'), IMG_FILTER_JPG: ('.jpg', 'jpeg'), } def plugin_main(timg, tdrawable, spriteWidth, spriteHeight, columnCount, imageSource, activeLayersOnly, directory, imageFilter): ''' ''' newImg = None # "Layers" source if imageSource == IMG_SOURCE_LAYER: newImg = _make_sprite_sheet(timg, spriteWidth, spriteHeight, columnCount) # "Directory" source elif imageSource == IMG_SOURCE_DIRECTORY: # Filter the image file by extention extFilters = SOURCE_FILTER_DICT.get(imageFilter) filesInDir = os.listdir(directory) if extFilters: sourceNames = [os.path.join(directory, fname) for fname in filesInDir if os.path.splitext(fname)[1] in extFilters] else: sourceNames = [os.path.join(directory, fname) for fname in filesInDir] # Create the temporary image that contains source images(layers) loadedImage = _load_layerd_iamge(sourceNames, spriteWidth, spriteHeight, columnCount) if loadedImage: # Make the sprite sheet from the image which contains the layers. newImg = _make_sprite_sheet(loadedImage, spriteWidth, spriteHeight, columnCount) gimp.delete(loadedImage) # Show the result image if newImg: gimp.pdb.gimp_display_new(newImg) def _get_sprite_row(index, columnCount): ''' index: origin 0 RETURN: origin 0 ''' row = int(math.ceil(float(index + 1) / float(columnCount))) return row - 1 def _get_sprite_column(index, columnCount): ''' index: origin 0 RETURN: origin 0 ''' return index % columnCount def _get_sprite_position(index, columnCount): ''' RETURN: Tuple (row index, column index) index : origin 0 ''' return (_get_sprite_row(index, columnCount), _get_sprite_column(index, columnCount)) def _get_image_size(sourceCount, spriteWidth, spriteHeight, columnCount): ''' RETURN: Tuple (image widht), image height) ''' cols = columnCount if sourceCount >= columnCount else sourceCount w = cols * spriteWidth h = (_get_sprite_row(sourceCount, columnCount) + 1) * spriteHeight return w, h def _load_layerd_iamge(filenames, spriteWidth, spriteHeight, columnCount): ''' RETURN: gimp.Image ''' imageW, imageH = _get_image_size(len(filenames), spriteWidth, spriteHeight, columnCount) newImg = gimp.Image(imageW, imageH, RGB) for fname in filenames: newLayer = gimp.pdb.gimp_file_load_layer(newImg, fname) gimp.pdb.gimp_image_add_layer(newImg, newLayer, len(newImg.layers)) return newImg def _make_sprite_sheet(image, spriteWidth, spriteHeight, columnCount): ''' return gimp.Image ''' # Validate arguments if not image or spriteWidth <= 0 or spriteHeight <= 0 or columnCount <= 0: return None # Resize image visibleLayerCount = len([la for la in image.layers if la.visible]) if visibleLayerCount == 0: print 'No visible layers.' return None imageW, imageH = _get_image_size(visibleLayerCount, spriteWidth, spriteHeight, columnCount) tmpImg = gimp.Image(imageW, imageH, RGB) tmpLayer = gimp.Layer(tmpImg, 'Sprite-Sheet', imageW, imageH, RGBA_IMAGE, 100, NORMAL_MODE) tmpImg.add_layer(tmpLayer) gimp.pdb.gimp_drawable_fill(tmpLayer, TRANSPARENT_FILL) # Destination layer pixel region dstPixRgn = tmpLayer.get_pixel_rgn(0, 0, imageW, imageH) # Arange the images gimp.progress_init() progressBarUnit = 100.0 / float(len(image.layers)) for idx, layer in enumerate(image.layers): row, col = _get_sprite_position(idx, columnCount) dstX = col * spriteWidth dstY = row * spriteHeight pixelsX = layer.width if layer.width <= spriteWidth else spriteWidth pixelsY = layer.height if layer.height <= spriteHeight else spriteHeight # Source layer pixel region srcPixRgn = layer.get_pixel_rgn(0, 0, pixelsX, pixelsY) # Copy source pixel regin to destination. dstPixRgn[dstX:dstX + pixelsX, dstY:dstY + pixelsY] = srcPixRgn[0:pixelsX, 0:pixelsY] gimp.progress_update(idx * progressBarUnit) ## === SLOWER === ## for x in range(pixelsX): ## for y in range(pixelsY): ## dstPixRgn[dstX + x, dstY + y] = srcPixRgn[x, y] ## === SLOWEST === ## for x in range(pixelsX): ## for y in range(pixelsY): ## channels, pixel = gimp.pdb.gimp_drawable_get_pixel(layer, x, y) ## gimp.pdb.gimp_drawable_set_pixel(tmpLayer, dstX + x, dstY + y, channels, pixel) return tmpImg # # Register script # register( 'python_fu_SSS', 'Simple sprite sheet maker(S.S.S).', 'Simple sprite sheet maker(S.S.S).', 'Junichi Kawanishi aka jkani4 (jkani4@gmail.com)', 'Copyright 2011 Junichi Kawanishi', '2011', '/Filters/_SSS...', '', # image types [(PF_INT, 'spriteWidth', 'Sprite cell width:', 128), (PF_INT, 'spriteHeight', 'Sprite cell height:', 128), (PF_INT, 'columnCount', 'Columns per row:', 8), (PF_RADIO, 'imageSource', 'Image source:', IMG_SOURCE_LAYER, (('Layer', IMG_SOURCE_LAYER), ('Directory', IMG_SOURCE_DIRECTORY))), (PF_TOGGLE, 'activeLayersOnly', 'Active layers only:', 1), (PF_DIRNAME, 'directory', 'Directory:', 0), (PF_OPTION, 'imageFilter', 'Image filter', IMG_FILTER_PNG, ['*.png', '*.jpg'])], [], plugin_main) # # Start # main()
def IsInSight(target as GameObject): if not target: return false targetPos as Vector3 = camera.WorldToViewportPoint(target.collider.bounds.center) if targetPos.x < 0.0 or targetPos.x > 1.0: return false if targetPos.y < 0.0 or targetPos.y > 1.0: return false return true
import UnityEngine class BezierBeam1 (Weapon): # PUBLICS public offsetQ1 as Vector3 = Vector3(0.0, 1.0, 1.0) public offsetQ2 as Vector3 = Vector3(0.0, 0.5, 1.5) # PRIVATES _goalPosition as Vector3 = Vector3.zero _lastT = 0.0 virtual def _UpdatePosition(initialPos as Vector3): posQ0 = initialPos posQ1 = posQ0 + offsetQ1 posQ2 = posQ0 + offsetQ2 posQ3 = _goalPosition Debug.DrawLine(posQ0, posQ1, Color.red) Debug.DrawLine(posQ1, posQ2, Color.red) Debug.DrawLine(posQ2, posQ3, Color.red) _lastT += Time.deltaTime if _lastT > 1.0: _lastT = 0.0 pos as Vector3 pos.x = _Blend(_lastT, posQ0.x, posQ1.x, posQ2.x, posQ3.x) pos.y = _Blend(_lastT, posQ0.y, posQ1.y, posQ2.y, posQ3.y) pos.z = _Blend(_lastT, posQ0.z, posQ1.z, posQ2.z, posQ3.z) transform.position = pos def _Blend(t as single, q0 as single, q1 as single, q2 as single, q3 as single): wt as single = 1.0 - t val as single = (q0 * wt * wt * wt) + (3 * q1 * wt * wt * t) + (3 * q2 * wt * t * t) + (q3 * t * t * t) # Debug.Log("Blend = ${t} ${q0}, ${q1}, ${q2}, ${q3}, ${val}") return val def SetGoalPosition(goal as Vector3): _goalPosition = goal