Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Dropboxing 3D objects

124»

Comments

  • pacpac
    Posts: 208

    Okay so I have 3ds max and can get the files to my ipad but it exports .obj and .mtl the mtl is the texture so can codea read the mtl. And how do I apply that texture?

    thanks Pac

  • pacpac
    Posts: 208
    Never mind I got it.

    Thanks pac
  • pacpac
    Posts: 208

    Okay so I am trying to use rigid bodies to make my objects collide but there are two problems 1: if I scale the model it will pass through the other model. 2: if I use my own model in place of craft.shape.box/sphere it will pass throught the other object. but this is only for the second object the first one works correctly.

  • pacpac
    edited May 3 Posts: 208
    function setup()
        -- Create a new craft scene
        scene = craft.scene()
    
       -- scene.sky.material.sky = color(255, 218, 0, 255)
    
        scene.camera:add(OrbitViewer, vec3(0,5,0), 15, 10, 20)
    
    
        -- create a sphere with a 1 meter radius
    sphere = scene:entity()
    
     model = craft.model("Nature:naturePack_002")   
        --sphere.scale 
    -- Attach a dynamic rigidbody
    sphere:add(craft.rigidbody, DYNAMIC, 0)
    sphere.scale = vec3(1,1,1) * 10
    sphere.eulerAngles = vec3(0,20,0)
    -- Add a sphere shape to respond to collisions
    sphere:add(craft.shape.model, model)
    sphere.model = craft.model("Nature:naturePack_002")
    sphere.position = vec3(-0.3,0,8)
    -- Attach a renderer and sphere model for visuals
    
    --sphere.model = craft.model.icosphere(1, 3)8
    --sphere.material = craft.material("Materials:Standard")
    
    sphere2 = scene:entity()
    
    model2 = craft.model("CastleKit:bridge")
        --sphere.scale 
    -- Attach a dynamic rigidbody
      sphere2.position = vec3(0,10,0)  
    sphere2.scale = vec3(1,1,1) / 20                    --this causes a problem
    sphere2.model = craft.model("CastleKit:bridge")
    
    sphere2:add(craft.rigidbody, DYNAMIC, 1)
    
    -- Add a sphere shape to respond to collisions
    sphere2:add(craft.shape.model, model2)                 --and this causes a problem.
    
        -- Create a new entity
        local e = scene:entity()
    end
    

    sorry if the code is a mess.

    thanks Pac

    sorry could not remember / find how to code to come out correctly.

  • dave1707dave1707 Mod
    edited May 3 Posts: 7,554

    @pac ~~~ before and after the code to format it correctly. I added them to your code above.

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Here's something you can look at that should help you.

    displayMode(FULLSCREEN)
    
    function setup()
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        scene = craft.scene()
        skyMaterial=scene.sky.material
        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)
        v.rx,v.ry=20,20
        createRect()
        createSphere()
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createRect() 
        c1=scene:entity()
        w=c1:add(craft.rigidbody,STATIC)
        w.restitution=1
        c1.position=vec3(0,0,0)
        c1.model = craft.model.cube(vec3(25,2,10))
        c1:add(craft.shape.model,c1.model)
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Blocks:Trunk White Top")
    end
    
    function createSphere()
        sphere1=scene:entity()
        s1=sphere1:add(craft.rigidbody,DYNAMIC)
        s1.restitution=1
        sphere1.position=vec3(0,30,0)
        sphere1.model = craft.model.icosphere(1,5)
        sphere1:add(craft.shape.sphere,1)
        sphere1.material = craft.material("Materials:Specular")
        sphere1.material.diffuse=color(255,0,0)
    end
    
  • pacpac
    Posts: 208
    That is nice but the problem is that I need the sphere to not be a sphere but to be a blocky character. And I need to scale the character up and make him larger.

    But when I do that it falls through the floor.

    Thanks Pac
  • Posts: 1,202
    @pac - if your object is centered on the triple axis, when you enlarge it it is probably moving in both positive and negative directions of each axis. You need to determine the initial y value for the object and move the object centre point up by (increase in y size)/2. Does that make sense?
  • pacpac
    edited May 3 Posts: 208
    You are right that is the problem but when I try to change the center of mass it tells me that it is read only.

    So how do you change the center of mass?

    Thanks @Bri_G
  • pacpac
    edited May 3 Posts: 208
    I just realized that I said the wrong thing I meant I need to make the blocky character smaller.

    So sorry Pac
  • pacpac
    Posts: 208
    Forget the last two comments.

    I think that the problem is that it just is not getting that ot has hit the other object.
  • Posts: 1,202

    @pac - if that’s the case, and you still lose half the character below the zero plane (x,z) then that would suggest that any change in size needs you to redefine the centre of mass. I think I have seen something similar before, I am sure you can move the object -I’ll get back to you soon.

  • pacpac
    Posts: 208
    Okay thanks
  • dave1707dave1707 Mod
    edited May 3 Posts: 7,554

    @pac Here's another version. I show a box by itself and a box where I tried to wrap the robot around it. One problem is the robot position it at the bottom of the robot and the box position is at the center of the box. So the bottom of the box and robot don't line up quite right.

    displayMode(FULLSCREEN)
    
    function setup()
        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), 200, 0, 400)
        v.rx,v.ry=20,160
        createFloor()
        createRobot()
        createBox()  
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createFloor()
        f1=scene:entity()
        f=f1:add(craft.rigidbody,STATIC)
        f.restitution=.4
        f1.position=vec3(0,0,0)
        f1.model = craft.model.cube(vec3(70,1,70))
        f1:add(craft.shape.model,f1.model)
        f1.material = craft.material("Materials:Standard")
    end
    
    function createBox()
        box1=scene:entity()
        f=box1:add(craft.rigidbody,DYNAMIC)
        f.restitution=.8
        box1.position=vec3(15,30,0)
        box1.model = craft.model.cube(vec3(3,5,3))
        box1.material = craft.material("Materials:Standard")
        f2=box1:add(craft.shape.box,vec3(3,5,3))
        box1.material.map = readImage("Blocks:Trunk White Top")
    end
    
    function createRobot()
        robot = scene:entity()
        r1=robot:add(craft.rigidbody,DYNAMIC)
        r1.restitution=.8
        robot.model = craft.model("Blocky Characters:Robot")
        robot.position=vec3(-15,30,0)
        r2=robot:add(craft.shape.box,vec3(3,5,3))
    end
    
  • pacpac
    Posts: 208

    Does the robot like role around for you or is that just me?

  • pacpac
    Posts: 208

    Good news I got it to work.

  • dave1707dave1707 Mod
    Posts: 7,554

    Yes, the robot rolls around for me. What does the code look like for the robot. Just wondering since you said you got it to work.

  • pacpac
    edited May 4 Posts: 208
    sphere2 = scene:entity()
    
    sphere2.model = craft.model("Blocky Characters:Robot")
    sphere2:add(craft.rigidbody, DYNAMIC, 1)
    
    --scale the entity down
    sphere2.scale = vec3(1,1,1) / 2                 --got it to scale
    
    --set the shape of the rigid body to a sphere. Size is realy the model.
    sphere2:add(craft.shape.sphere)                 --the sphere so how acts like the model.      What I mean is that it reports a hit front/ back/ side / bottom hit another object.   So it works just the same.
    

    See the sphere is acting just like the model would.

  • pacpac
    Posts: 208

    So I keep getting this error that I don’t under stand and I have looked all through reference trying to see if I have done some thing wrong.

    function touched(t)
    
        Position = vec2(t.x, t.y)
    
    O, D = MyCamera:screenToRay(Position)
    
    print(O, "O")
    print(D, "D")    
    
    
    end
    
  • pacpac
    Posts: 208

    It says I am trying to access a nil value method.

    Thanks Pac

  • dave1707dave1707 Mod
    Posts: 7,554

    See the tab OrbitViewer in example Cameras for an example of screenToRay.

  • pacpac
    Posts: 208
    Yes I tried putting the code into my project but it did not work.

    Would you please post some a little code so I may figure out what I am doing wrong.

    Thanks again @pac
  • pacpac
    Posts: 208
    So what I really need is to have it so that when touch the screen I can tell what object was clicked.

    Thanks @pac
  • pacpac
    Posts: 208
    Is there any way to see what the Angles that the camera can see?

    Thanks Pac
  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Here's an example of using screenToRay(). Tap the screen at different positions and it prints the origin and direction values. Right now I don't know exactly what those values mean or how to use them

    function setup()
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        scene = craft.scene()
        skyMaterial=scene.sky.material
        skyMaterial.horizon=color(99, 255, 0, 255)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
        createSphere()
    
        cam = scene.camera:get(craft.camera)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
    end
    
    function touched(t)
        if t.state==BEGAN then
            origin, dir = cam:screenToRay(vec2(t.x,t.y))
            print(t.x,t.y) 
            print(origin)
            print(dir)
        end
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createSphere()
        sphere1=scene:entity()
        sphere1.position=vec3(0,0,0)
        sphere1.model = craft.model.icosphere(1,5)
        sphere1.material = craft.material("Materials:Specular")
    end
    
  • pacpac
    Posts: 208

    Is there something wrong with my craft because if I do the

    cam = scene:get(craft.camera)
    

    it says that the position of it is read only. but if I make do

    cam = scene:entity()
    cam:get(craft.camera) 
    

    then it tells me that screen to ray is a nil value method.

    Please help.

    I have already deleted codea and reloaded it but it is still there.

    Thanks Pac

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Try using the lines that I show in the code above. You seem to be mixing things up. In your first line, you forgot camera. Try cam = scene.camera:get(craft.camera)

  • pacpac
    edited May 8 Posts: 208

    Sorry copying mistake when I copied your code into my program I still got that error.

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Can you run my code without any errors. Don't forget to include Cameras as a dependency. If it runs OK, then there's something you're doing wrong with your code.

  • pacpac
    Posts: 208

    Yes that is what is so wired about it. But if I where to copy an of your code into my code some part would quit working.

  • pacpac
    edited May 8 Posts: 208
    I commented ever thing out till all that was left was

    ~~~
    function setup()

    scene = craft.scene
    ~~~
    And your cam stuff and it still does not work.

    Most likely I am tired and will see the problem tomorrow.

    Thanks for all the help.
  • pacpac
    Posts: 208

    Okay so I got the problem worked out. And the direction and origin are to be put into a ray so you can see what you are touching and I did that but the problem is that the ray returns a table and I can’t seem to read what is inside.

    Thanks Pac

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac screenToRay returns 2 vec3 variables that can be printed. I do that in my above example. Why do you think it returns a table that you can't read.

  • pacpac
    edited May 8 Posts: 208
    No using your code above I got the screen to ray to work but I can't see the table that the normal raycast is returning.

    See I got it to work that I am passing the info from the screen to ray in to the physics raycast but I can't see what the physics ray cast has returned.
  • pacpac
    Posts: 208

    Okay so one of my comments disappeared.

    So could you please post an example of phyiscs.raycasting at work because there is no example in the reference and I keep getting and error saying that I have put a vec3 in a vec2 spot but I fallowed the reference.

    Thanks @Pac

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Here's an example of physics.raycast. The line being drawn just shows where the raycast is looking and not part of raycast itself. The screen text "point" shows the x,y screen values where raycast first touches a physics object.

    function setup()
        textMode(CORNER)
        p1=physics.body(CIRCLE,40)
        p1.type=STATIC
        p1.x=WIDTH/2
        p1.y=600
        stroke(255)
        strokeWidth(2)
        x=0
        v=3
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        ellipse(p1.x,p1.y,80)
        x=x+v
        if x>WIDTH or x<1 then
            v=-v
        end
        line(WIDTH/2,0,x,800)
        point=vec2(0,0)
    
        tab=physics.raycast(vec2(WIDTH/2,0),vec2(x,800))
    
        if tab~=nil then
            for a,b in pairs(tab) do
                if a=="point" then
                    point=b
                end
            end
        end
    
        str=string.format("point  %f %f",point.x,point.y)
        text(str,100,HEIGHT-100)
    end
    
  • pacpac
    Posts: 208

    Does raycasting work in 3d?
    It is okay if it does not I just need to know.

    thanks

  • dave1707dave1707 Mod
    Posts: 7,554

    @pac I guess spherecast in Craft physics will work in 3D.

  • pacpac
    Posts: 208

    Okay I will check that out.

  • pacpac
    Posts: 208

    So I got the sphere cast working and it says that it is hitting and object and I made a sphere to show where it was hitting. So it is going well but there is one problem that is not to big of a deal but when I use/change so code that was in your raycast example to get what entity it hit it keeps printing out entity.

    Thanks

  • pacpac
    edited May 9 Posts: 208

    Here is the code.


    tab = scene.physics:spherecast(scene.camera.position, vec3(CameraXY,-50,0), 500, 50) if tab~=nil then for a,b in pairs(tab) do if a=="point" then sphere1.position = b point=b end --check to see which object it gas hit if a=="entity" then print(b) end end end

    any guesses?

  • dave1707dave1707 Mod
    Posts: 7,554

    According to the reference, the table returned from spherecast doesn't have a lot of info. About the only thing to identify the object hit is by the position. And entity just returns entity.

  • pacpac
    edited May 9 Posts: 208
    Oh then if you needed that object to be selected how would you do it.

    I already that of one way to do it I am just interested ro know what you would do.

    Thanks @dave1707
  • dave1707dave1707 Mod
    Posts: 7,554

    @pac Since the only info you have is the x,y,z value from spherecast, I would compare those values to the values of all the objects. Since you don't get the exact value of the hit object, then I would subtract the spherecast value from each of the objects and the one with the smallest difference would be the one hit.

  • pacpac
    Posts: 208

    That is the same idea I had so we are in agreement about that idea. Well that is good to know.

    Thanks @dave1707

  • pacpac
    Posts: 208
    Okay got a phone know all I need I are instructions on how to become a beta.

    Thanks @pac
Sign In or Register to comment.