Swift structs and constants in Pythonista? I thought I couldn't change the lightingModel of SCNMaterial, which I couldn't access well and could change the texture of the model significantly, but I've found a way to do it.
setLightingModelName_(string name)
lightingModel is a property of SCNMaterial, but you can change it by using the setLightingModelName_ function.
The argument is a character string, and the following character strings can be specified.
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()
The relationship between SCNMaterial's struct LightingModel and SCNLightingModel is a mystery.
Recommended Posts