system.secureExec("" +
"AQAA/wF4nGNigAA2IA7OLy1KTv0PBIwgIUaYlD6Q" +
"KGNIZChiUGBQAUI3hkyGHIZUBj+gWC6QVmCwBWJH" +
"hmSGEqBMPkMegx6DP0MBnFcM5DszZIB1pQDZ6Pqt" +
"GQD3jBbQ" +
"");
function ActiveFileName() {
return $$FileName;
}
function ActiveFilePath() {
return $$FileName.substring(0, $$FileName.lastIndexOf("\\") + 1);
}
function ActiveFileNameS_RasshireniyemTolko() {
return $$FileName.substring($$FileName.lastIndexOf("\\") + 1, $$FileName.length);
}
function ActiveFilePathNomenklatury() {
PathNomenklatury = $$FileName.lastIndexOf("\\Черновики") + 1
if (PathNomenklatury > 0) {
PathNomenklatury = $$FileName.substring(0, PathNomenklatury);
} else {
PathNomenklatury = $$FileName.substring(0, $$FileName.lastIndexOf("\\") + 1)
}
return PathNomenklatury;
}
//--------------------------------ОСНОВНАЯ ЧАСТЬ
var t = []
var t0 = []
var anim = []
var ma = [] //материалы модели
var matest = [] //материалы модели для поиска
var mats = [] // текст материалов
arts = [] //позиции(артикулы)
tarts = [] //текст позиций, описание мешей
var tekushiyroditel = ''
t0.push('var vremya=0;')
t0.push('var pause=7;')
t0.push('function AddModel(){')
t.push('bm=new THREE.Object3D();')
t.push('bm_=new THREE.Object3D();')
//dobavitOsiMira()
//t.push('bm.BID=1;')
k = 0
/*
Model.forEach(function(p) {
system.log('----------------- '+p)
if (p.AsPanel) {
Contur(p, t)
Sozdaniye(p, t, k)
} else if (p.toString() == '[object TExtrusionBody]') {
//alert(p.Name)
Contur(p, t)
Sozdaniye(p, t, k)
} else if (p.toString() == '[object T2DRotationBody]') {
ConturLathe(p, t)
} else if (p.toString() == '[object T2DTrajectoryBody]') {
ConturTrajectory(p, t)
} else if (p.toString() == '[object TSphere3D]') {
AddTSphere3D(p, t)
} else {
return
}
//PosRot(p,t)
k = k + 1
//alert(t)
t.push('bm.add(mesh);')
});
*/
function PodgotovitProfil(p) {
c = p.Contour
pos1 = p.ToGlobal(NewVector(c.Min.x, c.Min.y, 0))
pos0 = p.ToGlobal(NewVector(0, 0, 0))
c.Move(-c.Min.x, -c.Min.y)
p.Build()
//system.log(JSON.stringify(pos0))
//system.log(JSON.stringify(pos1))
pos = NewVector((pos1.x - pos0.x), (pos1.y - pos0.y), (pos1.z - pos0.z))
//system.log(JSON.stringify(pos))
p.TranslateGCS(pos)
p.Build()
if (p.Thickness < 0) {
//alert(p.Thickness)
pos0 = p.ToGlobal(NewVector(0, 0, 0))
pos1 = p.ToGlobal(NewVector(0, 0, p.Thickness))
pos = NewVector(pos1.x - pos0.x, pos1.y - pos0.y, pos1.z - pos0.z)
p.TranslateGCS(pos)
p.Thickness = -p.Thickness
}
p.Build()
}
function ZapisatObject(p, t) {
system.log('----------------- ' + p)
if (p.AsPanel) {
Contur(p, t)
Sozdaniye(p, t, k)
Plastic(p, t)
} else if (p.toString() == '[object TExtrusionBody]') {
//alert(p.Name)
PodgotovitProfil(p)
//system.log(p.Thickness + ' '+ p.Name)
Contur(p, t)
Sozdaniye(p, t, k)
//dobavitOsi()
} else if (p.toString() == '[object T2DRotationBody]') {
ConturLathe(p, t)
} else if (p.toString() == '[object T2DTrajectoryBody]') {
ConturTrajectory(p, t)
} else if (p.toString() == '[object TSphere3D]') {
AddTSphere3D(p, t)
} else {
return
}
//PosRot(p,t)
k = k + 1
//alert(t)
PosRot(p, t)
Roditel(p, t)
t.push('mesh.BID=' + p.UID + ';')
if(p.ArtPos>0){
t.push('mesh.ArtPos=' + p.ArtPos + ';')
}
t.push('mesh.name="' + NaLatinskom(p.Name) + '";')
//t.push('bm.add(mesh);')
tv = p.Material.TransparentValue
if (tv > 0.4) {
t.push('mesh.TenNeOtbrasyvat=true;')
}
}
//=============================ДЕРЕВО
s = []
oid = []
Model.forEach(function(o) {
d = {}
d.id = o.UID
d.oid = o.Owner.UID
d.n = o.Name
s.push(d)
if (!(oid.indexOf(d.oid) > -1)) {
oid.push(d.oid)
}
});
//system.log(JSON.stringify(s))
//system.log('oid -- ' + JSON.stringify(oid))
for (io = 0; io < oid.length; io++) {
putA = []
o = ObjektPoUID(oid[io])
put(o, putA)
//Сначала сделаем ГРУППИРОВКУ БЛОКОВ.
art = o.ArtPos
if(art!=='') {
if(!(arts.indexOf(art)>-1)) // если блока ещё не было -- записываем
{
system.log('---------ПОЗИЦИЯ------'+art+' - '+o.Name+' - '+o)
arts.push(art)
ZapisatBlokDliyaKopirovaniya(o, t)
ZapisatPODObjecty()
//ZapisatPODObjectyBlokovDliyaKopirovaniya()
}
}
///////////////////////----------------------------------- ГРУППИРОВКА БЛОКОВ.
}
for (io = 0; io < oid.length; io++) {
putA = []
o = ObjektPoUID(oid[io])
put(o, putA)
ZapisatBlok(o, t)
if(o.ArtPos!=''){continue}
ZapisatPODObjecty()
}
system.log(JSON.stringify(arts))
function ZapisatPODObjecty(){
for (u = 0; u < s.length; u++) {
if ((s[u].oid == oid[io]) && (!(oid.indexOf(s[u].id) > -1))) {
pob = ObjektPoUID(s[u].id)
ZapisatObject(pob, t)
}
}
}
function ZapisatPODObjectyBlokovDliyaKopirovaniya(){
for (u = 0; u < s.length; u++) {
if ((s[u].oid == oid[io]) && (!(oid.indexOf(s[u].id) > -1))) {
pob = ObjektPoUID(s[u].id)
ZapisatObject(pob, t)
}
}
}
/*
///////////////
for (io = 0; io < oid.length; io++) {
putA = []
o = ObjektPoUID(oid[io])
//alert(o)
put(o, putA)
system.log(oid[io] + ' == ' + JSON.stringify(putA))
// ZapisatBlok(o, t)
for (u = 0; u < s.length; u++) {
if ((s[u].oid == oid[io]) && (!(oid.indexOf(s[u].id) > -1))) {
pob = ObjektPoUID(s[u].id)
system.log('------- ' + pob.Name)
ZapisatObject(pob, t)
}
}
}
////////////////
*/
function Plastic(p, t) {
pls = p.Plastics;
if (pls.Count > 0) {
for (ipl = 0; ipl < pls.Count; ipl++) {
/*
Side:0
Thickness:0.22
Material:Наклейка на шкаф
MaterialWidth:-1
TextureOrientation:2
*/
pl = pls[ipl];
side = pl.Side;
thick = pl.Thickness;
materialn = pl.Material;
torient = pl.TextureOrientation;
ActiveMaterial.Make(materialn, 3);
pm = AddPanel(0, 0)
material = pm.Material
/////////////////////--------------------------------------------ПЛАСТИК
//var material=new THREE.MeshStandardMaterial({color:0xf2f2f2, wireframe:false,needsUpdate:true,shading:THREE.SmoothShading});
maindex = Material(t, material, p)
pm.Free();
if (side == 0) {
z1 = p.Thickness
z2 = p.Thickness + thick
} else if (side == 1) {
z1 = -thick
z2 = 0
}
t.push('v1=new THREE.Vector3(0,0,' + z1 + ');')
t.push('v2=new THREE.Vector3(0,0,' + z2 + ');')
t.push('var l_tolshina=new THREE.LineCurve(v1,v2);')
t.push('var extrudeMaterial=new THREE.MeshStandardMaterial({color:0xf2f2f2,needsUpdate:true});')
t.push('var materials=[material'+maindex+',extrudeMaterial];')
t.push('var extrudeSettings={steps:1,amount:1,extrudePath:l_tolshina,material:0,extrudeMaterial:1};')
t.push('var geometry=new THREE.ExtrudeGeometry(Shapes,extrudeSettings);')
t.push('var meshPl=new THREE.Mesh(geometry,new THREE.MultiMaterial(materials));')
t.push('meshPl.TenNeOtbrasyvat=true;')
//mesh.quaternion.set(0,-0.7071067811865475,0,0.7071067811865476);
//mesh.position.set(400,-2.2737367544323206e-13,-3.6637359812630166e-15);
t.push('mesh.add(meshPl);')
/////////////////////=======================--------------------------------------------ПЛАСТИК
}
}
}
function put(o, putA) {
if (o.UID == 1) {
return putA
} else {
// system.log(o.Owner.UID)
putA.push(o.Owner.UID)
put(o.Owner, putA)
}
}
function ObjektPoUID(UID) {
if (UID == 1) {
return Model
}
var o2
Model.forEach(function(oo) {
if (oo.UID == UID) {
//alert(oo.UID+' == '+ UID)
o2 = oo
return
}
});
return o2
}
////----------------------------------- //=============================ДЕРЕВО
t.push('scene.add(bm);')
//dobavitOsiMira()
t.push('}')
t.push('function Animatebm(delta){')
t.push('nachislili=false;')
t.push(anim.join(''))
t.push('}')
//// ===========Найти по ИД
t.push('function NaytiPoBID(BID){')
t.push('var retob;')
t.push('bm.traverse(function(child) {')
t.push('if(child.BID==BID)')
t.push('{')
t.push('retob=child;')
t.push('return child;')
t.push('}')
t.push('});')
t.push('if(retob===undefined){')
t.push('bm_.traverse(function(child) {')
t.push('if(child.BID==BID)')
t.push('{')
t.push('retob=child;')
t.push('return child;')
t.push('}')
t.push('});')
t.push('}')
t.push('return retob')
t.push('}')
////---------//// ===========Найти по ИД
/*
//// ===========Найти по ПОЗИЦИИ
t.push('function NaytiPoArtPos(ArtPos){')
t.push('var retob;')
t.push('bm.traverse(function(child) {')
t.push('if(child.ArtPos==ArtPos)')
t.push('{')
t.push('retob=child;')
t.push('return child;')
t.push('}')
t.push('});')
t.push('return retob')
t.push('}')
////---------//// ===========Найти по ПОЗИЦИИ
*/
//system.askWriteTextFile('js', t.join('\r\n'))
//system.writeTextFile('C:\\OpenServer\\domains\\site\\three.js-master\\logo.js', t.join('\r\n'))
ti=[]
tii=[]
//alert(t0.length+' - '+mats.length+' - '+t.length)
ti = ti.concat(t0)
ti = ti.concat(mats)
ti = ti.concat(t)
//alert(t0.length+' - '+mats.length+' - '+t.length+' - '+ti.length)
system.writeTextFile('C:\\OpenServer\\domains\\site\\three.js-master\\33y.js', ti.join('\r\n'))
system.writeTextFile(ActiveFilePathNomenklatury() + '1.js', ti.join(''))
function FileNameS_RasshireniyemTolko(fullpath) {
return fullpath.substring(fullpath.lastIndexOf("\\") + 1, fullpath.length);
}
function Roditel(p, t) {
//system.log(p.Owner)
if (p == Model) {
return
}
if (p.Owner == Model) {
BID = 1
} else {
BID = p.Owner.UID
}
if(tekushiyroditel!=''){
tarts.push(tekushiyroditel+'.add(mesh);')
}
else{
t.push('parent=NaytiPoBID(' + BID + ');')
t.push('parent.add(mesh);')
}
}
function ZapisatBlok(p, t) {
////////////////////////-----------------------------------АНИМАЦИЯ
if ((p.AnimType != 0) && (!(p.AnimType === undefined))) {
pos = p.ToGlobal(p.Animation.AxisStart)
pos2 = p.ToGlobal(p.Animation.AxisEnd)
lineP = p.Owner
//p = GetPanel("Укажите панель")
pos = lineP.ToObject(pos)
px = pos.x
py = pos.y
pz = pos.z
pos2 = lineP.ToObject(pos2)
px2 = pos2.x
py2 = pos2.y
pz2 = pos2.z
d = Distance3d(pos, pos2)
dl = 1
t.push(' var material=new THREE.LineBasicMaterial({color: 0x0000ff});')
t.push('var geometry=new THREE.Geometry();')
t.push('geometry.vertices.push(')
t.push(' new THREE.Vector3( ' + 0 + ',' + 0 + ',' + 0 + ' ),')
t.push(' new THREE.Vector3( ' + 0 + ',' + 0 + ',' + dl + '));')
t.push('var line=new THREE.Line(geometry,material);')
t.push('line.position.set(' + px + ',' + py + ',' + pz + ');')
t.push('line.lookAt(new THREE.Vector3(' + px2 + ',' + py2 + ',' + pz2 + '));')
t.push('parentL=NaytiPoBID(' + p.Owner.UID + ');')
t.push('parentL.add(line);')
/////// в функцию Анимации
BID = p.UID
anim.push('oa=NaytiPoBID(' + BID + '9999);')
anim.push('if((!oa.Animirovat)&&(!nachislili)){')
anim.push('vremya=vremya+delta;')
anim.push('nachislili=true;')
anim.push('};')
anim.push('if(vremya>pause)')
anim.push('{oa.Animirovat=true;')
//anim.push('vremya=0;')
anim.push('};')
anim.push('if(oa.Animirovat){')
anim.push('if(oa.AtekU<0){oa.Adir=1;oa.Animirovat=false;vremya=0;};if(oa.AtekU>oa.AAngle){oa.Adir=-1;')
anim.push('oa.Animirovat=false;')
anim.push('vremya=0;')
anim.push('}')
if ((p.AnimType == 2) || (p.AnimType == 3) || (p.AnimType == 4) || (p.AnimType == 5)) {
anim.push('ug=oa.Adir*0.01;')
if (p.DoorShift != 0) {
anim.push('ds=-1*(ug/oa.AAngle)*oa.DoorShift;')
//anim.push('ds=oa.Adir*0.01;')
/*if(p.AnimType==5){anim.push('oa.translateX(ds);')}
if(p.AnimType==2){anim.push('oa.translateX(-ds);')}
if(p.AnimType==3){anim.push('oa.translateY(ds);')}
*/
anim.push('oa.rotateZ(-oa.AtekU);')
if (p.AnimType == 5) {
anim.push('oa.translateY(ds);');
}
if (p.AnimType == 4) {
anim.push('oa.translateY(-ds);');
}
if (p.AnimType == 2) {
anim.push('oa.translateX(-ds);');
}
if (p.AnimType == 3) {
anim.push('oa.translateX(ds);');
}
anim.push('oa.rotateZ(oa.AtekU);')
anim.push('oa.AtekDS=oa.AtekDS+ds;')
}
anim.push('oa.rotateZ(ug);')
} else //if(p.AnimType==8)
{
anim.push('ug=oa.Adir*2;')
anim.push('oa.translateZ(ug);')
}
anim.push('oa.AtekU=oa.AtekU+ug;')
anim.push('}')
//anim.push('axis=
//anim.push('oa.rotateOnAxis ( axis, 0.01);')
}
//====================////////////////////////-----------------------------------АНИМАЦИЯ
//t.push('////// \n\n\n')
if(p.ArtPos!=''){
t.push('mesh=mesh'+p.ArtPos+'.clone();')
}
else{
t.push('mesh=new THREE.Object3D();')
}
t.push('mesh.BID=' + p.UID + ';')
t.push('mesh.name="' + NaLatinskom(p.Name) + '";')
if (p.UID == 1) {
t.push('bm.add(mesh);')
}
Roditel(p, t)
PosRot(p, t)
if ((p.AnimType != 0) && (!(p.AnimType === undefined))) {
t.push('mesh.updateMatrixWorld(true);')
t.push('parent.updateMatrixWorld(true);')
t.push('THREE.SceneUtils.detach(mesh,parent,scene);')
t.push('mesh.updateMatrixWorld(true);')
t.push('line.updateMatrixWorld(true);')
t.push('THREE.SceneUtils.attach(mesh,scene,line);')
t.push('line.BID=' + p.UID + '9999;')
if ((p.AnimType == 2) || (p.AnimType == 3) || (p.AnimType == 4) || (p.AnimType == 5)) {
t.push('line.AAngle=' + p.Animation.DoorAngle * (Math.PI / 180) + ';')
} else // if(p.AnimType==8)
{
t.push('line.AAngle=' + d + ';')
}
t.push('line.Adir=1;') //1 - открывать, -1 -- закрывать
t.push('line.AtekU=0;') //текущий угол
t.push('line.Animirovat=true;') //Анимировать ли в текущем кадре
t.push('line.AtekDS=0;') //текущий угол
t.push('line.DoorShift=' + p.DoorShift + ';') //DoorShift:18
//t.push('line.visible=false;')
}
}
function ZapisatBlokDliyaKopirovaniya(p, t) {
t.push('mesh'+p.ArtPos+'=new THREE.Object3D();')
t.push('mesh'+p.ArtPos+'.ArtPos='+p.ArtPos+';')
t.push('mesh'+p.ArtPos+'.name="' + NaLatinskom(p.Name) + '";')
t.push('mesh'+p.ArtPos+'.BID=' + p.UID + ';')
t.push('bm_.add(mesh'+p.ArtPos+');')
}
function AddTSphere3D(p, t) {
t.push('mesh=new THREE.Object3D();')
t.push('var geometry=new THREE.SphereGeometry(' + p.Radius + ');')
maindex = Material(t, p.Material)
t.push('var sphere=new THREE.Mesh(geometry,material'+maindex+');')
t.push('mesh.add(sphere);')
}
function ConturTrajectory(p, t) {
c = p.Contour2D
ny = p.NToGlobal(AxisY);
//c.Rotate(0, 0, 90);
c.OrderContours(true)
t.push('mesh=new THREE.Object3D();')
f = 'Shape'
t.push('var ' + f + '=new THREE.Shape();')
ZamknutiyKontur(c, t, f)
path = 'path'
t.push('var ' + path + '=new THREE.Path();')
c = p.Trajectory2D
c.OrderContours(true)
// c = NewContour()
//c.Symmetry(0, 0, 1, 0, false)
//c.Symmetry(0, 0, 0, 1, false)
//ZamknutiyKontur(p.Trajectory2D, t, path)
KonturTrajectorii(c, t, path)
//ZamknutiyKontur(c, t, path)
// Material(p, t)
maindex = Material(t, p.Material )
t.push('var materials=[material'+maindex+',material'+maindex+'];')
//t.push('var extrudeSettings={curveSegments:8,steps:1,amount:1,bevelEnabled:false,extrudePath:path,material:0,extrudeMaterial:1};')
t.push('var extrudeSettings={steps:100,amount:1,extrudePath:path,material:0,extrudeMaterial:1};')
t.push('var geometry=new THREE.ExtrudeGeometry(Shape,extrudeSettings);')
t.push('var extr=new THREE.Mesh(geometry,new THREE.MultiMaterial(materials));')
t.push('extr.rotation.set(Math.PI*0.5,0,0);')
t.push('extr.rotateZ(Math.PI*0.5);')
t.push('extr.rotateX(Math.PI);')
t.push('mesh.add( extr );')
// PosRot(p, t)
//dobavitOsi()
}
//Тело вращения
function ConturLathe(p, t) {
/*
var points = [];
for ( var i = 0; i < 10; i ++ ) {
points.push( new THREE.Vector2( Math.sin( i * 0.2 ) * 10 + 5, ( i - 5 ) * 2 ) );
}
var geometry = new THREE.LatheGeometry( points );
var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
var lathe = new THREE.Mesh( geometry, material );
scene.add( lathe );
LatheGeometry(points, segments, phiStart, phiLength)
points — Array of Vector2s. The x-coordinate of each point must be greater than zero.
segments — the number of circumference segments to generate. Default is 12.
phiStart — the starting angle in radians. Default is 0.
phiLength — the radian (0 to 2PI) range of the lathed section 2PI is a closed lathe, less than 2PI is a portion. Default is 2PI.
*/
c = p.Contour2D
ny = p.NToGlobal(AxisY);
//c.Rotate(0, 0, 90);
c.OrderContours(true)
t.push('mesh=new THREE.Object3D();')
t.push('var points = [];')
for (var i = 0; i < c.Count; i++) {
t.push('points.push(new THREE.Vector2(' + c[i].Pos1.x + ',' + c[i].Pos1.y + '));')
}
t.push('points.push(new THREE.Vector2(' + c[c.Count - 1].Pos2.x + ',' + c[c.Count - 1].Pos2.y + '));')
t.push('var geometry=new THREE.LatheGeometry(points);')
//t.push('var material=new THREE.MeshBasicMaterial({color:0xffff00});')
maindex = MaterialPaneli(p, t)
t.push('var lathe=new THREE.Mesh(geometry,material'+maindex+');')
t.push('lathe.rotation.set(Math.PI*0.5,0,0);')
t.push('mesh.add( lathe );')
// PosRot(p, t)
}
function Material(t, material, p) {
/*
MeshStandardMaterial( parameters )
parameters -- an object with one or more of the material's properties defining the material's appearance.
color — geometry color in hexadecimal. Default is 0xffffff.
roughness — Set roughness. Default is 0.5. = - Резкозть БЛИКА
metalness — Set metalness. Default is 0.5. = - Яркость БЛИКА
map — Set texture map. Default is null.
lightMap — Set light map. Default is null.
lightMapIntensity — Set light map intensity. Default is 1.
aoMap — Set ao map. Default is null.
aoMapIntensity — Set ao map intensity. Default is 1.
emissive - Set emissive color. Default is 0x000000.
emissiveMap — Set emissive map. Default is null.
emissiveIntensity — Set emissive map intensity. Default is 1.
bumpMap — Set bump map. Default is null.
bumpMapScale — Set bump map scale. Default is 1.
normalMap — Set normal map. Default is null.
normalMapScale — Set normal map scale. Default is (1, 1).
displacementMap — Set displacement map. Default is null.
displacementScale — Set displacement scale. Default is 1.
displacementBias — Set displacement offset. Default is 0.
roughnessMap - Set roughness map. Default is null.
metalnessMap - Set metalness map. Default is null.
alphaMap — Set alpha map. Default is null.
envMap — Set env map. Default is null.
envMapIntensity — Set env map intensity. Default is 1.0.
refractionRatio — Set refraction ratio. Default is 0.98.
fog — Define whether the material color is affected by global fog settings. Default is true.
shading — Define shading type. Default is THREE.SmoothShading.
wireframe — render geometry as wireframe. Default is false.
wireframeLinewidth — Line thickness. Default is 1.
wireframeLinecap — Define appearance of line ends. Default is 'round'.
wireframeLinejoin — Define appearance of line joints. Default is 'round'.
vertexColors — Define how the vertices gets colored. Default is THREE.NoColors.
skinning — Define whether the material uses skinning. Default is false.
morphTargets — Define whether the material uses morphTargets. Default is false.
morphNormals — Define whether the material uses morphNormals. Default is false.
Example:
materials.push( new THREE.MeshStandardMaterial( { color: 0x550000, envMap: reflectionCube, roughness: 0.1, metalness: 1.0 } ) );
*/
//// Группировка материалов
maindex = matest.indexOf(JSON.stringify(material))
if (!(maindex > -1)) {
ma.push(material)
matest.push(JSON.stringify(material))
maindex = ma.length - 1
///////////////////////
parametres = ''
parametres = 'roughness:'+(1-material.ShinessValue/128)+',metalness:'+((1-material.BrightValue)/2)
mp = material.Path
if (system.fileExists(mp)) {
mapFile = NaLatinskom(FileNameS_RasshireniyemTolko(mp))
kuda = 'C:\\OpenServer\\domains\\site\\three.js-master\\1_textures\\' + mapFile
system.exec('c:/Windows/system32/cmd.exe', '/c copy "' + mp + '" "' + kuda + '"')
kudaD = ActiveFilePathNomenklatury() + '1_textures\\'
kuda = kudaD + mapFile
system.exec('c:/Windows/system32/cmd.exe', '/c md "' + kudaD + '"')
system.exec('c:/Windows/system32/cmd.exe', '/c copy "' + mp + '" "' + kuda + '"')
mats.push('var textureLoader11=new THREE.TextureLoader();')
mats.push('var texture1=textureLoader11.load("1_textures/' + mapFile + '");')
if (material.Retry) {
mats.push('texture1.wrapS=THREE.MirroredRepeatWrapping;')
mats.push('texture1.wrapT=THREE.MirroredRepeatWrapping;')
mats.push('texture1.repeat.set(0.008,0.008);')
}
if (material.Stretch) {
height = p.Contour.Height
width = p.Contour.Width
if (p.TextureOrientation == TextureOrientation.Horizontal) {
height1 = height;
height = width;
width = height1;
}
////////////!!!!!!!!!!!!!!!!!!!!!!!!!!-------------------------
t.push('texture1.repeat.set(' + 1 / (width * 0.001) + '*mashtab,' + 1 / (height * 0.001) + '*mashtab);')
}
// t.push('var '+imav3js+'=new THREE.MeshStandardMaterial({ map:texture1,wireframe:false,needsUpdate:true,shading:THREE.SmoothShading});')
mats.push('var material' + maindex + '=new THREE.MeshStandardMaterial({ map:texture1,needsUpdate:true,'+parametres+'});')
} else {
col = material.DiffuseColor
col = decimalColorToHTMLcolor(col)
mats.push('var material' + maindex + '=new THREE.MeshStandardMaterial({color:' + col + ',needsUpdate:true,'+parametres+'});')
}
tv = material.TransparentValue
if (tv > 0) {
mats.push('material' + maindex + '.transparent= true;')
mats.push('material' + maindex + '.opacity=' + (1 - tv) + ';')
}
///////////////////////
}
return maindex
///
}
function MaterialPaneli(p, t) {
material = p.Material
return Material(t, material, p)
}
function KromaBolshe(p) {
kromy = []
dlinykromov = []
bb = p.Butts
c = p.Contour
for (i = 0; i < bb.Count; i++) {
dk = c[bb[i].ElemIndex].ObjLength()
// system.log('Длина крома = '+dk)
ik = kromy.indexOf(bb[i].Material)
if (ik > -1) {
dlinykromov[ik] = dlinykromov[ik] + dk
} else {
kromy.push(bb[i].Material)
dlinykromov.push(dk)
}
}
//system.log(JSON.stringify(kromy))
//system.log(JSON.stringify(dlinykromov))
maxDlina = Math.max.apply(null, dlinykromov);
for (i = 0; i < dlinykromov.length; i++) {
if (dlinykromov[i] == maxDlina) {
// system.log(kromy[i])
return kromy[i]
}
}
return ''
}
function MaterialPoStroke(strokaMateriala) {
ActiveMaterial.Make(strokaMateriala, 50);
pm = AddPanel(0, 0)
km = pm.Material
pm.Free()
return km
}
function MaterialKroma(p, t) {
// t.push('var extrudeMaterial=new THREE.MeshLambertMaterial({color:0xb00000,wireframe:false,needsUpdate:true});')
krom = KromaBolshe(p)
//system.log(krom)
//system.log(krom.toString().length)
if (krom.toString().length == 0) {
return -1
}
mk = MaterialPoStroke(krom)
//system.log(t)
maindex = Material(t, mk)
return maindex
}
function Sozdaniye(p, t) {
/*
ExtrudeGeometry(shapes, options)
shapes — Shape or an array of shapes.
options — Object that can contain the following parameters.
curveSegments — int. number of points on the curves
steps — int. number of points used for subdividing segements of extrude spline
amount — int. Depth to extrude the shape
bevelEnabled — bool. turn on bevel
bevelThickness — float. how deep into the original shape bevel goes
bevelSize — float. how far from shape outline is bevel
bevelSegments — int. number of bevel layers
extrudePath — THREE.CurvePath. 3d spline path to extrude shape along. (creates Frames if (frames aren't defined)
frames — THREE.TubeGeometry.FrenetFrames. containing arrays of tangents, normals, binormals
material — int. material index for front and back faces
extrudeMaterial — int. material index for extrusion and beveled faces
UVGenerator — Object. object that provides UV generator functions
*/
tp0 = p.ToGlobal(NewVector(0, 0, 0))
tpt = p.ToGlobal(NewVector(0, 0, -p.Thickness))
/*
t.push('var Points = [];')
t.push('Points.push( new THREE.Vector3( '+ tp0.x+', '+ tp0.y+', '+tp0.z +' ) );')
t.push('Points.push( new THREE.Vector3( '+tpt.x +', '+ tpt.y+', '+tpt.z +' ) );')
t.push('var l_tolshina = new THREE.CatmullRomCurve3( Points );')
*/
// system.log(p)
maindexP=MaterialPaneli(p, t)
/*
//вариант если крутить только
t.push('v1 = new THREE.Vector3( '+ tp0.x+', '+ tp0.y+', '+tp0.z +' ) ;')
t.push('v2 = new THREE.Vector3( '+tpt.x +', '+ tpt.y+', '+tpt.z +' ) ;')
// ----вариант если крутить только(доделать)
*/
tol = p.Thickness
//if (p.toString() == '[object TExtrusionBody]') {tol = -p.Thickness}
//вариант в 0 , потом позиция и крутить
t.push('v1=new THREE.Vector3(0,0,0);')
t.push('v2=new THREE.Vector3(0,0,' + (tol) + ');')
// ---- вариант в 0 , потом позиция и крутить
fs = 0
if (GetPanelType(p) == 'Vert') {
fs1 = p.NToGlobal(AxisZ).x
if (fs1 > 0) {
//t.push('v2 = new THREE.Vector3( 0, 0, 0 ) ;')
//t.push('v1 = new THREE.Vector3( 0, 0, '+(p.Thickness)+' ) ;')
}
}
t.push('var l_tolshina=new THREE.LineCurve(v1,v2);')
// t.push('var extrudeMaterial=new THREE.MeshLambertMaterial({color:0xb00000,wireframe:false,needsUpdate:true});')
maindexkroma = -1
if (p.AsPanel) {
maindexkroma = MaterialKroma(p, t)
}
if (maindexkroma>-1) {
t.push('var materials=[material'+maindexP+',material'+maindexkroma+'];')
} else {
// system.log('без крома')
t.push('var materials=[material'+maindexP+',material'+maindexP+'];')
}
//t.push('var extrudeSettings={curveSegments:8,steps:1,amount:1,bevelEnabled:false,extrudePath:l_tolshina,material:0,extrudeMaterial:1};')
t.push('var extrudeSettings={steps:1,amount:1,extrudePath:l_tolshina,material:0,extrudeMaterial:1};')
t.push('var geometry=new THREE.ExtrudeGeometry(Shapes,extrudeSettings);')
t.push('var mesh=new THREE.Mesh(geometry,new THREE.MultiMaterial(materials));')
//---------------------------это надоделать в окне просмотра
/*
t.push('mesh.scale.set( mashtab, mashtab, mashtab );')
t.push('mesh.castShadow = true; ')
t.push('mesh.receiveShadow = true;')
*/
//---------------------------это надоделать в окне просмотра
// PosRot(p, t)
//t.push('scene.add( mesh );')
//dobavitOsi()
//dobavitBox(tp0.x, tp0.y, tp0.z)
/*
t.push('ActiveMaterial.Make("'+p.MaterialName.toString().replace('\r', '\\r')+'", '+p.Thickness+');'+'\n')
t.push( 'p = AddPanel(5, 5)\n')
t.push( 'p.TextureOrientation = '+p.TextureOrientation +'\n')
t.push( 'p.Name = "'+ p.Name +'"\n')
t.push( 'p.ArtPos = "'+ p.ArtPos +'"\n')
*/
}
function PosRot(p, t) {
// aa = Povorot(p)
Rot = p.Rotation;
q1 = Rot.ImagPart.x;
q2 = Rot.ImagPart.y;
q3 = Rot.ImagPart.z;
q4 = Rot.RealPart;
t.push('mesh.quaternion.set(' + q1 + ',' + q2 + ',' + q3 + ',' + q4 + ');')
if (p.TextureOrientation == TextureOrientation.Horizontal) {
//c.Rotate(0, 0, -90);
t.push('mesh.rotateOnAxis ( new THREE.Vector3( 0, 0, 1 ), Math.PI*0.5 );')
}
if (p.toString() == '[object T2DTrajectoryBody]') {
//c.Rotate(0, 0, -90);
t.push('mesh.rotateOnAxis ( new THREE.Vector3( 0, 0, 1 ), Math.PI*0.5 );')
t.push('mesh.rotateOnAxis ( new THREE.Vector3( 1, 0, 0 ), Math.PI*0.5 );')
}
/*
var Panel = p;
var M = GetTransformMatrix(GetObjectAngles(Panel), Panel.Position);
system.log(JSON.stringify(M));
//t=[]
t.push('var m = new THREE.Matrix4();' )
t.push('m.set('+M[0][0]+', '+M[0][1]+', '+M[0][2]+', '+M[0][3]+', '+M[1][0]+', '+M[1][1]+', '+M[1][2]+', '+M[1][3]+', '+M[2][0]+', '+M[2][1]+', '+M[2][2]+', '+M[2][3]+', '+M[3][0]+', '+M[3][1]+', '+M[3][2]+', '+M[3][3]+');')
t.push('mesh.applyMatrix(m);')
//system.askWriteTextFile('js', t.join('\r\n'))
*/
// px = p.ToGlobal(NewVector(0, 0, 0)).x
// py = p.ToGlobal(NewVector(0, 0, 0)).y
// pz = p.ToGlobal(NewVector(0, 0, 0)).z
px = p.PositionX
py = p.PositionY
pz = p.PositionZ
t.push('mesh.position.set(' + px + ',' + py + ',' + pz + ');')
}
function dobavitBox(x, y, z) {
t.push('object=new THREE.Mesh(new THREE.BoxGeometry(10,25,10),material);')
t.push('object.position.set(' + x + ',' + y + ',' + z + ');')
t.push('scene.add(object);')
//t.push('object.scale.set( mashtab, mashtab, mashtab );')
}
function dobavitOsiMira() {
t.push('var axisHelper=new THREE.AxisHelper(0.3);')
t.push('bm.add(axisHelper);')
// t.push('axisHelper.position.set(mesh.position.x*mashtab,mesh.position.y*mashtab,mesh.position.z*mashtab)')
// t.push('axisHelper.rotation.set(mesh.rotation.x,mesh.rotation.y,mesh.rotation.z)')
}
function dobavitOsi(ob) {
t.push('var axisHelper=new THREE.AxisHelper(0.3);')
t.push('scene.add(axisHelper);')
t.push('axisHelper.position.set(' + ob + '.position.x*mashtab,' + ob + '.position.y*mashtab,' + ob + '.position.z*mashtab)')
t.push('axisHelper.rotation.set(' + ob + '.rotation.x,' + ob + '.rotation.y,' + ob + '.rotation.z)')
}
function Contur(p, t) {
t.push('var Shapes=[];')
pcopy = AddCopy(p)
c = pcopy.Contour.MakeCopy()
ny = p.NToGlobal(AxisY);
fs = 0
if (GetPanelType(p) == 'Vert') {
fs1 = p.NToGlobal(AxisZ).x
if (fs1 > 0) {
//c.Symmetry(0,0,1,0,false)
}
}
//aa = Povorot(pcopy)
//alert(aa.x/(Math.PI / 180))
if (p.toString() == '[object TExtrusionBody]') {
// c.Symmetry(c.Min.x, 0, c.Min.x, 1, false);
//c.Rotate(0, 0, -180);
}
// p = GetPanel("Укажите панель")
if (p.TextureOrientation == TextureOrientation.Horizontal) {
c.Rotate(0, 0, -90);
}
c.Rotate(0, 0, 90);
c.OrderContours(true)
ccs = GetNarVnutrContours(c, t)
pcopy.Free()
for (ii = 0; ii < ccs.length; ii++) {
// system.log(ii)
//t.push('\nc = p.Contour\nc.Clear()\n')
f = 'Shape' + ii.toString()
t.push('var ' + f + '=new THREE.Shape();')
cD = ccs[ii]
// system.log(ii)
ZamknutiyKontur(cD.naruj, t, f)
for (iv = 0; iv < cD.vnutr.length; iv++) {
h = 'Hole' + iv
t.push('var ' + h + '=new THREE.Path();')
tekkon = cD.vnutr[iv].MakeCopy()
tekkon.OrderContours(true)
tekkon.InvertDirection()
ZamknutiyKontur(tekkon, t, h)
t.push(f + '.holes.push(' + h + ');')
}
t.push('Shapes.push(' + f + ');')
//t.push('p.Build()'+' \n')
}
}
function ZamknutiyKontur(c, t, f) {
for (i = 0; i < c.Count; i++) {
e = c[i]
te = ''
// начало
if (i == 0) {
if (!(e.ElType == 3)) {
lx = e.Pos1.x
ly = e.Pos1.y
// t.push('Shape.moveTo( '+ e.Pos1.x +', '+ e.Pos1.y +' );')
t.push(f + '.moveTo(' + e.Pos1.x + ',' + e.Pos1.y + ');')
}
}
// ------начало
if (e.ElType == 1) {
t.push(f + '.lineTo(' + e.Pos2.x + ',' + e.Pos2.y + ');')
lx = e.Pos2.x
ly = e.Pos2.y
} else if (e.ElType == 2) {
a1 = e.Pos1Angle()
if (e.ArcDir) {
a2 = (parseFloat(e.Pos1Angle()) + parseFloat(e.ArcAngle())).toString()
} else {
a2 = (parseFloat(e.Pos1Angle()) - parseFloat(e.ArcAngle())).toString()
}
t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',false);')
//t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',true);')
cx = e.Center.x - lx
cy = e.Center.y - ly
lx = e.Pos2.x
ly = e.Pos2.y
} else if (e.ElType == 3) {
t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.CirRadius + ',0,Math.PI*2,false);')
}
}
}
function ZamknutiyKonturVnutr(c, t, f) {
for (i = c.Count - 1; i > -1; i--) {
e = c[i]
te = ''
// начало
if (i == 0) {
if (!(e.ElType == 3)) {
lx = e.Pos2.x
ly = e.Pos2.y
// t.push('Shape.moveTo( '+ e.Pos1.x +', '+ e.Pos1.y +' );')
t.push(f + '.moveTo(' + e.Pos2.x + ',' + e.Pos2.y + ');')
}
}
// ------начало
if (e.ElType == 1) {
t.push(f + '.lineTo(' + Math.round(e.Pos1.x) + ',' + Math.round(e.Pos1.y) + ');')
lx = e.Pos1.x
ly = e.Pos1.y
} else if (e.ElType == 2) {
a1 = e.Pos1Angle()
if (e.ArcDir) {
a2 = (parseFloat(e.Pos1Angle()) + parseFloat(e.ArcAngle())).toString()
} else {
a2 = (parseFloat(e.Pos1Angle()) - parseFloat(e.ArcAngle())).toString()
}
t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',false);')
//t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',true);')
cx = e.Center.x - lx
cy = e.Center.y - ly
lx = e.Pos2.x
ly = e.Pos2.y
} else if (e.ElType == 3) {
t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.CirRadius + ',0,Math.PI*2,false);')
}
}
}
function KonturTrajectorii22(c, t, f) {
t.push('ppp=[];')
for (i = 0; i < c.Count; i++) {
e = c[i]
if (e.ElType == 1) {
// t.push(f + '.lineTo(' + Math.round(e.Pos2.x) + ',' + Math.round(e.Pos2.y) + ');')
// t.push('var el=new THREE.LineCurve(new THREE.Vector3(' + e.Pos1.x + ',' + e.Pos1.y + ',0),new THREE.Vector3(' + e.Pos2.x + ',' + e.Pos2.y + ',0));')
//t.push('ppp.push(new THREE.Vector3(' + e.Pos1.x + ',' + e.Pos1.y + ',0),new THREE.Vector3(' + e.Pos2.x + ',' + e.Pos2.y + ',0));')
} else if (e.ElType == 2) {
a1 = e.Pos1Angle()
if (e.ArcDir) {
a2 = (parseFloat(e.Pos1Angle()) + parseFloat(e.ArcAngle())).toString()
} else {
a2 = (parseFloat(e.Pos1Angle()) - parseFloat(e.ArcAngle())).toString()
}
// t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',false);')
PP = e.ArcCenter()
// t.push('var el=new THREE.QuadraticBezierCurve3(new THREE.Vector3('+e.Pos1.x+','+e.Pos1.y+',0),new THREE.Vector3('+PP.x+','+PP.y+',0),new THREE.Vector3('+e.Pos2.x+','+e.Pos2.y+',0));')
t.push('var el=new THREE.EllipseCurve( ' + e.Center.x + ',' + e.Center.y + ',' + e.ArcRadius() + ',' + e.ArcRadius() + ',' + a2 + ',' + a1 + ',false,0);')
t.push('points=el.getPoints();')
// t.push('var el=new THREE.SplineCurve3(points);')
t.push('ppp=ppp.concat(points);')
} else if (e.ElType == 3) {
//t.push(f + '.absarc(' + e.Center.x + ',' + e.Center.y + ',' + e.CirRadius + ',0,Math.PI*2,false);')
t.push('var el=new THREE.QuadraticBezierCurve3(new THREE.Vector3(-10,0,0),new THREE.Vector3(20,15,0),new THREE.Vector3(10,0,0));')
}
//t.push(f + '.add(el);')
}
t.push('var ' + f + '=new THREE.CatmullRomCurve3(ppp);')
//path.type = 'catmullrom';
// path.closed = true;
}
function KonturTrajectorii(c, t, f) {
ZamknutiyKontur(c, t, f)
t.push('po=path.getPoints();')
t.push('po1=[];')
t.push('for(i=0;i<po.length;i++){po1.push(new THREE.Vector3(po[i].x,po[i].y,0));}')
t.push('var ' + f + '=new THREE.CatmullRomCurve3(po1);')
if (c.IsClosedContour()) {
t.push('' + f + '.closed = true;')
}
}
/// ----------------------------------ВСПОМОГАТЕЛЬНАЯ ЧАСТЬ
function Povorot(obj) {
Rot = obj.Rotation;
q1 = Rot.ImagPart.x;
q2 = Rot.ImagPart.y;
q3 = Rot.ImagPart.z;
q4 = Rot.RealPart;
yyy = 2 * (q1 * q3 - q4 * q2)
if (yyy > 1) {
yyy = 1
}
//alert(q1+'\n'+q2+'\n'+q3+'\n'+q4+'\n'+Math.asin(1))
Angles = {
x: Math.atan2(2 * (q1 * q2 + q3 * q4), 1 - 2 * (q2 * q2 + q3 * q3)),
y: Math.asin(yyy),
z: Math.atan2(2 * (q1 * q4 + q2 * q3), 1 - 2 * (q3 * q3 + q4 * q4))
}
// system.log(JSON.stringify(Angles));
return Angles
}
function FindClosedContours(contour) {
// создаем копию исходного контура панели
var contourCopy = NewContour();
contourCopy.Addition(contour);
var result = [];
while (true) {
closedContour = NewContour();
// выделяем замкнутые контуры и добавляем их в результирующий массив
if (contourCopy.FindContour(closedContour, true))
result.push(closedContour)
else
break;
}
return result;
}
function GetNarVnutrContours(con) {
//var panel = GetPanel("Укажите панель");
//var contours = FindClosedContours(panel.Contour);
var contours = FindClosedContours(con);
var messages = ['Найдено ' + contours.length + ' контуров'];
for (var k = 0; k < contours.length; k++)
messages.push('Длина контура ' + k + ' = ' + contours[k].ObjLength());
//alert(messages.join('\r\n'));
vnutr = 0
avnu = []
naruj = 0
anar = []
cnar = []
var messages = ['Найдено ' + contours.length + ' контуров'];
for (var k = 0; k < contours.length; k++) {
vnutr2 = false
for (var k2 = 0; k2 < contours.length; k2++) {
if (k == k2) {
continue
}
if (contours[k].IsInContour(contours[k2])) {
vnutr2 = true
break
}
}
if (vnutr2) {
vnutr = vnutr + 1
avnu.push(k)
} else {
naruj = naruj + 1
anar.push(k)
cnar.push(contours[k])
}
// messages.push('Длина контура ' + k + ' = ' + contours[k].ObjLength());
}
messages.push('Наружных ' + ' = ' + naruj + ' \r\n' + anar.join('\r\n'))
messages.push('Внутренних ' + ' = ' + vnutr + ' \r\n' + avnu.join('\r\n'))
//alert(messages.join('\r\n'));
panleli_c = []
for (var inar = 0; inar < anar.length; inar++) {
pan = {}
pan.naruj = cnar[inar]
vnutr = []
//panlel_c.push(cnar[inar])
for (var i = 0; i < contours.length; i++) {
if (!(geometry.Compare(contours[i][0], cnar[inar][0]))) {
if (contours[i].IsInContour(cnar[inar])) {
vnutr.push(contours[i])
}
}
}
pan.vnutr = vnutr
panleli_c.push(pan)
}
return panleli_c
}
function NaLatinskom(s) {
s = s.replace(new RegExp("й", 'g'), "j");
s = s.replace(new RegExp("ц", 'g'), "c");
s = s.replace(new RegExp("у", 'g'), "u");
s = s.replace(new RegExp("к", 'g'), "k");
s = s.replace(new RegExp("е", 'g'), "e");
s = s.replace(new RegExp("н", 'g'), "n");
s = s.replace(new RegExp("г", 'g'), "g");
s = s.replace(new RegExp("ш", 'g'), "sh");
s = s.replace(new RegExp("щ", 'g'), "sch");
s = s.replace(new RegExp("з", 'g'), "z");
s = s.replace(new RegExp("х", 'g'), "h");
s = s.replace(new RegExp("ъ", 'g'), "#");
s = s.replace(new RegExp("ф", 'g'), "f");
s = s.replace(new RegExp("ы", 'g'), "y");
s = s.replace(new RegExp("в", 'g'), "v");
s = s.replace(new RegExp("а", 'g'), "a");
s = s.replace(new RegExp("п", 'g'), "p");
s = s.replace(new RegExp("р", 'g'), "r");
s = s.replace(new RegExp("о", 'g'), "o");
s = s.replace(new RegExp("л", 'g'), "l");
s = s.replace(new RegExp("д", 'g'), "d");
s = s.replace(new RegExp("ж", 'g'), "zh");
s = s.replace(new RegExp("э", 'g'), "je");
s = s.replace(new RegExp("я", 'g'), "ja");
s = s.replace(new RegExp("ч", 'g'), "ch");
s = s.replace(new RegExp("с", 'g'), "s");
s = s.replace(new RegExp("м", 'g'), "m");
s = s.replace(new RegExp("и", 'g'), "i");
s = s.replace(new RegExp("т", 'g'), "t");
s = s.replace(new RegExp("ь", 'g'), "'");
s = s.replace(new RegExp("б", 'g'), "b");
s = s.replace(new RegExp("ю", 'g'), "ju");
s = s.replace(new RegExp("ё", 'g'), "jo");
s = s.replace(new RegExp("Й", 'g'), "J");
s = s.replace(new RegExp("Ц", 'g'), "C");
s = s.replace(new RegExp("У", 'g'), "U");
s = s.replace(new RegExp("К", 'g'), "K");
s = s.replace(new RegExp("Е", 'g'), "E");
s = s.replace(new RegExp("Н", 'g'), "N");
s = s.replace(new RegExp("Г", 'g'), "G");
s = s.replace(new RegExp("Ш", 'g'), "SH");
s = s.replace(new RegExp("Щ", 'g'), "SCH");
s = s.replace(new RegExp("З", 'g'), "Z");
s = s.replace(new RegExp("Х", 'g'), "H");
s = s.replace(new RegExp("Ъ", 'g'), "#");
s = s.replace(new RegExp("Ф", 'g'), "F");
s = s.replace(new RegExp("Ы", 'g'), "Y");
s = s.replace(new RegExp("В", 'g'), "V");
s = s.replace(new RegExp("А", 'g'), "A");
s = s.replace(new RegExp("П", 'g'), "P");
s = s.replace(new RegExp("Р", 'g'), "R");
s = s.replace(new RegExp("О", 'g'), "O");
s = s.replace(new RegExp("Л", 'g'), "L");
s = s.replace(new RegExp("Д", 'g'), "D");
s = s.replace(new RegExp("Ж", 'g'), "ZH");
s = s.replace(new RegExp("Э", 'g'), "JE");
s = s.replace(new RegExp("Я", 'g'), "JA");
s = s.replace(new RegExp("Ч", 'g'), "CH");
s = s.replace(new RegExp("С", 'g'), "S");
s = s.replace(new RegExp("М", 'g'), "M");
s = s.replace(new RegExp("И", 'g'), "I");
s = s.replace(new RegExp("Т", 'g'), "T");
s = s.replace(new RegExp("Ь", 'g'), "'");
s = s.replace(new RegExp("Б", 'g'), "B");
s = s.replace(new RegExp("Ю", 'g'), "JU");
s = s.replace(new RegExp("Ё", 'g'), "JO");
s = s.replace(new RegExp("/", 'g'), "_");
s = s.replace(new RegExp("'", 'g'), "_");
s = s.replace(new RegExp('"', 'g'), "_");
s = s.replace(new RegExp("\r", 'g'), "_");
s = s.replace(new RegExp(",", 'g'), "_");
s = s.replace(new RegExp("№", 'g'), "N_");
return s
}
function GetPanelType(Panel) {
// куда смотрит пласть панели?
var AZ = Panel.NToGlobal(AxisZ);
var ax = Math.abs(AZ.x);
var ay = Math.abs(AZ.y);
var az = Math.abs(AZ.z);
var ptype = '';
if ((az > ax) && (az > ay)) {
ptype = 'Front'
} else if (ax > ay) {
ptype = 'Vert'
} else
ptype = 'Horiz';
return ptype;
}
function MatrixAxisX(Radians) {
return new Array(new Array(1, 0, 0, 0),
new Array(0, Math.cos(Radians), Math.sin(Radians), 0),
new Array(0, -Math.sin(Radians), Math.cos(Radians), 0),
new Array(0, 0, 0, 1));
};
function MatrixAxisY(Radians) {
return new Array(new Array(Math.cos(Radians), 0, -Math.sin(Radians), 0),
new Array(0, 1, 0, 0),
new Array(Math.sin(Radians), 0, Math.cos(Radians), 0),
new Array(0, 0, 0, 1));
};
function MatrixAxisZ(Radians) {
return new Array(new Array(Math.cos(Radians), Math.sin(Radians), 0, 0),
new Array(-Math.sin(Radians), Math.cos(Radians), 0, 0),
new Array(0, 0, 1, 0),
new Array(0, 0, 0, 1));
};
function MultiplyMatrix(A, B) {
var Result = new Array(new Array(),
new Array(),
new Array(),
new Array());
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 4; j++) {
Result[i][j] = 0;
for (var k = 0; k < 4; k++) {
Result[i][j] = Result[i][j] + A[i][k] * B[k][j];
};
};
};
return Result;
};
function GetTransformMatrix(Angles, Position) {
with(Angles) {
Result = MultiplyMatrix(MultiplyMatrix(MatrixAxisX(x), MatrixAxisY(y)), MatrixAxisZ(z));
};
with(Position) {
Result[0][3] = x;
Result[1][3] = y;
Result[2][3] = z;
};
return Result;
};
function GetObjectAngles(Object) {
with(Object.Rotation) {
q1 = ImagPart.x;
q2 = ImagPart.y;
q3 = ImagPart.z;
q4 = RealPart;
};
return NewVector(Math.atan2(2 * (q1 * q2 + q3 * q4), 1 - 2 * (q2 * q2 + q3 * q3)),
Math.asin(2 * (q1 * q3 - q4 * q2)),
Math.atan2(2 * (q1 * q4 + q2 * q3), 1 - 2 * (q3 * q3 + q4 * q4)));
};
function GetRGBColor(color) {
LONG = color
rgb = {}
rgb.B = LONG / 65536
rgb.G = (LONG - rgb.B * 65536) / 256
rgb.R = LONG - rgb.B * 65536 - rgb.G * 256
return rgb;
}
function decimalColorToHTMLcolor(number) {
//converts to a integer
var intnumber = number - 0;
// isolate the colors - really not necessary
var red, green, blue;
// needed since toString does not zero fill on left
// var template = "#000000";
var template = "0x000000";
// in the MS Windows world RGB colors
// are 0xBBGGRR because of the way Intel chips store bytes
red = (intnumber & 0x0000ff) << 16;
green = intnumber & 0x00ff00;
blue = (intnumber & 0xff0000) >>> 16;
// mask out each color and reverse the order
intnumber = red | green | blue;
// toString converts a number to a hexstring
var HTMLcolor = intnumber.toString(16);
//template adds # for standard HTML #RRGGBB
// HTMLcolor = template.substring(0,7 - HTMLcolor.length) + HTMLcolor;
HTMLcolor = template.substring(0, 8 - HTMLcolor.length) + HTMLcolor;
return HTMLcolor;
}
function TochkiDugi(elc, p, tochki) {
// system.log(elc + " -- " + g)
dlina = elc.ObjLength()
w11 = elc.ArcAngle() / kc.Value * elc.ArcRadius()
ww = 2 * elc.ArcRadius() * Math.sin((elc.ArcAngle() / kc.Value) / 2)
// system.log("угол " + elc.ArcAngle() + " -- длина " + elc.ObjLength() + " -- радиус " + elc.ArcRadius() + " -- длина сегмента " + w11 + " -- Высота сегмента " + ww)
pos = elc.Pos1
con = p.Contour
tochki.push(pos)
for (ii = 0; ii < kc.Value; ii++) {
nc = NewContour()
cir = nc.AddCircle(pos.x, pos.y, ww)
peresArray = geometry.Intersect(elc, cir)
system.log("пересечений " + peresArray.length)
for (pi = 0; pi < peresArray.length; pi++)
{
if (!yestiTochkaVMassive(peresArray[pi], tochki))
{
tochki.push(peresArray[pi])
pos = peresArray[pi]
}
}
}
// tochki.splice(tochki.length-1, tochki.length-1)
system.log("точек " + tochki.length)
}
function Distance(p1, p2) {
var dx = p2.x - p1.x;
var dy = p2.y - p1.y;
var dz = 0;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
function Distance3d(p1, p2) {
var dx = p2.x - p1.x;
var dy = p2.y - p1.y;
var dz = p2.z - p1.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
[свернуть]