1
1

More than 3 years have passed since last update.

PythonistaでSCNMaterialのlightingModelを指定する

Posted at

C4826DB1-F6F1-482A-9F18-57A5E837144A.jpeg

Pythonista では swift の struct や定数?にうまくアクセスできなくてモデルの質感を大きく変えられる SCNMaterial の lightingModel を変更できないと思っていたのですが、方法が見つかったのでご紹介します。

setLightingModelName_(string name)

lightingModel は SCNMaterial のプロパティですが、変更する時は setLightingModelName_ 関数を使います。

引数は文字列で下記の文字列が指定可能です。

class SCNLightingModel:
    blinn = 'SCNLightingModelBlinn'
    constant = 'SCNLightingModelConstant'
    lambert = 'SCNLightingModelLambert'
    phong = 'SCNLightingModelPhong'
    physicallyBased = 'SCNLightingModelPhysicallyBased'
    shadowOnly = 'SCNLightingModelShadowOnly'

サンプルソース

scenekit03.py
import objc_util
from objc_util import *
import ui

load_framework('SceneKit')

SCNView,SCNNode,SCNScene,SCNCamera,SCNLight,SCNBox,SCNMaterial = map(ObjCClass, ['SCNView','SCNNode','SCNScene','SCNCamera','SCNLight','SCNBox','SCNMaterial'])

class SCNLightingModel:
    blinn = 'SCNLightingModelBlinn'
    constant = 'SCNLightingModelConstant'
    lambert = 'SCNLightingModelLambert'
    phong = 'SCNLightingModelPhong'
    physicallyBased = 'SCNLightingModelPhysicallyBased'
    shadowOnly = 'SCNLightingModelShadowOnly'


def main():
    main_view = ui.View()
    main_view_objc = ObjCInstance(main_view)

    # View
    scene_view = SCNView.alloc().initWithFrame_options_(((0, 0),(400, 400)), None).autorelease()
    # UIView.autoresizingMask = flexibleWidth(2) | flexibleHeight(16)
    scene_view.setAutoresizingMask_(18)
    scene_view.setAllowsCameraControl_(True)

    scene = SCNScene.scene()
    node_root = scene.rootNode()

    # material
    material = SCNMaterial.material()
    material.setLightingModelName_(SCNLightingModel.physicallyBased) 
    material.diffuse().setColor_(UIColor.redColor().CGColor())

    # box geometry
    geom_box = SCNBox.boxWithWidth_height_length_chamferRadius_(1.0,1.0,1.0,0.2)    
    geom_box.setMaterials_([material])
    node_box = SCNNode.nodeWithGeometry_(geom_box)
    node_box.setPosition((-0.5,0.5,-0.5))
    node_root.addChildNode_(node_box)

    # camera
    camera = SCNCamera.camera()
    node_camera = SCNNode.node()
    node_camera.setCamera(camera)
    node_camera.setPosition((0,0,5.0))
    node_root.addChildNode_(node_camera)

    # Light
    light = SCNLight.light()
    light.setType_('omni')
    light.setColor_(UIColor.whiteColor().CGColor())
    node_light = SCNNode.node()
    node_light.setPosition((2.0,2.0,2.0))
    node_light.setLight_(light)
    node_root.addChildNode_(node_light)

    scene_view.setScene_(scene)

    main_view_objc.addSubview_(scene_view)

    main_view.name = 'scene kit'
    main_view.present()

main()

SCNMaterial の struct LightingModel と SCNLightingModel の関係は謎。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1