จะสร้างพื้นผิว UV Grid ด้วย Python ได้อย่างไร

Aug 22 2020

จะสร้างพื้นผิว "UV Grid" ที่สร้างขึ้นด้วยความช่วยเหลือของ Blender Python API ได้อย่างไร

คำตอบ

2 brockmann Aug 22 2020 at 17:57

ทั้งสร้างกระดานหมากรุกและกำหนดพิกเซลไปยังบล็อกข้อมูลภาพใหม่หรือเพียงโทรbpy.ops.image.new()และส่งผ่านUV_GRID:

หนึ่งในข้อเสียของการใช้ประกอบการคือการที่คุณจะต้องจัดหาที่เชื่อถือได้ (ไม่ซ้ำกัน) ชื่อสำหรับบล็อกข้อมูลภาพมิฉะนั้นมันจะได้รับการเปลี่ยนชื่อUntitled.001, Untitled.002... เนื่องจากลักษณะปั่นของการจัดการข้อมูล:

import bpy
import secrets

# Generate "unique" name
image_name = secrets.token_hex(5)

# Call the operator 
bpy.ops.image.new(
        name=image_name, 
        width=1024, 
        height=1024, 
        color=(0.0, 0.0, 0.0, 1.0), 
        alpha=True, 
        generated_type='UV_GRID', # BLANK, COLOR_GRID
        float=False, 
        use_stereo_3d=False, 
        tiled=False
    )

# Get the image from data blocks
image = bpy.data.images.get(image_name)

# Display the result
if image:
    bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
    # Change area type
    area = bpy.context.window_manager.windows[-1].screen.areas[0]
    area.type = 'IMAGE_EDITOR'

    # Assign the image
    bpy.context.area.spaces.active.image = image

ที่เกี่ยวข้อง:

  • เป็นไปได้หรือไม่ที่จะสร้างข้อมูลรูปภาพและบันทึกลงในไฟล์จากสคริปต์
  • จะเปิดหน้าต่างแก้ไขรูปภาพและแสดงไฟล์รูปภาพในนั้นได้อย่างไร?