Here’s my code as I attempt to setup a project under Craft.
-- Test
function setup()
-- Create the scene
scene = craft.scene()
-- Move the main camera
scene.camera.position = vec3 (0,-10,0)
-- Adjust the scene lighting
scene.sun.rotation = quat.eulerAngles(75,0,45)
scene.ambientColor = color(30,30,30)
-- Turn on fog and set distances and color
scene.fogEnabled = false
scene.fogNear = 10
scene.fogFar = 1000
scene.fogColor = color(168, 168, 168, 255)
-- Get the sky material and change the sky and horizon colors
local skyMaterial = scene.sky.material
skyMaterial.sky = color(255, 60, 60, 255)
skyMaterial.horizon = color(255, 180, 180, 255)
-- Create a new entity
ground = scene:entity()
-- Attach a model and material for rendering
ground.model = craft.model.cube(vec3(1,1,1), vec3(0,0,0))
ground.material = craft.material("Materials:Voxel")
-- Rotate the entity
ground.eulerAngles = vec3(45, 0, 45)
-- Set the z position of the entity
ground.z = 100
end
function update(dt)
-- Update the scene (including physics, voxels and other systems)
scene:update(dt)
end
function draw()
update(DeltaTime)
-- Draw the scene (must be done within the draw function)
scene:draw()
end
All I get is this, no matter what I do with the camera, I don’t see anything other than this horizon line, no cubes, no nothing.
Can someone help me figure out how to setup a basic scene in Codea as a template.
@Kurall_Creator Welcome to the forum. Instead of fixing your code for you, here’s a simple example that you can look over that will help you fix your code.
displayMode(FULLSCREEN)
function setup()
fill(255,0,0)
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(99, 255, 0, 255)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
-- create cube with texture
c1=scene:entity()
c1.position=vec3(0,0,0)
c1.model = craft.model.cube(vec3(10,10,10))
c1.material = craft.material("Materials:Standard")
c1.material.map = readImage("Blocks:Trunk White Top")
end
function draw()
update(DeltaTime)
scene:draw()
text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
end
function update(dt)
scene:update(dt)
end
Thanks Dave, that’s prefect. I can start to do some things to see what piece of code does what through commenting it out.
@Kurall_Creator Changing existing code to see what happens is a great way to learn. You can do a forum search for craft code to get more examples. Just a reminder, when you post code, put ~~~ before and after your code so it displays correctly. I added them you your above example.
Thanks Dave,
Using your example and the inbuilt examples, I got a cool result.
I’m definitely happy picking up this package, learning how to create some interesting stuff.
@Kurall_Creator You’re off to a good start. There’s a lot of things to learn with Codea and it will keep you interested for a long time.