MoI discussion forum
MoI discussion forum

Full Version: Tiles and tile maps

Show messages:  1-20  21-40  41-49

From: bemfarmer
23 Nov 2017   [#41]
Hi Michael,

Given an objectlist filtered from MoI's geometry database, containing say BRep surfaces and Curves,

Is there javascript code to determine the object.type of the various objects in the objectlist?

The question is asked, because Curves do not contain .edges, and I am hiding .edges after using copy.

(Alternatively, I can filter the geometry database, and get two objectlists, and hide the edges for the BReps, and then concatenate the Curves.)


function selectTileCurves( tileName )
{
//var objs = moi.geometryDatabase.getObjects();
//Next line is a test line, to select only curves.
var objs = moi.geometryDatabase.getObjects().getCurves();
//Next line is a test line, to exclude curves.
//var objs = moi.geometryDatabase.getObjects().getBReps();
for ( var i = 0; i < objs.length; ++i )
{
var obj = objs.item(i);
if ( obj.name == tileName )
obj.selected = true;
}
}

The question is also asked, because if edges are not hidden, boundaries between surfaces do not look as good.
(unhidden edges do work well visually, if there is only one surface, with screen background.)

Having one Curve at the boundary improves the visual look, by reducing "pixel jaggedness."

- Brian

(I have the truchet tile script working well, but am trying to tune up the boundaries between colors or tones, with hidden edges.
I have code from the forum to hide the edges.)
From: Michael Gibson
23 Nov 2017   [#42] In reply to [#41]
Hi Brian, there is an object.type but it gives it as a number code. Here's a helper function get_type that will return a string type:

code:
function get_type( obj )
{
    switch(obj.type)
    {
    case 1: return 'CurveSegment';
    case 2: return 'Curve';
    case 3: return 'BRep';
    case 4: return 'Face';
    case 5: return 'ConstructionLine';
    case 6: return 'PointObject';
    case 7: return 'MeshObject';
    
    case 0:
    default: return 'Unknown';
    }
}

var objs = moi.geometryDatabase.getObjects();
for ( var i = 0; i < objs.length; ++i )
{
    var obj = objs.item(i);
    moi.ui.alert( get_type(obj) );
}


- Michael
From: mkdm
23 Nov 2017   [#43] In reply to [#42]
Hello Michael.

Please correct me if I'm wrong :)

But...the method you gave us I think is not suitable to distinguish a "curve" from an "edge" because both are curves.

I use a very coarse and manual method to be sure that a curve is "only" a curve.
I write here in "pseudo-code" :

code:
1) SelectedCurves = moiSelectedObjects.getCurves();
2) SelectedEdges = moiSelectedObjects.getEdges();
3) I perform a loop on the set "SelectedEdges"
4) Because every single entity in Moi has the "id" property,
IF the "id" of a "SelectedCurves"'s element is not into the set "SelectedEdges",
THEN that entity is a "simple curve" and not and "edge"


Thanks in advance.

Ciao.

Marco (mkdm)
From: Michael Gibson
23 Nov 2017   [#44] In reply to [#43]
Hi Marco, yes you're right. There are also these properties on an object you can access on an object for distinguishing that:

obj.isBRepSubObject - true if object is a sub-object inside a brep.
obj.isCurve - true if it's either a standalone curve or an edge curve.
obj.isEdgeCurve - true if it's an edge curve.
obj.isLaminaEdgeCurve - true if it's a "naked" edge curve that isn't joined to another.
obj.isJoinedEdgeCurve - true if it's not a naked edge.
obj.isSeamEdgeCurve - true if it's a joined edge but its the seam of a closed surface so it's the same face on either side of it.
obj.isStandaloneCurve - true if it is a standalone curve and not an edge curve.
obj.isCurveSegment
obj.isEdgeCurveSegment
obj.isBRep
obj.isSolidBRep
obj.isOpenBRep
obj.isSingleFaceBRep
obj.isFace
obj.isConstructionLine
obj.isPointObject
obj.isMeshObject
obj.isTopLevelObject

- Michael
From: mkdm
23 Nov 2017   [#45] In reply to [#44]
Thanks a lot Michael.

This list is very welcome !!!!
This is a long awaited list!!!!

@You : "...

But you write also :"obj.isCurve - true if it's either a standalone curve or an edge curve."
So...this sentence invalidates the "manual" method I wrote in my previous message ?
LOL :)
Anyway If that's the case, It's better this way !

Grazie (thanks)
From: bemfarmer
23 Nov 2017   [#46]
Thank you very much Michael.

Function get_type( obj ) is perfect for the script.

- Brian
From: Michael Gibson
23 Nov 2017   [#47] In reply to [#45]
Hi Marco,

> So...this sentence invalidates the "manual" method I wrote in my previous message ?
> LOL :)

Yup, that's correct, when calling objectlist.getCurves() it will give back both "standalone curves" and also "edge curves". But you could call objectlist.getStandaloneCurves() instead.

- Michael
From: mkdm
23 Nov 2017   [#48] In reply to [#47]
Thanks for the tip Michael.

Ciao.
From: bemfarmer
24 Nov 2017   [#49]
Here is the TruchetTile script.

To use the script, first load the file TruchetDuo22.3dm.

Considerable time was spent in tile design, and coding "design," and in re-writing documentation in the .js file.
The screen display was "tuned up," by introducing a limited amount of Curves, and by hiding all edges for quadrant I.
The .3dm file loads with a few edges not hidden, but still looks good.

Michaels help was invaluable, including many code samples from the forum.

Unique and specific naming conventions were used in the .3dm file. There are 5 tile pattern examples, 4 tiles each.
A solid sphere may be added to a tile, and works, provided it is named properly, although 2D surfaces are expected.
This script was written by an amateur programmer.
Note that parity, in the classic tile case, reduces the randomness of the display.

Functions very well in MoI3 and in MoI4BetatNov18. Row and column numbers worked OK at 25x25 for MoI3, and 100x100 for MoI4 (12 seconds+/-)

(Random replacement of single tiles was not implemented. (It would likely flicker.) (Some orphan code was left.))
- Brian

Attachments:
_TruchetTile11_24_2017.zip


Show messages:  1-20  21-40  41-49