I have a scene created in blender and consists of different meshes. Each mesh has child-of constraint which i have added. When this scene is exported to .babylon file and used, there is no parent-child constraint preserved. Do I add this constraint separately or is there any way to use this constraint from blender ?
If I have to add the constraint separately then how ?
I haven't found a way to let Blender export ChildOf contraints as parent relationships for Babylon directly but you can set the relationship using 'parent' on the mesh in your script. Let's say you have 4 boxes in blender A, B1, B2 and C.
A is parent of B1 and B2,
C is child of B1.
:
// ... after loading the scene in the browser
// store world coordinates
var wa = a.position.clone();
var wb1 = b1.position.clone();
var wb2 = b1.position.clone();
var wc = c1.position.clone();
// set to local coordinates (storing difference vector)
b1.position = b1.position.subtract(wa);
b2.position = b2.position.subtract(wa);
c.position = c.position.subtract(wb1);
// set relationship
c.parent = b1;
b1.parent = a;
b2.parent = a;
Related
After reading this excellent Medium article, I've been stoked on Migrations in CraftCMS. They've been super useful in importing the same changes across the 10 or so developers who work on our site.
When trying to change the handles on individual fields within block types within matrix blocks (whew) via migrations, I came across a hurdle. The field itself can easily have its "handle" attribute updated, but the columns table for that matrix block's content (matrixcontent_xxxxx) do not get updated to reflect any updated handles. The association between the Matrix Block & its associated Matrix Content table only exists in the info column in the field record for that Matrix Block.
If the Matrix Block's field is updated via the CMS, the change is reflected, so it's gotta be somewhere in Craft's source, but it's not apparent through the Craft CMS Class Reference.
Any ideas?
Edited to add the migration snippet:
public function safeUp()
{
// Strings for labels, etc.
$matrix_block_instructions = "instructions";
$block_label = "Video";
$block_handle = "video";
$field_handle = "video_url";
$field_label = "Video URL";
$field_instructions = "Add a YouTube or Facebook video URL.";
// Fetching the MatrixBlock fields used on the entries themselves
$video_gallery_1 = Craft::$app->fields->getFieldByHandle("handle_1");
$video_gallery_2 = Craft::$app->fields->getFieldByHandle("handle_2");
$video_gallery_3 = Craft::$app->fields->getFieldByHandle("handle_3");
$galleries = [$video_gallery_1, $video_gallery_2, $video_gallery_3];
foreach( $galleries as $gallery ) {
// Fetching the record for this specific MatrixBlock field.
$gallery_record = \craft\records\Field::find()->where(
['id' => $gallery->id]
)->one();
// Fetching the record for this specific MatrixBlockType
$gallery_block_id = $gallery->getBlockTypes()[0]->id;
$gallery_block = \craft\records\MatrixBlockType::find()->where(
['id' => $gallery_block_id]
)->one();
// Assigning standard labels for the MatrixBlockType
$gallery_block->name = $block_label;
$gallery_block->handle = $block_handle;
$gallery_block->update();
// Getting the specific ... 1 ... field to edit
$field_group = \craft\records\FieldLayout::find()->where(
['id' => $gallery_block->fieldLayoutId]
)->one();
$field_layout_field = $field_group->fields[0];
$field = $field_layout_field->field;
$field = \craft\records\Field::find()->where(
['id' => $field->id]
)->one();
// Assigning standard labels for the Label
$field->name = $field_label;
$field->handle = $field_handle;
$field->instructions = $field_instructions;
$field->update();
// Updating the MatrixBlock record with new instructions
$gallery_record->refresh();
$gallery_record->instructions = $matrix_block_instructions;
$gallery_record->update();
}
OK, so my apologies if anyone was stoked on figuring this out, but my approach above was kind of a crazy person's approach, but I've found my own solution.
The key here is that I should have been interacting with craft\fields\MatrixBlock and the craft\fields\PlainText objects, not craft\records\Field objects. There's a method within \craft\services\Fields for saving the field that requires a FieldInterface implemented. This is actually the default classes returned, and I was making more work for myself in the code!
Within that foreach loop, this worked out:
// Fetching the record for this specific MatrixBlock field.
$gallery->instructions = $matrix_block_instructions;
// Update the MatrixBlockType
$gallery_block_id = $gallery->getBlockTypes()[0]->id;
$gallery_block = \craft\records\MatrixBlockType::find()->where(
['id' => $gallery_block_id]
)->one();
$gallery_block->name = $block_label;
$gallery_block->handle = $block_handle;
$gallery_block->update();
// Update the actual field.
$field = $gallery->blockTypeFields[0];
$field->name = $field_label;
$field->handle = $field_handle;
$field->instructions = $field_instructions;
Craft::$app->getFields()->saveField( $field );
Craft::$app->getFields()->saveField( $gallery );
Thanks for looking at this, and sorry for being a crazy person.
I want to create a "Fact" type relationship between a Measure group and a "Fact dimension" both based on the same fact table.
I use the below piece of code
var cubeDim = OlapCube.Dimensions.GetByName(dimensionName);
var regMgDim = new RegularMeasureGroupDimension(cubeDim.ID);
olapMeasureGroup.Dimensions.Add(regMgDim);
var cubeDimKeyAttr = cubeDim.Dimension.KeyAttribute;
var mgAttr = regMgDim.Attributes.Add(cubeDimKeyAttr.ID);
mgAttr.Type = MeasureGroupAttributeType.Granularity;
But it gets created as a "Regular" type relationship.
I want it to end up like this (See relationship type):
Managed to figure it out.
The code should be,
var cubeDim = OlapCube.Dimensions.GetByName(dimensionName);
var regMgDim = new DegenerateMeasureGroupDimension(cubeDim.ID);
olapMeasureGroup.Dimensions.Add(regMgDim);
Although the name DegenerateMeasureGroupDimension is not obvious, it is the dimension to create fact dimension relationship.
I managed to create an own inline content element (on tt_content table) but when i try to get the values on the frontend via fluid, i get nothing.
I debugged the {data} variable and on the column that my data are saved, there is an integer. I suppose it reads the number of the content elements which were created on the foreign table (accordion). How can i get those values?
At this point the {data} variables reads the tt_content table and the column that has the integer reads the number of content elements on the table accordion.
I suppose no code is necessary. If it is necessary, feel free to comment the part of the code you would like to review.
Best regards
You need to add a DataProcessor to your TypoScript creating the content element, which fetch your accordion records. Example:
tt_content {
yourContentElementName < lib.contentElement
yourContentElementName.templateName = YourContentElementName
yourContentElementName.dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
if.isTrue.field = fieldInTtContentWithInteger
table = your_accordion_table
pidInList = this
where.field = uid
where.intval = 1
where.dataWrap = field_pointing_to_ttcontent_record = |
as = accordions
}
}
}
I'm writing a game in Elm and in this game there's a button that when pressed should reset the game board to its initial state. I don't understand however how a button click signal is to be propagated to the board model's update function. In the code below, I've just passed the unit value to stepBoard but I can't do much with it so how can I solve it?
--MODEL
type Board = [(Int,Int)]
type Game = {name: String, board: Board}
defaultGame = {name = "Test", board = [(3,3)]}
--UPDATE
stepBoard click (colsInit, rowsInit) (rows, cols) g =
{g | board <- if ? then --some initial value (colsInit, rowsInit)
else --some updated value using (rows, cols)}
stepGame: Input -> Game -> Game
stepGame {click, name, rowsColsInit, rowsCols} g = stepBoard click (0,0) (0,0) g
game = foldp stepGame defaultGame input
--INPUT
type Input = {click:(), name: String, rowsColsInit: (Int,Int), rowsCols: (Int,Int)}
input = Input <~ clicks ~ nameSignal ~ rowsColsInitSignal ~ rowsColsSignal
--VIEW
(btn, clicks) = Input.button "Click"
Combining foldp and click information can be unintuitive.
The usual solution employed is an ADT to encode the different possible events:
data Input = Init (Int, Int)
| Update { name : String
, rowsCols : ( Int, Int )
}
input = merge (Init <~ (sampleOn clicks rowsColsInitSignal))
(OtherInput <~ nameSignal ~ rowsColsSignal)
merge merges two signals and always creates a constant function.
Now you can just match by case in your update function:
stepBoard input g =
let newBoard =
case input of
Init (initRows, initCols) -> -- do your initialisation here
Update {name, rowsCols} -> -- do your update here
in { g | board <- newBoard }
I have a class like so:
classdef Vehicle < handle
%Vehicle
% Vehicle superclass
properties
Is_Active % Does the vehicle exist in the simualtion world?
Speed % [Km/Hour]
end
methods
function this = Vehicle(varargin)
this.Speed = varargin{1}; % The speed of the car
this.Is_Active = true;
end
end
end
I create my Vehicle-class objects in a cell form (don't ask me why - it's a laymen's workaround for global setting):
Vehicles{1} = Vehicle(100);
Vehicles{2} = Vehicle(200);
Vehicles{3} = Vehicle(50);
Vehicles{1}.Is_Active = true;
Vehicles{2}.Is_Active = true;
Vehicles{3}.Is_Active = true;
My questions:
1. Is there a way to set all three objects' active in a single command?
2. Is there a way to get all three objects' Speed in a single command?
3. Is there a way to query which vehicles are faster than X in a single command?
Thanks
Gabriel
For the members of the same class you can use round brackets (regular array):
Vehicles(1) = Vehicle(100);
Vehicles(2) = Vehicle(200);
Vehicles(3) = Vehicle(50);
To set all objects use deal:
[Vehicles(:).Is_Active] = deal( true );
You could also initialize an array of objects in the first place.
For your questions (2) and (3) the syntax is equivalent to those of MATLAB structures:
speedArray = [Vehicles.Speed];
fasterThanX = Vehicles( speedArray > X );
Such vectorization notation is a strong point of MATLAB and is used extensively.