---
title: 之後想要開發的 blender 功能
lang: zh-tw
description: Blender Addon prepare
tags: Blender, rd
---
之後想要開發的 blender 功能
## mesh version
類似目前內建的 KTX Mesh Version,但是想要一個自己的版本,還有比較完整的管理功能。
## 1. Vertex Assigner 或是 mesh data convert
根據各種情況將物件加上 vertex color,例如每個 element 上不同顏色,根據 uv island 等等,並且可以根據 vertex color 選物件。
或是可以用 vertex group 定義 vertex color
這個東西對於之後要導入 Substance Paint 時很有幫助,因為 SP 需要這個來產生 color mask ,並且 blender 也需要一個可以管理編輯模式時的功能,不然只能一直 shift h alt h 也是有點煩。
## 2. Camera Store
類似這個,但是要有縮圖可以看
https://www.blendermarket.com/products/bookmark-view
## 3. Proxy
blender 的 proxy 功能前提都是必須要外部資料,但又缺乏可以單獨儲存一個 scene 的功能
## bake map to vertex color
```python=
import bpy
def bake_uv_to_vc(image_name):
# Lookup the image by name. Easier than trying to figure out which one is
# currently active
image = bpy.data.images[image_name]
width = image.size[0]
height = image.size[1]
# Keep UVs in the within the bounds to avoid out-of-bounds errors
def _clamp_uv(val):
return max(0, min(val, 1))
# Need to set the mode to VERTEX_PAINT, otherwise the vertex color data is
# empty for some reason
ob = bpy.context.object
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
# Caching the image pixels makes this *much* faster
local_pixels = list(image.pixels[:])
for face in ob.data.polygons:
for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
uv_coords = ob.data.uv_layers.active.data[loop_idx].uv
# Just sample the closest pixel to the UV coordinate. If you need
# higher quality, an improved approach might be to implement
# bilinear sampling here instead
target = [round(_clamp_uv(uv_coords.x) * (width - 1)), round(_clamp_uv(uv_coords.y) * (height - 1))]
index = ( target[1] * width + target[0] ) * 4
bpy.context.object.data.vertex_colors["Col"].data[loop_idx].color[0] = local_pixels[index]
bpy.context.object.data.vertex_colors["Col"].data[loop_idx].color[1] = local_pixels[index + 1]
bpy.context.object.data.vertex_colors["Col"].data[loop_idx].color[2] = local_pixels[index + 2]
bpy.context.object.data.vertex_colors["Col"].data[loop_idx].color[3] = local_pixels[index + 3]
bake_uv_to_vc("NAME_OF_THE_IMAGE_TO_BAKE_TO_VC")
```
```python=
def check_objects_list(self, context):
#check if object exist
for index, item in reversed(list(enumerate(self.objects_list))):
if not context.scene.objects.get(item.name):
self.objects_list.remove(index)
```