Hello guys I am new here and definitely rusty on javascript, and that why I am asking for help adding a function to the script that change the tooltip (pastille) colors. I have already a sample of the code but I can't find the way to add the function into my main code.
Here is the function to add:
const version = '1.12.1';
const urlid = '526be2fd9c56426aacc0674548c7f543';
const iframe = document.getElementById('api-frame');
const client = new Sketchfab(version, iframe);
let api;
let currentAnnotation;
const render = () => {
if (currentAnnotation) {
const current = 'annotation-' + currentAnnotation;
document.querySelector('.slide.active').classList.remove('active');
document.getElementById(current).classList.add('active');
}
};
var buttonFront = document.getElementById('a2');
var buttonBack = document.getElementById('a3');
var apiSkfb;
var selectedAnnotation = -1;
var lastSelectedAnnotation = -1;
var pastillesURL;
(function() {
// create images pastilles from svg
// create transparent image for pastille from svg
function computePastilles(wCanvas, hCanvas, bgColor, bgBorderColor, fgColor, fgBorderColor, text, numHotspot, wPastille, hPastille) {
var wSize = wPastille / 10.0;
var col = wCanvas / wSize;
var row = hCanvas / wSize;
var padding = 3;
var w = wSize - padding;
var cx;
var cy = w * 0.5;
var ty = cy + 0;
var pastille = '';
var num = 0;
for (var i = 0; i < row; i++) {
cx = wSize * 0.5;
for (var k = 0; k < col; k++) {
num++;
var letters = text === 0 ? num : text[num];
var circle = "<circle cx="".concat(cx, ""ntttttttcy="").concat(cy, ""ntttttttr="20"ntttttttfill="").concat(bgColor, ""ntttttttstroke="").concat(bgBorderColor, ""ntttttttstroke-width="2"/>");
var textVG = "<text font-size="26"nttttttstroke="".concat(fgBorderColor, ""nttttttfill="").concat(fgColor, ""nttttttfont-family="sans-serif"ntttttttext-anchor="middle"nttttttalignment-baseline="baseline"nttttttx="").concat(cx, ""ntttttty="").concat(ty, "">").concat(letters, "</text>");
pastille += circle + textVG;
cx += wSize;
}
cy += wSize;
ty += wSize;
}
var s = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
s.setAttribute('version', '1.1');
s.setAttribute('baseProfile', 'full');
s.setAttribute('width', wPastille);
s.setAttribute('height', hPastille);
s.setAttribute('viewBox', "0 0 ".concat(wPastille, " ").concat(hPastille));
s.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
s.innerHTML = pastille; // make it base64
var svg64 = btoa(s.outerHTML);
var b64Start = 'data:image/svg+xml;base64,';
var image64 = b64Start + svg64;
var textureOptions = {
url: image64,
colNumber: col,
padding: padding,
iconSize: w
};
return textureOptions;
}
function getNewPastilleURL(bgColor, bgBorderColor, fgColor, fgBorderColor, text, numHotspot, w, h) {
var imageData;
imageData = computePastilles(w, h, bgColor, bgBorderColor, fgColor, fgBorderColor, text, numHotspot, w, h);
return imageData;
}
pastillesURL = getNewPastilleURL('#FF671D', '#FF671D', 'white', 'none', 0, 50, 512, 256);
})();
/////////////////////////////////////
// end pastilles
/////////////////////////////////////
function actionSkfb() {
var error = function error(err) {
console.error('Sketchfab API error', err);
};
var success = function success(api) {
apiSkfb = api;
apiSkfb.start(function() {
api.addEventListener('viewerready', function() {
apiSkfb.setAnnotationsTexture(pastillesURL, function() {});
});
});
};
client.init(urlid, {
success: success,
error: error,
annotation: 0, // Usage: Setting to [1 – 100] will automatically load that annotation when the viewer starts.
animation_autoplay: 1,
annotation_tooltip_visible: 0,
annotations_visible: 1, // Usage: Setting to 0 will hide annotations by default.
autospin: 0, // Usage: Setting to any other number will cause the model to automatically spin around the z-axis after loading.
autostart: 1, // Usage: Setting to 1 will make the model load immediately once the page is ready, rather than waiting for a user to click the Play button.
cardboard: 0, // Usage: Start the viewer in stereoscopic VR Mode built for Google Cardboard and similar devices.
camera: 1, // Usage: Setting to 0 will skip the initial animation that occurs when a model is loaded, and immediately show the model in its default position.
preload: 1, // Usage: Setting to 1 will force all resources (textures) to download before the scene is displayed.
ui_stop: 0, // Usage: Setting to 0 will hide the "Disable Viewer" button in the top right so that users cannot stop the 3D render once it is started.
transparent: 0, // Usage: Setting to 1 will make the model's background transparent
ui_animations: 0, // Usage: Setting to 0 will hide the animation menu and timeline.
ui_annotations: 1, // Usage: Setting to 0 will hide the Annotation menu.
ui_controls: 0, // Usage: Setting to 0 will hide all the viewer controls at the bottom of the viewer (Help, Settings, Inspector, VR, Fullscreen, Annotations, and Animations).
ui_fullscreen: 1, // Usage: Setting to 0 will hide the Fullscreen button.
ui_general_controls: 0, // Usage: Setting to 0 will hide main control buttons in the bottom right of the viewer (Help, Settings, Inspector, VR, Fullscreen).
ui_help: 1, // Usage: Setting to 0 will hide the Help button.
ui_hint: 0, // Usage: Setting to 0 will always hide the viewer hint animation ("click & hold to rotate"). Setting to 1 will show the hint the first time per browser session (using a cookie). Setting to 2 will always show the hint.
ui_color:'FF671D',
prevent_user_light_rotation: 1,
orbit_constraint_zoom_in: 50,
dof_circle: 1,
ui_infos: 0, // Usage: Setting to 0 will hide the model info bar at the top of the viewer.
ui_inspector: 0, // Usage: Setting to 0 will hide the inspector button.
ui_settings: 0, // Usage: Setting to 0 will hide the Settings button.
ui_vr: 0, // Usage: Setting to 0 will hide the View in VR button.
ui_ar: 0, // Usage: Setting to 0 will hide the View in AR button.
ui_watermark_link: 0, // Usage: Setting to 0 remove the link from the Sketchfab logo watermark.
ui_watermark: 0, // Usage: Setting to 0 remove the Sketchfab logo watermark.
});
};
actionSkfb();
This is the code we have starting and where I need to add fur function to change "Pastille color"
const version = '1.12.1';
const urlid = '526be2fd9c56426aacc0674548c7f543';
const iframe = document.getElementById('api-frame');
const client = new Sketchfab(version, iframe);
let api;
let currentAnnotation;
const render = () => {
if (currentAnnotation) {
const current = 'annotation-' + currentAnnotation;
document.querySelector('.slide.active').classList.remove('active');
document.getElementById(current).classList.add('active');
}
};
client.init(urlid, {
annotation: 0, // Usage: Setting to [1 – 100] will automatically load that annotation when the viewer starts.
animation_autoplay: 1,
annotation_tooltip_visible: 0,
annotations_visible: 1, // Usage: Setting to 0 will hide annotations by default.
autospin: 0, // Usage: Setting to any other number will cause the model to automatically spin around the z-axis after loading.
autostart: 1, // Usage: Setting to 1 will make the model load immediately once the page is ready, rather than waiting for a user to click the Play button.
cardboard: 0, // Usage: Start the viewer in stereoscopic VR Mode built for Google Cardboard and similar devices.
camera: 1, // Usage: Setting to 0 will skip the initial animation that occurs when a model is loaded, and immediately show the model in its default position.
preload: 1, // Usage: Setting to 1 will force all resources (textures) to download before the scene is displayed.
ui_stop: 0, // Usage: Setting to 0 will hide the "Disable Viewer" button in the top right so that users cannot stop the 3D render once it is started.
transparent: 0, // Usage: Setting to 1 will make the model's background transparent
ui_animations: 0, // Usage: Setting to 0 will hide the animation menu and timeline.
ui_annotations: 1, // Usage: Setting to 0 will hide the Annotation menu.
ui_controls: 1, // Usage: Setting to 0 will hide all the viewer controls at the bottom of the viewer (Help, Settings, Inspector, VR, Fullscreen, Annotations, and Animations).
ui_fullscreen: 1, // Usage: Setting to 0 will hide the Fullscreen button.
ui_general_controls: 0, // Usage: Setting to 0 will hide main control buttons in the bottom right of the viewer (Help, Settings, Inspector, VR, Fullscreen).
ui_help: 1, // Usage: Setting to 0 will hide the Help button.
ui_hint: 0, // Usage: Setting to 0 will always hide the viewer hint animation ("click & hold to rotate"). Setting to 1 will show the hint the first time per browser session (using a cookie). Setting to 2 will always show the hint.
ui_color:'FF671D',
prevent_user_light_rotation: 1,
orbit_constraint_zoom_in: 50,
dof_circle: 1,
ui_infos: 0, // Usage: Setting to 0 will hide the model info bar at the top of the viewer.
ui_inspector: 0, // Usage: Setting to 0 will hide the inspector button.
ui_settings: 0, // Usage: Setting to 0 will hide the Settings button.
ui_vr: 0, // Usage: Setting to 0 will hide the View in VR button.
ui_ar: 0, // Usage: Setting to 0 will hide the View in AR button.
ui_watermark_link: 0, // Usage: Setting to 0 remove the link from the Sketchfab logo watermark.
ui_watermark: 0, // Usage: Setting to 0 remove the Sketchfab logo watermark.
success: (apiClient) => {
api = apiClient;
api.addEventListener('viewerready', () => {
// Update the current annotation when the annotation changes
api.addEventListener('annotationSelect', (index) => {
currentAnnotation = 1 + index;
render();
});
});
},
error: () => window.console.log('Error while initializing the viewer')
});