Specify the lighting Model of SCN Material in Pythonista

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

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'

Sample source

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()

Mystery

The relationship between SCNMaterial's struct LightingModel and SCNLightingModel is a mystery.

reference

Recommended Posts

Specify the lighting Model of SCN Material in Pythonista
Count the number of parameters in the deep learning model
[Golang] Specify an array in the value of map
Display the timetable of the Morioka bus location system in Pythonista
Specify the encoding of the unicode string in the Python 2.x print statement
The story of participating in AtCoder
Python-Simulation of the Epidemic Model (Kermack-McKendrick Model)
Try to model the cumulative return of rollovers in futures trading
The story of the "hole" in the file
The meaning of ".object" in Django
I tried touching touch related methods in the scene module of pythonista
[Understanding in 3 minutes] The beginning of Linux
Specify the color in the matplotlib 2D map
Check the behavior of destructor in Python
The story of an error in PyOCR
Implement part of the process in C ++
The importance of Lint as Pythonista thinks
Sum of variables in a mathematical model
The result of installing python in Anaconda
Let's claim the possibility of pyenv-virtualenv in 2021
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
Benefits of using slugfield in Django's model
Reading comprehension of "The Go Memory Model"
[IOS] Change the display time for each frame of GIF animation in Pythonista3.
plot the coordinates of the processing (python) list and specify the number of times in draw ()
Python scikit-learn A collection of predictive model tips often used in the field
Implement the mathematical model "SIR model" of infectious diseases in OpenModelica (see the effect of the vaccine)
Visualization of the firing state of the hidden layer of the model learned in the TensorFlow MNIST tutorial
Python scikit-learn A collection of predictive model tips often used in the field
Output the number of CPU cores in Python
The meaning of {version-number} in the mysql rpm package
Link the list_display item in Django's Model Admin
[Python] Sort the list of pathlib.Path in natural sort
Change the font size of the legend in df.plot
Get the caller of a function in Python
Match the distribution of each group in Python
View the result of geometry processing in Python
Make a copy of the list in Python
Find the number of days in a month
Read the output of subprocess.Popen in real time
Find the divisor of the value entered in python
The story of finding the optimal n in N fist
Fix the argument of the function used in map
Find the solution of the nth-order equation in python
[Python numpy] Dynamically specify the index of the array
The story of reading HSPICE data in Python
[Note] About the role of underscore "_" in Python
Put the second axis in 2dhistgram of matplotlib
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Visualized the usage status of the sink in the company
Output in the form of a python array
Specify the view URL in your Django template
The story of viewing media files in Django
Make any key the primary key in Django's model
Search by the value of the instance in the list
Make progress of dd visible in the progress bar
Factfulness of the new coronavirus seen in Splunk
GUI simulation of the new coronavirus (SEIR model)
[SIR model analysis] Peak out of infection numbers in Japan and around the world ♬