ホーム » 3D (ページ 2)

3D」カテゴリーアーカイブ

2024年3月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,427 アクセス



GLUT インストール

ちょっと時間が空いたので,Linux 環境で GLUT を使える様にしてみた.
以前からお世話になっている次の所に詳しく書かれている.
GLUTによる「手抜き」OpenGL入門


Ubuntu , Debian ,Raspberry Pi では
  $ sudo apt install freeglut3 freeglut3-dev
Fedora では
  $ sudo yum install freeglut
  $ sudo yum install freeglut-devel


コンパイルは
  $ cc hello_gl.c -lglut -lGLU -lGL
GLUT を使用したサンプルのコンパイルと実行
https://jml.mish.work/index.php/cpp/install-glut.html


2019/08/17 本屋に寄ったらあったので購入.


opengl.jp
The OpenGL Utility Toolkit (GLUT) Programming Interface API Version 3 日本語翻訳版


2021/05 Win10 に GLUT インストール


https://itl.mish.work/Iwao/Doc/algo/to_thick/glut.htm

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Win10 で 3mf の読込み

https://itl.mydns.jp/i_Tools/Doc/blog/data_3mf/duck.html
Win10 での duck.3mf の表示

バージョン 読込 保存
Print 3D  3.3.7910.0 stl obj 3mf wrl ply
ペイント 3D 5.1904.8017.0 3mf stl ply obj glb fbx 3mf glb fbx
3D ビューアー 6.1903.4012.0 3mf fbx obj stl ply gltf glb glb
3D Builder  16.1.1431.0 stl obj 3mf wrl ply gltf glb 3mf stl obj ply gltf glb

duck.3mf は Print 3D と 3D Builder ではうまく読めない.
Print 3D 読み込めませんでした 0x8000FFFF
ペイント 3D で読んだ duck.3mf を Paint_3D_duck.3mf としてそのまま保存.
その状態であればどれでもちゃんと開ける.


もっと単純なデータで確認.Cube_org.3mf
幾つかの面のテクスチャが貼られていない.
Print 3D でテクスチャがうまく貼られていない
ペイント 3D は大丈夫.
ペイント 3D でのテクスチャ
テクスチャ座標を 0 ~ 1 の範囲にしたものでは大丈夫.
0 ~ 2 や -2 ~ 2 にしたものは,Print 3D では 0 ~ 1 のみうまく貼りつく.Cute_tx2.3mf
Print 3D では 0 ~ 1 の範囲のみ
//mish.work/…/i_Tools/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

3DS 保存でアプリケーションエラー

次の様な 3DS 形式で保存するコード.
データ部分が空の時,アプリケーションエラー.
3DS 保存でアプリケーションエラー

bool	save_3DS	(FILE* ofp,const tDS_Chunk& chnk)
{
	if (ofp == NULL)		{	return	false ;		}
	{
		u_16	id  = chnk.GetID() ;
		u_32	len = chnk.GetLen() ;
		v_u__8	data= chnk.GetData() ;
		::fwrite(&id,		1,		sizeof(u_16),	ofp) ;
		::fwrite(&len,		1,		sizeof(u_32),	ofp) ;
		::fwrite(&data[0],	data.size(),	sizeof(u__8),	ofp) ;
		}
	for (size_t index=0 ; index<size_t(chnk.GetChildCount()) ; index++) {
		tDS_Chunk	child = chnk.GetChild(long(index)) ;
		bool	result = ::save_3DS(ofp,child) ;
		if (!result)		{	return	false ;		}
		}
	return	true ;
	}

::fwrite(&data[0], data.size(),sizeof(u__8), ofp) ; がうまくない.
次の様な感じでコードを修正.

if (data.size() > 0) {	::fwrite(&data[0],	data.size(),	sizeof(u__8),	ofp) ;	}

VC 6 や VC 14 では,たまたまだと思うがエラーにならなかった.


VC 14 デバッグ版では,アサートされることを確認.
サイズ 0 の vector の fwrite VC 14 デバッグ版でアサート

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux で 32 ビット色の BMP に変換

3D データの相互変換を書き直していて,32 ビット DIB が必要になってきた.
Windows 環境では,自前の Image クラスがあるのでそれを利用している.
Linux 環境は,先日見つけた convert コマンドが使えそうと思って調べるとなかなか情報が少ない.
次の -depth 32 で行けそうと思うが,24 ビットのまま.
convert dib_24.png -depth 32 dib_32.bmp
それで検索して見つけたのが,Convert to 32-bit depth BMP
次の様に存在しないアルファの情報を指定(-alpha set)する必要があるみたい.
convert dib_24.png -depth 32 -alpha set dib_32.bmp

ImageMagick

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

xml の読込み

幾つかの xml データを読んでみると,データにより msxml.dll を使用したときに比べて明らかに遅い.

bool Test (LPCTSTR pathName)
{
    tstring outPath = ::Get_i_Tools_tmp_date() ;
    tstring now_hms = ::Now_Format(_T("_%M%S")) ;
    tstring out_xml = ::Path_AddLastSP(outPath) + ::Path_GetName(pathName) + now_hms + _T(".o.xml") ;
    tstring new_xml = ::Path_AddLastSP(outPath) + ::Path_GetName(pathName) + now_hms + _T(".n.xml") ;
    {
        ElapseTime eto ;
        Xml_E xml = ::Xml_Import(pathName) ;
        std::cerr << eto.GetElapse() << std::endl ;
        Xml_Out::Export(xml,out_xml.c_str()) ;
        }
    {
        ElapseTime etn ;
        Xml_E xml = ::Load_xml_2018_12(pathName) ;
        std::cerr << etn.GetElapse() << std::endl ;
        Xml_Out::Export(xml,new_xml.c_str()) ;
        }
    return true ;
    }

データは次の様な x3d で,5 倍くらいかかる.

Parse_xml で時間がかかる x3d
Parse_xml で時間がかかる x3d

x3d の場合は,属性の値が長い.
そのため次のコード部分( q_str+=cq )がうまくない.

tstring Parse_xml_quot (c_tstring& str,const TCHAR qm,size_t* index)
{
    tstring q_str ;
    if (*index < str.length()) {
        TCHAR c = str[*index] ;
        if (c == qm) {
            q_str += c ;
            for (size_t indexQ=*index+1 ; indexQ<str.size() ; indexQ++) {
                TCHAR cq = str[indexQ] ;
                q_str += cq ;
                if (cq == qm) {
                    *index = indexQ ;
                    break ;
                    }
                }
            }
        }
    return q_str ;
    }

https://jml.mish.work/index.php/cpp/xml.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

three.js で表示できない

ipl を WebGL で表示できる形式に変換しても,表示できないデータができてしまった.

本当は次の様に表示されなければならない.


vt と vn がない時にうまくない.
f 1// 2// 3// の様になってしまっていて,これをうまく処理してくれない.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

STL(Stereolithography) 読込みで…

STL(Stereolithography,Standard Triangulated Language) バイナリ読込みで,VC 14 でビルドした exe でダウンする.
VC 6 でビルドしたものは通っているが,たまたまエラーにならなかっただけ.
コードは,

    {
        size_t  hStart = 0 ;
        v_char  head ;
        head.resize(STL_B_HEADER_SIZE+100,0x00) ;
        memmove(&head,&readBuf[hStart],sizeof(STL_B_HEADER_SIZE)) ;
        stl.SetName(::To_tstring(head).c_str()) ;
        }

::To_tstring で head を利用した時にエラーとなる.
ここをコメントにすると,ブロックを抜けた時に head の解放?でエラーになる.


memmove で &head ではなく &head[0] としなければならない.

正しくは,

    {
        size_t	hStart = 0 ;
        v_char	head ;
        head.resize(STL_B_HEADER_SIZE+100,0x00) ;
        memmove(&head[0],&readBuf[hStart],STL_B_HEADER_SIZE) ;
        stl.SetName(::To_tstring(head).c_str()) ;
        }

v_char は次の様に定義.
 typedef std::vector<char> v_char ;

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

3D ファイルの表示で黒?

個人的な形式の ipl .直接読込んで OpenGL で表示する様にコードを修正中…
表示すると黒くなる.
3D データの表示で黒くなる
STL などはそれなりの色で表示される.
ワイヤフレームなどでは,色で表示されている.
原因は,ipl では法線ベクトルを持っていないので 0,0,0 として表示されていた.
法線ベクトルを正しく設定しているので面の色で表示される


2021/12/27
GonsA GonsA_CalcNormal (const GonsA& gnsa_,…)

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

#define での括弧 …

STL バイナリのサイズをチェックする所でうまく判断できず,気が付くまで少し時間がかかったのでメモ.
   u_64 dataSize = STL_B_H_COUNT_SIZE + faceCount * STL_B_FACE_1_SIZE ;
   if (dataSize == fileSize) { return true ; }
STL_B_FACE_1_SIZE が 4*3*4+2 となっていて,84 + faceCount * 48 + 2 になってしまっていた.
括弧で括って 84 + faceCount * 50 で OK .
#define     STL_B_FACE_1_SIZE       (4*3*4+2)

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

球が作成できない

背景画像のアップロードで,球を生成してそれに貼り付ける.
コード自体はそれほど難しくないので,1 日位でできると思ってた.
Windows のコンソール AP で,次の様なコードを書いてテスト.
MakeBG.cpp
make_bg.hxx


#include "MessBar.hxx"
#include "i_Trace.hxx"
#include "gonsprm2.hxx"
#include "Htm_thrj.hxx"

//*******************************************************************************
// make bg files imo and html
// Create : 2018/04/19
//*******************************************************************************
inline bool MakeBG (c_tstring& dibPath)
{
    tstring ext = ::Path_GetExtLow(dibPath) ;
    if      (ext == _T("bmp")) { ;              }
    else if (ext == _T("jpg")) { ;              }
    else if (ext == _T("png")) { ;              }
    else                       { return false ; }
    {
        tstring imoPath = ::Path_ChangeExt(dibPath,_T(".imo")) ;
        tstring htmName = ::Path_ChangeExt(dibPath,_T(".html")) ;
        tstring dmpName = ::Path_ChangeExt(dibPath,_T(".ipl")) ;
        {
            long div = 90/5 ;
            v_Vd3A pntsAry = ::BuildSphere(div) ;
            {
                std::tout << pntsAry.size() << std::endl ;
                if (pntsAry.size() > 0) {
                    Vd3A pnts = pntsAry[0] ;
                    std::tout << pnts.size() << std::endl ;
                    }
                tstring str = ::v_V3_To_tstring(pntsAry,_T(",")) ;
                {
                    std::tout << str << std::endl ;
                    }
                ::SaveText(dmpName.c_str(),str) ;
                }
            v_Vd2A  txuvAry = ::SetTextureUV(pntsAry) ;
                    pntsAry = ::V3_Scale (pntsAry,Vd3(20.)) ;
            Gons1   gons1 = ::Gons_BuildFace(pntsAry,txuvAry,dibPath.c_str()) ;
            GonsA   ga ;
                    ga.push_back(gons1) ;
            Ed3     es = ::GonsA_GetExtent(ga) ;
            {
                std::tout << imoPath << _T("\t") ;
                std::tout << ::V3_To_tstring(es.Volume()) << std::endl ;
                }
            if (es.Volume() != Vd3(0)) {
                es = Ed3(es.L*0.01,es.G*0.01) ;
                ::GonsA_ToOBJ(ga,imoPath.c_str()) ;
                ::HT_Make_three_js_html(imoPath.c_str(),es) ;
                }
            }
        }
    return true ;
    }

//*******************************************************************************
// Make BG
// Create : 2018/04/19
//*******************************************************************************
int _tmain (int argc,TCHAR* argv[])
{
    _tsetlocale(LC_ALL,_T("")) ;
    {
        double s = sin(rad(30)) ;
        double c = cos(rad(30)) ;
        std::tout << ::To_tstring(rad(30)) << _T("\t") << ::To_tstring(s) << _T("\t") << ::To_tstring(c) << std::endl ;
        }
    if (argc > 1) {
        v_tstring argAry ;
        for (int index=1 ; index<argc ; index++) {
            tstring av = argv[index] ;
            ::MakeBG(av) ;
            }
        }
    else {
        tstring buf ;
        buf.resize(1000) ;
        {
            while (std::terr << _T("dib ? =") , std::tin.getline(&buf[0],buf.size()))
            {
                tstring str = buf.c_str() ;
                if      (str == _T("q"))   { break ; }
                else if (str == _T("Q"))   { break ; }
                str = ::QuotM_Del_All(str) ;
                if (str.empty())           { continue ; }
                if (::File_IsNothing(str)) { continue ; }
                tstring dib_file = str ;
                ::MakeBG(dib_file) ;
                }
            }
        }
    return 0 ;
    }

#include "MessBar.cxx"

今度は,DS116 でビルドして実行すると,

Iwao@DS116:/var/.../Test/up_bg/data$ ./a.out
0.523599        98314745853377985068733249901357667205561433229409406145971019710277043155206326909160297391588106447153156445277590513896008090831662627743743127151181611161993303763348552511914898438567008016612049817143085994563143448055356356529593034366351316506187159487365573007925410016860727208738652774465536.000000  98321247861193438769252981549279948821735544950351014769381393881588573259178110828643912278175146924986161470094082713103803921735703931192359519739047155548857037547932930737608178537416409042994283830606984599100883034181136178714087912736395732787698542049681305006129736011480288874859116047106048.000000
dib ? =

本当は,

C:\Users\Iwao\...\i_Tools.tmp>\\DevXP\C_Drive\Temp\DS11x\MakeBG\Release.060\MakeBG.exe
0.523599        0.500000        0.866025
dib ? =

cmath が使えない様で,検索すると「-lm でコンパイルが通る」と言うのは見つかる.
が,コンパイルの問題ではなく,実行でうまくない.


当然ではあるが,DS115j でも同様.
試しに,opkg update と opkg install gcc .
root@DS116:/var/…/Iwao# opkg update
Downloading http://pkg.entware.net/binaries/armv7/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/packages
root@DS116:/var/…/Iwao# opkg install gcc
Upgrading gcc on root from 6.3.0-1 to 6.3.0-1a…
Downloading http://pkg.entware.net/binaries/armv7/gcc_6.3.0-1a_armv7soft.ipk
Configuring gcc.
root@DS116:/var/…/Iwao#
もう一度,ビルドして実行すると,
Iwao@DS116:/var/…/Test/up_bg/data$ g++ MakeBG.cpp
Iwao@DS116:/var/…/Test/up_bg/data$ ./a.out
0.523599 0.500000 0.866025
dib ? =
予想以上に時間がかかってしまったが,何とか…
daikoku_edit.html


2019/02/13 リンクなどを修正

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Cardboard と WebGL

Cardboard で撮った画像を,WebGL の背景として利用してみた.

もう少しうまく貼れればと思うが,方法がわからない.
球に貼っているため縦方向に引き伸ばされてしまう.


以下,画像は 横:縦 = 2:1 に編集している.
このすぐ下は,SceneJS を使用したもの.


2018/04/27 画像をアップロードできるページ
360度パノラマ画像の表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

B-Spline

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

B-Spline ノットベクトル

v_double	BS_make_knot	(const Vd4A& pnts,const size_t order)
{
	v_double	knot ;
	size_t		degree = order - 1 ;
	{
		for (size_t index0=0 ; index0< degree ; index0++) {
			knot.push_back(0) ;
			}
		for (size_t index_=0 ; index_< pnts.size()-degree ; index_++) {
			knot.push_back(index_) ;
			}
		for (size_t indexL=0 ; indexL< degree+1 ; indexL++) {
			knot.push_back(pnts.size()-degree) ;
			}
		}
	return	knot ;
	}

「制御点 8 個,次数(degree) 2」で求まったノットは,
    0   0   0   1   2   3   4   5   6   6   6         

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

B-Spline basis

3D グラフィックスのための数学入門 157 ページをコードに.
コードは,kodatuno を参考にさせてもらった.

double BS_basis (const double t,c_v_double& knot,const long order,const long i) { if (order <= 0) { return 0. ; } if (order == 1) { // Ni,0(t) if (t == knot[knot.size()-1]) { if (knot[i]<=t && t<=knot[i+1]) { return 1. ; } else { return 0. ; } } else { if (knot[i]<=t && t< knot[i+1]) { return 1. ; } else { return 0. ; } } } else { double n1 = 0 ; // (*/0) --> n = 0 double n2 = 0 ; double d1 = knot[i+order-1] - knot[i ] ; // T(i+k) -T(i) double d2 = knot[i+order-0] - knot[i+1] ; // T(i+k+1)-T(i+1) if (!::V1_is_near<double<(d1,0)) { n1 = t - knot[i] ; // t - T(i) n1 = n1 * BS_basis(t,knot,order-1,i ) ; // N(i, k-1)(t) n1 = n1 / d1 ; } if (!::V1_is_near<double<(d2,0)) { n2 = knot[i+order-0] - t ; // T(i+k+1)-t n2 = n2 * BS_basis(t,knot,order-1,i+1) ; // N(i+1,k-1)(t) n2 = n2 / d2 ; } return (n1 + n2) ; } return -1. ; }
double BS_basis (const double t,const long order,const long i) { if (order <= 0) { return 0. ; } if (order == 1) { // Ni,0(t) if (i<=t && t< i+1) { return 1. ; } else { return 0. ; } } else { double n1 = 0 ; double n2 = 0 ; double d1 = order - 1 ; // k double d2 = order - 1 ; // k if (!::V1_is_near<double<(d1,0)) { n1 = t - i ; // t-i n1 = n1 * BS_basis(t,order-1,i ) ; // N(i ,k-1) n1 = n1 / d1 ; } if (!::V1_is_near<double<(d2,0)) { n2 = (i+order-0) - t ; // i+k+1 - t n2 = n2 * BS_basis(t,order-1,i+1) ; // N(i+1,k-1) n2 = n2 / d2 ; } return (n1 + n2) ; } return -1. ; }
long pt_count = 7 ; v_vd_n.resize(pt_count) ; for (size_t index=0 ; index<10 ; index++) { for (size_t index_d=0 ; index_d<div_c ; index_d++) { double t = double(index*div_c + index_d)/div_c ; for (size_t i=0 ; i<pt_count ; i++) { double r = ::BS_basis(t,order,i) ; Vd3A v3a = v_vd_n[i] ; Vd3 v(v3a.size(),r*100,0) ; v3a.push_back(v) ; v_vd_n[i] = v3a ; } } }


Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Rational B-Spline

Vd4 として w に設定してみたが,これで良いのか?

Vd3A	b_spline	(const Vd4& q0,const Vd4& q1,const Vd4& q2,const Vd4& q3,const long div_c)
{
	Vd3A	vd3a ;
	for (long index=0 ; index<=div_c ; index++) {
		double	t  = 1./div_c*index ;
		double	n0 = 1./6 * (1.-t)*(1.-t)*(1.-t) ;
		double	n1 = 1./2 * t*t*t - t*t + 2./3 ;
		double	n2 =-1./2 * t*t*t + 1./2 * t*t + 1./2 *t + 1./6 ;
		double	n3 = 1./6 * t*t*t ;
		double	px = ( (n0*q0.x)*q0.w + (n1*q1.x)*q1.w + (n2*q2.x)*q2.w + (n3*q3.x)*q3.w ) / ((n0)*q0.w + (n1)*q1.w + (n2)*q2.w + (n3)*q3.w) ;
		double	py = ( (n0*q0.y)*q0.w + (n1*q1.y)*q1.w + (n2*q2.y)*q2.w + (n3*q3.y)*q3.w ) / ((n0)*q0.w + (n1)*q1.w + (n2)*q2.w + (n3)*q3.w) ;
		double	pz = ( (n0*q0.z)*q0.w + (n1*q1.z)*q1.w + (n2*q2.z)*q2.w + (n3*q3.z)*q3.w ) / ((n0)*q0.w + (n1)*q1.w + (n2)*q2.w + (n3)*q3.w) ;
		vd3a.push_back(Vd3(px,py,pz)) ;
		}
	return	vd3a ;
	}

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

スプライン

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

XP 環境で OpenGL での表示が…

WinXP 環境で OpenGL での表示が変になっている.

スムージングを無効にしていると正しく表示される.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

IGES ファイル

どこまで対応可能か不明だが,IGES の仕様書を読んで自分用にまとめている途中…
https://mish.myds.me/Iwao/Doc/spec/3d/iges/iges.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

3D Builder 0x80510018

データにより,3D Builder の読込で 0x80510018 エラーに.

以前の 3mf 出力では,テクスチャファイル名を数字と ‘_’ にしていたが,
 先日他の 3D 形式の関係で,7 bit の文字の範囲に変更した.
どうもこれがいけなかったみたいで,
 3mf で出力する時は,newName.Format(_T(“Tex_%03d.png”),tIndex+1) に修正.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

threejs requestAnimationFrame

使い方が間違ってた?


  function three_start() {
    init() ;
    loop() ;
    }
  function loop() {
    controls.update();
    renderer.clear();
    renderer.render( scene, camera );
    requestAnimationFrame( loop );
    }


正しくは loader / babylon
  function init() {
    // …
    animate() ;
    // …
    }
  function animate() {
    requestAnimationFrame( animate );
    render();
    }
  function render() {
    controls.update();
    renderer.render( scene, camera );
    }
この方法でも,環境により CPU リソースが食われる.


一先ずここまで
本当は,完全にロードが終わったタイミングが取れれば良いのだが…

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.