[Closed] Analyzing Viewport Lighting [3DS Max 2014]
Hello, I am trying to improve the script based on the svg renderer with max script tutorial because this script proposed by @PolyTools3D is working almost perfectly for simple real-time rendering kind of tasks. Now I wonder if there is a way to add very simplistic shadows either raytraced or if there’s something simpler like a shadow map also that . Can someone help me to implement it into the script . What would be a good starting point? I would also pay a little for help because I am too much of a novice and I think it might be quite easy for an expert to add simple shadows to the scene . Now I hope for help : ) good night and greetings from Hamburg
EDIT:
this is the tutorial :
https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_14B02950_26DF_498C_A88A_CD87DC84473C_htm
this i my script so far: ( the code function is not working good… )
clearListener()
(
– Generals
global myNodeName = “kopfmodell”
– face mapping position in uv map from left top to hardware order
global faceMap = #(159, 154, 153, 60, 134, 59, 79, 19, 43, 94, 56, 7, 12, 20, 40, 27, 65, 82, 121, 176, 1, 77, 90, 30, 91, 89, 78, 81, 85, 57, 76, 31, 44, 13, 11, 10, 83, 49, 50, 64, 93, 87, 88, 5, 4, 3, 6, 92, 75, 66, 34, 22, 58, 24, 23, 33, 21, 80, 41, 28, 39, 26, 47, 61, 9, 46, 32, 45, 2, 8, 14, 16, 15, 35, 36, 51, 73, 69, 72, 67, 74, 52, 37, 62, 18, 17, 86, 84, 63, 48, 150, 101, 106, 114, 38, 68, 70, 42, 25, 71, 29, 55, 54, 53, 185, 183, 172, 175, 179, 151, 170, 125, 138, 107, 173, 113, 137, 188, 144, 158, 187, 181, 182, 99, 98, 97, 100, 186, 95, 171, 184, 124, 152, 118, 117, 127, 115, 174, 135, 122, 133, 120, 105, 104, 177, 143, 126, 139, 96, 102, 108, 110, 109, 129, 130, 145, 169, 160, 128, 116, 168, 146, 131, 156, 112, 111, 180, 178, 157, 142, 141, 155, 103, 140, 132, 162, 164, 136, 119, 165, 123, 149, 148, 147, 167, 163, 166, 161);
– face mpping face ids to hardware order of leds
global faceMap2 = #(132,162,164,136,119,165,123,149,148,147,167,163,166,161,168,146,131,156,112,111,180,178,157,142,141,155,103,140,126,139,96,102,108,110,109,129,130,145,169,160,128,116,152,118,117,127,115,174,135,122,133,120,105,104,177,143,144,158,187,181,182,99,98,97,100,186,95,171,184,124,185,183,172,175,179,151,170,125,138,107,173,113,137,188,150,101,106,114,38,68,70,42,25,71,29,55,54,53,73,69,72,67,74,52,37,62,18,17,86,84,63,48,47,61,9,46,32,45,2,8,14,16,15,35,36,51,75,66,34,22,58,24,23,33,21,80,41,28,39,26,11,10,83,49,50,64,93,87,88,5,4,3,6,92,1,77,90,30,91,89,78,81,85,57,76,31,44,13,79,19,43,94,56,7,12,20,40,27,65,82,121,176,159,154,153,60,134,59);
global mappedOutput = #();
for i=1 to 188 do (
if i == 2 then (
append mappedOutput (254 as integer)
) else (
append mappedOutput (0 as integer)
)
)
global mappedOutputTest = #();
for i=1 to 188 do (
if i == 1 then (
append mappedOutputTest (254 as integer)
) else (
append mappedOutputTest (i as integer)
)
)
– prepare serial port
global serialEnabled = true
fn setupSerialPort = (
if serialEnabled then (
global serialPortName = “COM49”
global serialBaudRate = 230400
global port = dotNetObject “System.IO.Ports.SerialPort”
port.portname = serialPortName
port.baudrate = serialBaudRate
port.parity = port.parity.even
–port.databits = 8
–port.stopbits = port.stopbits.one
–port.readtimeout = 500
–
–port.writetimeout = 100
port.Open()
--sleep(1)
--port.Write("q\r")
sleep(1)
--port.Write("livemodedebug\r")
type = dotNetClass "System.byte[]"
res = dotnet.ValueToDotNetObject mappedOutputTest type
if serialEnabled then (
--port.Write res 0 188
--port.Write("\r")
for i=0 to 187 do (
--port.write res i 1
--sleep(0.01)
-- ComPort.Write(mappedOutput[i])
--writeSerialPort((mappedOutput[i] as byte))
)
)
port.Close()
)
)
setupSerialPort()
fn openSerialPort = (
if port != undefined AND serialEnabled then (
port.Open()
sleep(1)
isOpen = getProperty port #IsOpen
print ("Open port " + (serialPortName as string) + " isOpen: " + (isOpen as string))
)
)
fn closeSerialPort = (
if port != undefined AND serialEnabled then (
port.Close()
sleep(1)
isOpen = getProperty port #IsOpen
print ("Close port " + (serialPortName as string) + " isOpen: " + (isOpen as string))
)
)
fn writeSerialPort data = (
isOpen = getProperty port #IsOpen
if port != undefined AND serialEnabled AND isOpen then (
port.Write(data)
)
)
try destroydialog ::RO_DISPLAY_FACES_COLORS catch()
rollout RO_DISPLAY_FACES_COLORS "Faces Colors" width:172 height:250
(
colorPicker cp1 "Material Color:" pos:[8, 8] height:16 color:white
radioButtons rdo1 "Display:" pos:[8,32] labels:#("RGB","H","S","B") columns:4
label lab1 "Live Mode - Serial Transfer"
checkbutton btnStartStop "Start" pos:[8,100] width:154 height:28
timer clock interval:50 active:false
global GW_DisplayFacesColors
local node = getNodeByName (myNodeName as string)
local GetfaceNormal = polyop.getfaceNormal
local GetFaceCenter = polyop.getFaceCenter
fn CalculateFacesColors obj =
(
mappedOutput = #();
viewTM = viewport.getTM()
viewTM.row4 = [0,0,0]
viewPos = (inverse (viewport.getTM())).row4
fillColor = cp1.color
for faceIndex = 1 to obj.numfaces do (
faceNormal = normalize (GetfaceNormal obj faceIndex)
value = 0
--if (faceNormal*viewTM).z > 0 then
if true then
(
faceCenter = GetFaceCenter obj faceINdex
viewVector = normalize (viewPos - faceCenter)
faceColor = black
for k in lights where classof k != targetobject do
(
lightDir = normalize (k.pos - faceCenter)
diffuse = amax ((dot lightDir faceNormal)*k.multiplier) 0
faceColor += fillColor * k.color * diffuse
)
value = amin (int faceColor.r) 255
)
if value == 255 then value = 254
mappedOutput[faceMap2[faceIndex]] = value
--mappedOutput[fmp2[faceIndex]] = value
)
)
fn GW_DisplayFacesColors =
(
--CalculateFacesColors(node)
type = dotNetClass "System.byte[]"
res = dotnet.ValueToDotNetObject mappedOutput type
if serialEnabled then (
port.write res 0 188
for i=0 to 187 do (
--port.write res i 1
-- ComPort.Write(mappedOutput[i])
--writeSerialPort((mappedOutput[i] as byte))
)
)
)
on clock tick do
(
GW_DisplayFacesColors()
)
fn exitProgram = (
print "Exit program"
clock.active = false
writeSerialPort("q\r\n") -- serial command to enter menu
closeSerialPort()
unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on RO_DISPLAY_FACES_COLORS open do
(
--unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on RO_DISPLAY_FACES_COLORS close do
(
exitProgram()
unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on btnStartStop changed arg do
(
unregisterRedrawViewsCallback GW_DisplayFacesColors
if arg then -- start program
(
openSerialPort()
--writeSerialPort("q\r") -- serial command to enter menu
--writeSerialPort("livemode\r") -- serial command to enter live mode
clock.active = true
if lights.count == 0 then
(
node = undefined
btnStartStop.checked = false
messagebox "There must be at least one light source in the scene"
) else (
--node.wirecolor = cp1.color
if classof node.mat == standardmaterial do node.mat.diffuse = cp1.color
--registerRedrawViewsCallback GW_DisplayFacesColors
)
) else (
exitProgram()
)
if btnStartStop.checked then (
btnStartStop.Text = "Stop"
) else (
btnStartStop.Text = "Start"
)
completeredraw()
)
on rdo1 changed arg do completeredraw()
on cp1 changed arg do
(
if node != undefined do
(
node.wirecolor = arg
if classof node.mat == standardmaterial do node.mat.diffuse = arg
)
completeredraw()
)
)
createdialog RO_DISPLAY_FACES_COLORS
)
`