Loading Models in same position, so that it overlays - javascript

I'm using the multimodel loader of the Autodesk. When I load the same model to the viewer, the position of previous model shifts to a different position.
I'm using transformations, like translation,rotation and scaling, to adjust the position of the model so that is overlays over the first model. Is there a way to load the model in a way where it overlaps on loading the second model?
Also, for the z-oriented rvt and nwc files, is there a fix?
For reference, I have been following these blogs:
https://forge.autodesk.com/blog/preparing-your-viewing-application-multi-model-workflows
https://forge.autodesk.com/blog/preparing-your-viewing-application-multi-model-workflows-part-2-model-loader

It seems to have another placement or offsets applied to loaded models while using the ModelLoaderExtension. If you just want to load the same model twice,
here is a sample for you:
var models = [
'123.svf',
'123.svf'
];
function _onGeometryLoaded( event ) {
if( urns.length <= 0 ) {
viewer.removeEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
return;
}
viewer.loadModel( urns[0], { globalOffset: event.model.getData().globalOffset } );
urns.splice( 0, 1 );
}
viewer.addEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
viewer.loadModel( urns[0] );
urns.splice( 0, 1 );
Hope it helps!

Related

Not able to make sprite interaction to work

I'm trying to build a simple game menu, containing some clickable sprites, which will be used as buttons to navigate around the menu.
( I'm using the latest pixi.js (v4.3.5) )
Structure of my app:
loader.module ( makes use of the pixi.loaders.Loader )
events.module (basic event sub/pub module)
base.view
menu.view ( extends base.view )
game.main
How it all works now ?
Both all resources and ui elements have to be explicitly defined, before initializing the view.
so in the menu.view, the follwoing attributes have to be defined.
this.resources = [
{ name: 'start', src: 'img/start.png'},
{ name: 'start2', src: 'img/start2.png'}
];
this.ui = [{
name: 'start', /// resource name
type: 'img',
pos: { x: 0, y: 0 }
}];
Now I only need to call view.init() to get it all loaded and drawn. On the visual side, evrything works perfectly, however the 'start' sprite (which has it's interactive and buttonMode set to true) is not reacting to any mouse events.
The below method is responsible for getting the required resource and returning a new sprite. It also enables the actual interaction functionality as part of this process. But the test function is never triggered for some reason.
__getSpriteObject( element ){
let sprite = new PIXI.Sprite( this.loader.loader.resources[ element.name ].texture );
sprite.x = element.pos.x;
sprite.y = element.pos.y;
sprite.interactive = true;
sprite.buttonMode = true;
console.log( sprite )
sprite.on('pointerdown', function(){
console.log("what")
})
return sprite;
}
If the above info isn't sufficient , here is also a working example.
I answered this here: http://www.html5gamedevs.com/topic/28474-not-able-to-make-sprite-interaction-to-work/?do=findComment&comment=163647 in any case anyone else is curious

What does rootmodifers do in famo.us?

I am new to Famo.us, can anybody explain me what does rootmodifers do in famo.us, here is its example
function SlideshowView () {
Views.apply(this, arguments);
this.rootModifier = new StateModifier({
size:this.options.size
});
this.mainNode = this.add(this.rootModifier);
_createLightBox.call(this);
_createSlides.call(this);
}
this.rootMidifier just allows you to have a way to control the entire slideShow's position, opacity, origin, or alignment later in the applications. More importantly this.rootModifier is added to the render node like this this.mainNode = this.add(this.rootModifier); This code places the modifier at the top of the render tree for the slideshow branch and exposes access to the modifier for later use in the all. For example later in the app you could have a function that changes the opacity.
SlideShow.prototype.hide = function() {
this.rootModifier.setOpacity(0, {duration: 3000});
}

How to load image on demand

I have this simple image zoom jQuery. Here is a Demo example. It uses the elevateZoom jQuery.
The code behind is very simple:
<img id="zoom_05" src='small_image1.png' data-zoom-image="large_image1.jpg"/>
<script>
$vc("#zoom_05").elevateZoom({
zoomType : "inner",
cursor: "crosshair"
});
</script>
My question, is how can i make the large image load on demand, only when the mouse is over it. Please have a look at this demo example and let me know what i need to add in the code.
img element (id="zoom_05") above, would not load large_image1.jpg on its own.
Large image load happens because elevateZoom() looks into its data-zoom-image value and immediately loads it. One way around this behaviour is to defer elevateZoom() until user hover's over the small image for the first time. Quick example:
jQuery( function () {
var elevate_zoom_attached = false, $zoom_05 = $("#zoom_05") ;
$zoom_05.hover(
// hover IN
function () {
if ( ! elevate_zoom_attached ) {
$zoom_05.elevateZoom({
zoomType : "inner",
cursor : "crosshair"
});
elevate_zoom_attached = true ;
};
},
// hover OUT
function () {
if ( elevate_zoom_attached) { // no need for hover any more
$zoom_05.off("hover");
}
}
);
}) ;
Mind you this is an quick, on-top-of-my-head code, but should work ...
Also in this case elevateZoom() action might not be immediate while large image loading is going on.
I used this idea to initiate zoom on any number of images on the same page by adding a zoom class to the image. It works without any HOVER OUT
<img class="zoom" src="myimage.png" data-zoom-image="mybigimage.png"/>
$('.zoom').hover(
// hover IN
function () {
var currImg = $(this); //get the current image
if (!currImg.hasClass('zoomon')) { //if it hasn't been initialized
currImg.elevateZoom(); //initialize elevateZoom
currImg.addClass('zoomon'); //add the zoomon class to the img so it doesn't re-initialize
}
})

ExtJs4 - AutoComplete ComboBox not displaying Empty Text

I have a combo-box with following configuration.
{
fieldLabel:'Service',
xtype:'combo',
displayField: 'srvcDesc',
store: storeServiceCodeVar,
valueField:'srvcCD',
id:'serviceCodeId',
name:'serviceCodeName',
queryMode: 'remote',
queryDelay:100,
typeAhead: true,
minChars:0,
hideTrigger:true,
forceSelection:true,
maxHeight:23,
deferEmptyText:false,
autoSelect:true,
fieldStyle:'text-transform:uppercase',
listConfig: {
loadingText: 'Loading...',
// Custom rendering template for each item
getInnerTpl: function() {
return '<table width="200px"><tr><td height="5"></td></tr><tr valign="top"><td>Code:{srvcCD}</td></tr><tr><td height="2"></td></tr><tr valign="top"><td>Description:{srvcDesc}</td></tr><tr><td height="5"></td></tr></table>';
},
emptyText:'No Values Found'
}
}
The issue is that when there is no data returned from the server, then emptyText (which has value - No values found) gets displayed for may be a millisecond and goes off. I want it to stay there till the next query if fired. How is it possible. I have tried with deferEmptyText but no luck.
Could someone throw some light on this. I am using ExtJS 4 and behavior is same in IE9 and Mozilla.
Thanks in advance.
From stepping through the source, it doesn't seem like there is any reference to the listConfig.emptyText being used to determine whether or not to set the element's height to a number other than zero.
I've ended up overriding the alignPicker() function which Ext.form.field.ComboBox inherits from Ext.form.field.Picker, and adding a check for listConfig.emptyText.
Ext.override(Ext.form.field.ComboBox, {
alignPicker: function() {
var picker, height;
if (this.isExpanded) {
// Get the picker component.
picker = this.getPicker();
if (this.matchFieldWidth) {
// Set the default height to null, since we don't
// automatically want to have the height changed.
height = null;
// If our store exists, but the count is zero
// and we've got no emptyText defined...
if (picker.store &&
picker.store.getCount() === 0 &&
Ext.isEmpty(this.listConfig.emptyText)) {
// ...we set the height to zero.
height = 0;
}
// Set the size of the picker component.
picker.setSize(this.bodyEl.getWidth(), height);
}
if (picker.isFloating()) {
this.doAlign();
}
}
}
});
Hope this helps!
A word of warning here. I'm on ExtJs 4-0-6 and it seems that there is now some code in Ext.form.field.ComboBox and it no longer just relies on inheriting the method from Ext.field.form.Picker.
So, instead the above code should now override the code directly in Ext.field.form.Picker rather than in the ComboBox.
But admittedly, hopefully Sencha will fix this themselves soon in 4.1.

Extjs Ext.ComboBox autosize over existing content

I have a problem when apply an Ext.ComboBox over an existing html select item, even if the existing content makes the html select about 20px (by it's content non static width is set), the Ext.ComboBox will resize to a sort of default, large, width value.
There's a way to auto resize the Ext.ComboBox based on the existing items and no using the default width?
Even if I know which best tool Ext is, this issue will let my colleagues to discard Extjs.
Thanks in advance
You can't technically make a combo "auto width" -- Ext actually converts the <select> into a regular <input> behind the scenes, and <input> elements have to have a width/size specified. However, you can trick Ext into sizing the combo based on the existing <select> which should give you the same end result. Here's an example from the Ext combo demo page, where I have modified the width config value:
var converted = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
transform:'state',
width: Ext.fly('state').getWidth(),
forceSelection:true
});
The obvious caveat would be that if you subsequently modify the list after it's rendered, the combo will not resize itself automatically and you'd have to figure out a way to resize it yourself.
Use this code:
Ext.ux.ResizableComboBox = Ext.extend(Ext.form.ComboBox, {
initComponent: function(){
Ext.ux.ResizableComboBox.superclass.initComponent.call(this);
this.on('render', this.resizeToFitContent, this);
},
resizeToFitContent: function(){
if (!this.elMetrics){
this.elMetrics = Ext.util.TextMetrics.createInstance(this.getEl());
}
var m = this.elMetrics, width = 0, el = this.el, s = this.getSize();
this.store.each(function (r) {
var text = r.get(this.displayField);
width = Math.max(width, m.getWidth(text));
}, this);
if (el) {
width += el.getBorderWidth('lr');
width += el.getPadding('lr');
}
if (this.trigger) {
width += this.trigger.getWidth();
}
s.width = width;
this.setSize(s);
this.store.on({
'datachange': this.resizeToFitContent,
'add': this.resizeToFitContent,
'remove': this.resizeToFitContent,
'load': this.resizeToFitContent,
'update': this.resizeToFitContent,
buffer: 10,
scope: this
});
}
});Ext.reg('resizable-combo', Ext.ux.ResizableComboBox);
In addition to what bmoeskau suggests, you can use an xtemplate for your combo's items. This will give you the ability to change the look of the item. You can wrap text, add images, etc.
add a listener to the afterrender event and set the width if the list (the div that drops down ) to auto e.g.
afterrender: function(combo){
combo.list.setSize('auto', 0);
combo.innerList.setSize('auto', 0);
}
The reason I am using afterrender and not render is because if you set lazyInit to false it will set the list width, so in afterrender you override that setWidth
I'm pretty sure you can get ExtJs to render whatever html items you need to, in the way you want them to be rendered.
here's some code from the Examples/Form/Combos.js file:
var converted = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
transform:'state',
width:20, //<-- set this config value!
forceSelection:true
});
in the code that you're using to transform the combo, just specify a width for the ExtJs combo.

Categories

Resources