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 の関係は謎。