Forum

web link on object

15 May 2016 11:19
I tried to get object inside mouse x and y coordinates
but it gives null value not the object, what can be the reson ?

"use strict"

// register the application module
b4w.register("AQSTES", function(exports, require) {

// import modules used by the app
var m_app = require("app");
var m_cfg = require("config");
var m_data = require("data");
var m_ver = require("version");


/*
from b4w tut

*/

var m_anim = require("animation");
//var m_app = require("app");
var m_cam = require("camera");
//var m_cfg = require("config");
var m_cont = require("container");
var m_cons = require("constraints");
var m_ctl = require("controls");
//var m_data = require("data");
var m_obj = require("objects");
var m_phy = require("physics");
var m_quat = require("quat");
var m_scenes = require("scenes");
var m_trans = require("transform");
var m_tsr = require("tsr");
var m_util = require("util");
var m_vec3 = require("vec3");
var m_mouse = require("mouse");
var m_main = require("main");

/**/

// detect application mode
var DEBUG = (m_ver.type() === "DEBUG");

// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_std_assets_path() + "AQSTES/";

/**
* export the method to initialize the app (called at the bottom of this file)
*/
exports.init = function() {

m_app.init({
canvas_container_id: "main_canvas_container",
callback: init_cb,
show_fps: DEBUG,
console_verbose: DEBUG,
autoresize: true
});
}

/**
* callback executed when the app is initialized
*/
function init_cb(canvas_elem, success) {

if (!success) {
console.log("b4w init failure");
return;
}

m_app.enable_controls();
load();
}

/**
* load the scene data
*/
function load() {
m_data.load(APP_ASSETS_PATH + "AQSTES.json", load_cb);
}

/**
* callback executed when the scene is loaded
*/
function load_cb(data_id, success) {

if (!success) {
console.log("b4w load failure");
return;
}

m_app.enable_controls();
m_app.enable_camera_controls();

// place your code here


var from = new Float32Array(3);
var to = new Float32Array(3);


//////////////////

function main_canvas_down(e) {



var x = m_mouse.get_coords_x(e);
var y = m_mouse.get_coords_y(e);

var obj = m_scenes.pick_object(x, y);
var obts = m_scenes.get_all_objects();

console.log(obj);


}


var cont = m_cont.get_container();
cont.addEventListener("mousedown", main_canvas_down, false);
//canvas_elem.addEventListener("mousedown", main_canvas_down);
//canvas_elem.addEventListener("touchstart", main_canvas_down);
console.log("Dilan");
m_mouse.enable_mouse_hover_outline();
}


});

// import the app module and start the app by calling the init method
b4w.require("AQSTES").init();
Software Engineer
16 May 2016 10:35
I tried to get object inside mouse x and y coordinates
but it gives null value not the object, what can be the reson ?
Hello!
Please make sure that you've marked the object as "Selectable"
Blend4Web Team - developer
Twitter
LinkedIn
16 May 2016 12:06
Much Appreciated Mr. Konstantin, Its working
Software Engineer
 
Please register or log in to leave a reply.