Help - Ray Cast decal doesn't appear
19 June 2017 21:28
Hi everyone, i created a test project for my future shooting app. Now i am developing how to create the trace of the bullet once it hit the objects in the scene.For this i want to use the code-snippet of RayTest. I check my code hundreds of time, i check the JS console of the browser, look all good, but no trace!!… please help me, i m quite new, just two day using blend4web.
I attach .blend file, the console and here the .js , the scene is a test, so i use just one cube and one plance for decal .
Thank you in advance.
I attach .blend file, the console and here the .js , the scene is a test, so i use just one cube and one plance for decal .
Thank you in advance.
"use strict"
// register the application module
b4w.register("1aTestdecal_main", function(exports, require) {
// import modules used by the app
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_math = require("math");
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_version = require("version");
var m_preloader = require("preloader");
// detect application mode
var DEBUG = (m_version.type() == "DEBUG");
// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_assets_path("1aTestdecal");
/**
* export the method to initialize the app (called at the bottom of this file)
*/
exports.init = function() {
m_app.init({
autoresize: true,
callback: init_cb,
canvas_container_id: "main_canvas_container",
physics_enabled: true,
show_fps: true,
assets_dds_available: !DEBUG,
assets_min50_available: !DEBUG,
console_verbose: true
});
}
/**
* callback executed when the app is initialized
*/
function init_cb(canvas_elem, success) {
if (!success) {
console.log("b4w init failure");
return;
}
m_preloader.create_preloader();
// ignore right-click on the canvas element
canvas_elem.oncontextmenu = function(e) {
e.preventDefault();
e.stopPropagation();
return false;
};
load();
}
/**
* load the scene data
*/
function load() {
m_data.load(APP_ASSETS_PATH + "1aTestdecal.json", load_cb, preloader_cb);
}
/**
* update the app's preloader
*/
function preloader_cb(percentage) {
m_preloader.update_preloader(percentage);
}
/**
* callback executed when the scene data is loaded
*/
function load_cb(data_id, success) {
if (!success) {
console.log("b4w load failure");
return;
}
m_app.enable_camera_controls();
init_logic();
// place your code here
}
function init_logic() {
var from = new Float32Array(3);
var pline = m_math.create_pline();
var to = new Float32Array(3);
var decal_num = 0;
var decal_src = m_scenes.get_object_by_name("Decal");
var decal_tsr = m_tsr.create();
var obj_tsr = m_tsr.create();
var decal_rot = m_quat.create();
var ray_test_cb = function(id, hit_fract, obj_hit, hit_time, hit_pos, hit_norm) {
var decal = m_obj.copy(decal_src, "decal" + String(++decal_num), false);
m_scenes.append_object(decal);
m_tsr.set_trans(hit_pos, decal_tsr);
m_quat.rotationTo(m_util.AXIS_Z, hit_norm, decal_rot);
m_trans.set_rotation_v(decal, decal_rot);
m_tsr.set_quat(decal_rot, decal_tsr);
if (obj_hit && m_anim.is_animated(obj_hit)) {
m_trans.get_tsr(obj_hit, obj_tsr);
m_tsr.invert(obj_tsr, obj_tsr);
m_tsr.multiply(obj_tsr, decal_tsr, decal_tsr);
var offset = m_tsr.get_trans_view(decal_tsr);
var rot_offset = m_tsr.get_quat_view(decal_tsr);
m_cons.append_stiff(decal, obj_hit, offset, rot_offset);
}
m_trans.set_tsr(decal, decal_tsr);
}
var mouse_cb = function(e) {
var x = e.clientX;
var y = e.clientY;
m_cam.calc_ray(m_scenes.get_active_camera(), x, y, pline);
m_math.get_pline_directional_vec(pline, to);
m_vec3.scale(to, 100, to);
var obj_src = m_scenes.get_active_camera();
var id = m_phy.append_ray_test_ext(obj_src, from, to, "ANY",
ray_test_cb, true, false, true, true);
}
var cont = m_cont.get_container();
cont.addEventListener("mousedown", mouse_cb, false);
}
});
// import the app module and start the app by calling the init method
b4w.require("1aTestdecal_main").init();
20 June 2017 05:35
Hi Monder23,
In the Ray Test code snippet, there is a button on the lower left to Make Project. If you click that button, it will copy the project. Once you have a copy of the project you can start making your changes. This way, you start with a working project and if you make a change the breaks it, you will know what the problem is.
In the Ray Test code snippet, there is a button on the lower left to Make Project. If you click that button, it will copy the project. Once you have a copy of the project you can start making your changes. This way, you start with a working project and if you make a change the breaks it, you will know what the problem is.
20 June 2017 19:49
thank Will i tried do this in the first place but actually is not working… after i click the button y say and i name the project from ray test snippet the page is: http status 404 The requested resource is not available.
I also try recreate bymyself also the raytest project using the .js the.blend and the .json files we have in blend4web directory but not working too, so why try create my own…some have solution?
I also try recreate bymyself also the raytest project using the .js the.blend and the .json files we have in blend4web directory but not working too, so why try create my own…some have solution?
20 June 2017 19:54