Don't know why you mentioned that, given that it is a defacto requirement to be a developer..........faulty brain
AttachNodeObject() Error
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AttachNodeObject() Error
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: AttachNodeObject() Error
thats a great idea.defacto requirement to be a developer
i'm trying to apply the script file color to your Cube without success, even using exactly the Samuel procedure. but it could be colored with a texture like the example at the top of the previous page. i will try it.
Re: AttachNodeObject() Error
IdeasVacuum , this gives your cube a color other than black
AmbientColor(RGB(255,255,255))
GetScriptMaterial(#MyMatl, "Color/Yellow")
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
MaterialBlendingMode(#MyMatl, #PB_Material_Add )
i want it to be colored by Yellow from script, but can't get this unless inserting this line:
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
if we replaced RGB(255,255,0) with RGB(0,0,255) we will get a blue color.
so whats the purpose of the script color in this case !!.
here is all your code for rapid testing:
AmbientColor(RGB(255,255,255))
GetScriptMaterial(#MyMatl, "Color/Yellow")
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
MaterialBlendingMode(#MyMatl, #PB_Material_Add )
i want it to be colored by Yellow from script, but can't get this unless inserting this line:
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
if we replaced RGB(255,255,0) with RGB(0,0,255) we will get a blue color.
so whats the purpose of the script color in this case !!.
here is all your code for rapid testing:
Code: Select all
IncludeFile "Screen3DRequester.pb"
Enumeration
#MyMesh
#MyMatl
#MyEnt
#MyNode
#MyCamera
#MyLight
EndEnumeration
#CameraSpeed = 2
NewList sgListPts.s()
sgDelim.s = Chr(44)
igFaceCnt.i = 0
Define iKeyX.i, iKeyY.i, iMouseX.i, iMouseY.i
Restore MeshPoints
For i = 1 To 36
AddElement(sgListPts())
Read.s sgListPts()
Next i
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
Add3DArchive("Data\Scripts", #PB_3DArchive_FileSystem)
Add3DArchive("Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
If Screen3DRequester()
AmbientColor(RGB(255,255,255))
GetScriptMaterial(#MyMatl, "Color/Yellow")
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
MaterialBlendingMode(#MyMatl, #PB_Material_Add )
MaterialCullingMode(#MyMatl, #PB_Material_NoCulling)
CreateMesh(#MyMesh, #PB_Mesh_TriangleList, #PB_Mesh_Static)
FirstElement(sgListPts())
i = 0
SkyBox("desert07.jpg")
Repeat
MeshVertexPosition(ValD(StringField(sgListPts(),1,sgDelim)),ValD(StringField(sgListPts(),2,sgDelim)),ValD(StringField(sgListPts(),3,sgDelim)))
NextElement(sgListPts())
MeshVertexPosition(ValD(StringField(sgListPts(),1,sgDelim)),ValD(StringField(sgListPts(),2,sgDelim)),ValD(StringField(sgListPts(),3,sgDelim)))
NextElement(sgListPts())
MeshVertexPosition(ValD(StringField(sgListPts(),1,sgDelim)),ValD(StringField(sgListPts(),2,sgDelim)),ValD(StringField(sgListPts(),3,sgDelim)))
NextElement(sgListPts())
MeshFace(i, i + 1, i + 2)
igFaceCnt = igFaceCnt + 1
i = i + 3
Until i > 34
FinishMesh(#True)
CreateEntity(#MyEnt, MeshID(#MyMesh), MaterialID(#MyMatl), 0, 0, 0)
;Camera
CreateCamera(#MyCamera, 0, 0, 100, 100)
MoveCamera(#MyCamera,0,200,500, #PB_Absolute)
CameraLookAt(#MyCamera, EntityX(#MyEnt), EntityY(#MyEnt), EntityZ(#MyEnt))
CameraFixedYawAxis(#MyCamera, #True, 0, 1, 0)
CameraBackColor(#MyCamera, RGB(35, 35, 35))
;node
node = CreateNode(#PB_Any, 0,0,0)
AttachNodeObject(node, CameraID(#MyCamera))
;Light
CreateLight(#MyLight, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(255, 255, 255))
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
iKeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
iKeyX = #CameraSpeed
Else
iKeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
iKeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
iKeyY = #CameraSpeed
Else
iKeyY = 0
EndIf
EndIf
If ExamineMouse()
iMouseX = -(MouseDeltaX()/10)
iMouseY = -(MouseDeltaY()/10)
EndIf
RotateNode(node, 0, -0.4, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
End
DataSection
MeshPoints:
;01
Data$ "50.0000,50.0000,-50.0000"
Data$ "-50.0000,-50.0000,-50.0000"
Data$ "-50.0000,50.0000,-50.0000"
;02
Data$ "50.0000,50.0000,-50.0000"
Data$ "50.0000,-50.0000,-50.0000"
Data$ "-50.0000,-50.0000,-50.0000"
;03
Data$ "50.0000,50.0000,50.0000"
Data$ "-50.0000,50.0000,50.0000"
Data$ "-50.0000,-50.0000,50.0000"
;04
Data$ "50.0000,50.0000,50.0000"
Data$ "-50.0000,-50.0000,50.0000"
Data$ "50.0000,-50.0000,50.0000"
;05
Data$ "50.0000,-50.0000,50.0000"
Data$ "-50.0000,-50.0000,50.0000"
Data$ "-50.0000,-50.0000,-50.0000"
;06
Data$ "50.0000,-50.0000,50.0000"
Data$ "-50.0000,-50.0000,-50.0000"
Data$ "50.0000,-50.0000,-50.0000"
;07
Data$ "50.0000,50.0000,50.0000"
Data$ "50.0000,-50.0000,50.0000"
Data$ "50.0000,-50.0000,-50.0000"
;08
Data$ "50.0000,50.0000,50.0000"
Data$ "50.0000,-50.0000,-50.0000"
Data$ "50.0000,50.0000,-50.0000"
;09
Data$ "-50.0000,50.0000,50.0000"
Data$ "50.0000,50.0000,50.0000"
Data$ "50.0000,50.0000,-50.0000"
;10
Data$ "-50.0000,50.0000,50.0000"
Data$ "50.0000,50.0000,-50.0000"
Data$ "-50.0000,50.0000,-50.0000"
;11
Data$ "-50.0000,-50.0000,50.0000"
Data$ "-50.0000,50.0000,50.0000"
Data$ "-50.0000,50.0000,-50.0000"
;12
Data$ "-50.0000,-50.0000,50.0000"
Data$ "-50.0000,50.0000,-50.0000"
Data$ "-50.0000,-50.0000,-50.0000"
EndDataSection-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AttachNodeObject() Error
Great stuff ApplePi.
When I run the code, the compiler halts at SetMaterialColor() with [Error] The specified material is not initialised, most likely because I have not got the script path correct - however, that led me to another thought (= another question). It's become my mission to help Comtois to acheive 100% gray hair!
When I run the code, the compiler halts at SetMaterialColor() with [Error] The specified material is not initialised, most likely because I have not got the script path correct - however, that led me to another thought (= another question). It's become my mission to help Comtois to acheive 100% gray hair!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AttachNodeObject() Error
I have edited the original code to use a texture file (png) for the colour - that works perfectly.
Concerning Camera Rotate, NodeAnimation is a temptation, but with a large Mesh, wouldn't that be an unnecessary load on the CPU?
Concerning Camera Rotate, NodeAnimation is a temptation, but with a large Mesh, wouldn't that be an unnecessary load on the CPU?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: AttachNodeObject() Error
If you want the blue in a script to be changed to yellow all you have to do is edit the diffuse in the script.applePi wrote: i want it to be colored by Yellow from script, but can't get this unless inserting this line:
SetMaterialColor(#MyMatl, #PB_Material_AmbientColor, RGB(255,255,0))
if we replaced RGB(255,255,0) with RGB(0,0,255) we will get a blue color.
so whats the purpose of the script color in this case !!.
The coloring setup in scripts works like this. The color value goes from 0 to 1 instead of 0 to 255. So you still have the RGB setup just different numbers.
Diffuse 0 0 0 means that there is no color so then you would get black. If you change the first 0 to 0.5 you would get a red material.
If you can compare this to purebasics setup it would look like this.
Diffuse 0.5 0 0 = RGB(127,0,0)
Just in case you don't know here is a quick breakdown of these 4 script commands.
ambient= The color of the material when the light doesn't reach it. This why the bottom of that blue sphere was black.
diffuse= The color of the material when the light hits it.
specular= The color of the shiny spot on it. The 4th parameter is the strength of the shine. If i remember correctly it goes from 0 to 120.
shading= The style of shadowing on the material.
One more thing scripting for just a simple color can become time consuming so most of the time its easier to just use SetMaterialColor or to
manually create a texture for the material.
When you get to harder things like alphablending materials together or bump/normal mapping then scripting is necessary.
Sorry for rambling on a topic not even meant for scripting, but I think I'm done now.
Hope this helps.
Code: Select all
material ColorYellow/Yellow
{
technique
{
pass
{
ambient 0.1 0.1 0.1
diffuse 1 1 0.1
specular 0.7 0.7 0.7 64
shading phong
}
}
}
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AttachNodeObject() Error
That's very helpfull info on material scripts, thanks Samuel 
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: AttachNodeObject() Error
thank you Samuel very much, i wish a fixed section in the 3D programming section dedicated only to tutorials so you can put your tutorial on scripts there, and every one can write lessons can put it there for a reference.
i first thought that the meshes made from triangle lists can't be colored from material scripts, but i'm wrong, below i have merged my example on page 1 and your example about scripts and shortening the code, and the two entitites colored by yellow as i want without using SetMaterialColor function.
save the code to Examples\3D
the output should be like this: press Z to change to specular color
i first thought that the meshes made from triangle lists can't be colored from material scripts, but i'm wrong, below i have merged my example on page 1 and your example about scripts and shortening the code, and the two entitites colored by yellow as i want without using SetMaterialColor function.
save the code to Examples\3D
the output should be like this: press Z to change to specular color
Code: Select all
#MeshFromTriangles = 3
#MyEnt = 4
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
ExamineDesktops()
;************************ADD PATH TO SCRIPTS************************
Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)
OpenWindow(0, 0, 0, DeskWid, DeskHei, "Script Test, press Z to change light to Light_SpecularColor ", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
Yellow = GetScriptMaterial(#PB_Any, "Color/Yellow")
CreateSphere(0, 40, 50, 50)
CreateEntity(0,MeshID(0), MaterialID(Yellow) , -90, 0, 0)
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(0,50,0))
MoveCamera(0,0, 100, 300)
CameraLookAt(0, 0, 0, 0)
CreateLight(0, $FFFFFF, 1560, 900, 500)
;SetLightColor(0, #PB_Light_SpecularColor, $FFFFFF)
WorldShadows(#PB_Shadow_Modulative, 6000, RGB(100,100,100))
;;;;Mesh from triangles list
CreateMesh(#MeshFromTriangles ,#PB_Mesh_TriangleList, #PB_Mesh_Static)
Restore MeshPoints
For i=0 To 5
Read.f x : Read.f y : Read.f z
Read.f u: Read.f v
MeshVertexPosition(x*2 , y*2, z*2 )
MeshVertexTextureCoordinate(u, v)
MeshVertexNormal(x, y, z)
Next i
NormalizeMesh(#MeshFromTriangles)
;reading how to build faces
Restore Triangles
For i=0 To 1
Read.w t1 : Read.w t2 : Read.w t3
MeshFace(t1, t2, t3)
Next i
FinishMesh(#True)
CreateEntity(#MyEnt, MeshID(#MeshFromTriangles), MaterialID(Yellow), 90, -50, 0)
RotateEntity(#MyEnt, 0, 100, 0, #PB_Absolute)
;;;oooooooooooooooooooooooooooooooooooooooooo
Repeat
Event=WaitWindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Z)
SetLightColor(0, #PB_Light_SpecularColor, $FFFFFF)
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
DataSection
MeshPoints:
Data.f 50,0,0 , 0,0
Data.f -50,0,0 , 1,0
Data.f 0,60,0 , 1,1
Data.f 0,60,0 ,0,1
Data.f 50,0,-70 ,0,0
Data.f 50,0,0 ,1,0
Triangles:
Data.w 0,1,2
Data.w 3,4,5
EndDataSection-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AttachNodeObject() Error
That's a very nice example ApplePi.
I have manufactured another issue - With the original code rolled-up as a Procedure, on pressing the Escape key to break out of the loop, I'm getting a crash on EndProcedure (never seen that before!): [ERROR] Invalid memory access (read error at address 28).
I have manufactured another issue - With the original code rolled-up as a Procedure, on pressing the Escape key to break out of the loop, I'm getting a crash on EndProcedure (never seen that before!): [ERROR] Invalid memory access (read error at address 28).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.

