Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Chia Xin Lin
    @chiaxin

    C++ How to read line from a file

    We need ifstream from <fstream>
    And use getline function to get lines.
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char * argv[])
    {
        if ( argc > 1 )
        {
            ifstream fh;
            fh.open(argv[1]);
            if (fh.is_open())
            {
                while (std::getline(fh, buffer)
                {
                    std::cout << buffer << std::endl;
                }
                fh.close();
            }
            else
            {
                cout << "Failed to open file :  << argc[1] << endl;
            }
        }
    }
    Chia Xin Lin
    @chiaxin

    C++ ifstream How to put a char back to buffer

    char c_buffer;
    std::ifstream handle;
    handle.get(c_buffer); // Get a char and move one char.
    handle.putback(c_buffer); // Put c_buffer back into file handle buffer.
    Chia Xin Lin
    @chiaxin

    C++ STD Regex

    #include <regex>
    #include <string>
    #include <iostream>
    
    int main(int argc, char * argv[])
    {
        using namespace std;
        string target("This is book");
        regex reg(R"(This is (\\w+))");
        smatch smat;
        if (regex_match(target, smat, reg)) {
            for (int i = 0 ; i < smat.size() ; i++) {
                cout << smat[i] << endl;
            }
        } else {
            cout << "No match !" << endl;
        }
        return 0;
    }
    Chia Xin Lin
    @chiaxin
    Use CMake to build Maya C++ API Project on Windows and Mac
    Chia Xin Lin
    @chiaxin

    How to send "command" to Maya from external


    Open command port in Maya

    import maya.cmds as mc
    
    mc.commandPort(n=':54321')

    External Python Script

    import socket
    
    HOST = '127.0.0.1'
    PORT = 54321
    
    ADDR = (HOST, PORT)
    
    def send_command():
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.connect(ADDR)
        command = 'polyCube()'
        message = command
        client.send(message)
        data = client.recv(1024)
        client.close()
        print('Result : %s' % (data))
    
    if __name__ == '__main__':
        send_command()
    Chia Xin Lin
    @chiaxin

    JavaScript隱式型態轉換的問題

    var a = '1';
    var b = 2;
    var c = a + b;
    alert(c);
    // The "c" will get "12", not 3!

    Solution

    var a = '1'
    var b = 2;
    
    // Add a plug before "a"
    var c = +a + b;
    alert(c);
    // The "c" will get 3!
    Chia Xin Lin
    @chiaxin

    JavaScript 的陣列宣告與 Python 很像

    var array = ['a', 'b', 'c', 100, 200, 'd'];
    for (var idx = 0 ; idx < array.length ; idx++) {
        alert(array[idx]);
    }
    Chia Xin Lin
    @chiaxin

    JavaScript 的陣列加入元素可以自動擴充

    var array = ['a', 'b', 'c'];
    array(array.length) = 'd';
    // Now array have a, b, c and d
    array.push('e');
    // Use "push" method could be append a element after
    array[array.length + 1] = 'f';
    // It will auto insert "undefined" type element
    // Now we have a, b, c, d, e, undefined and f

    JaveScript 陣列插入前端使用 unshift

    var array = ['b', 'c', 'd'];
    array.unshift('a');
    // array have a, b, c, d
    Chia Xin Lin
    @chiaxin

    JavaScript 查詢陣列大小使用 array.length 屬性

    var array = ['a', 'b', 'c'];
    alert(array.length);
    // Get 3

    JavaScript 移除前端與後端使用 pop() 與 shift()

    var array = ['a', 'b', 'c', 'd'];
    array.pop(); // a, b, c
    array.shift(); // b, c
    Chia Xin Lin
    @chiaxin

    JaveScript 比較運算子擁有嚴格相等比較運算子 ===

    if ('2' === 2) {
        alert("The string 2 is number 2!");
    } else {
        alert("The string 2 is not number 2!");
    }
    Chia Xin Lin
    @chiaxin

    jQuery 取得選擇器並操作物件

    function foo () {
        var logo_obj = $("#logo");
        logo_obj.replaceWith("<h1>Replaced Logo</h1>"); // Replace
        logo_obj.hide() // Hide the html id "logo"
        logo_obj.remove() // Remove it
    }
    Chia Xin Lin
    @chiaxin

    jQuery 可以動態加入 Class

    // <h1>aaaaaaa</h1>
    var logo_obj = $("#logo");
    logo_obj.addClass("be-red");
    // <h1 class="be-red">aaaaaaa</h1>
    Chia Xin Lin
    @chiaxin

    jQuery 改變 CSS 屬性 鏈結式以及實字式

    // 鏈結式
    $('#logo').css('color: red').css('background-color: blue');
    // 實字式
    $('#logo').css( {
        'color' : 'red',
        'background-color' : 'blue'
    } )
    // 實字式 採用傳入物件
    Chia Xin Lin
    @chiaxin

    jQuery 動態改變屬性

    $('#logo').attr('color', 'rgb(0, 0, 0)');
    // remove
    $('#logo').removeAttr('color');
    Chia Xin Lin
    @chiaxin

    jQuery 應用在所有選擇器找到的物件 並加上函數

    $('.someobject').each(function () { alert("I found it!") });
    Chia Xin Lin
    @chiaxin

    jQuery 如果想在 each 使用物件本身

    $('.someobject').each(function () { alert( $(this) ); } );
    Chia Xin Lin
    @chiaxin

    jQuery 事件觸發器

    $("#logo").click( function (event) { event.stopPropagation; } );
    // event.stopPropagation() 就像 Qt的 event.accept() 阻止事件傳播
    Chia Xin Lin
    @chiaxin

    jQuery 進階事件觸發器

    function when_click_it (event) {
        alert(event.data.message);
    }
    $("#somebody").on("click", { message: "Hello, World!" }, when_click_it);
    // 1. Event name, 2. 實字輸入, 3. 事件函式
    Chia Xin Lin
    @chiaxin
    @chiaxin 使用 "$(this)" 即是使用該物件本身
    Chia Xin Lin
    @chiaxin

    Log & Alert

    console.log("This is log"); // For debug information
    window.alert("Hello!"); // For display alert
    Chia Xin Lin
    @chiaxin

    jQuery

    Selector : If you want to get <a> and "href" is prefix with "http://"

    $('a[href="http://"]').each( function () { // do something ... } );

    $('') -> Use single quote because we need quote inside (double quote)

    $('a[href^="http://"]')

    If you want to control itself, remind call "$(this)" instead of "this"

    jQuery

    Stop Propagation 停止事件傳播

    $("#theLink").click( function (event) {
        event.stopPropagation();
    });
    Chia Xin Lin
    @chiaxin

    jQuery filter method

    $().filter could be filter out CSS condition
    such as '[alt="pic"]', it will filter any not have alt=pic*
    function setup () {
        $("img").filter('alt*="pic"').addClass("opaque");
    }
    Chia Xin Lin
    @chiaxin

    How to use VIM in Mac XCode?

    Try to resign xcode and install XVim2
    git clone https://github.com/XVimProject/XVim2.git
    git clone https://github.com/slegetank/ResignXcode.git
    cd ResignXcode
    python3 ResignXcode.py
    cd ../XVim2
    make
    Chia Xin Lin
    @chiaxin

    How to restore a file status if not yet commit?

    This can be restore README.md, if it not yet add new status into git.
    git checkout README.md
    Nero
    @SZNero
    怎么样 用vs c++ 去调用 Qt的界面呢,作为 插件的操作界面
    Chia Xin Lin
    @chiaxin
    不需要編譯 QT for Maya 就可以用 vs 寫了
    Nero
    @SZNero
    @chiaxin thank you
    Nero
    @SZNero
    你好! c++ std::thread 可以在maya 里正常使用吗 因为 我在使用线程去设置 currentTime 时总是 maya 崩溃 是否需要 用 mutex 加锁控制就行了?
    Chia Xin Lin
    @chiaxin
    Hi,您好 我對thread沒有研究。。您若是有什麼新發現也歡迎告訴我,也許以後會遇到需要多線程
    wuming1461
    @wuming1461
    @chiaxin 你好,看了你的視頻學了很多東西,但是出現了一些問題想請教你

    // Error: file: C:/Program Files/Autodesk/Maya2019/scripts/others/pluginWin.mel line 935: RuntimeError: file C:/Users/wumin/PycharmProjects/helloWorldPy/DoubleMultipleNode.py line 34: (kInvalidParameter): Object is incompatible with this method //
    // Warning: file: C:/Program Files/Autodesk/Maya2019/scripts/others/pluginWin.mel line 935: Failed to call script creator function //

    我34行是這樣寫的
    node.addAttribute(node.output)

    沒關係,我找到問題了
    Chia Xin Lin
    @chiaxin
    HI
    @wuming1461 Hi 歡迎 有任何問題都可以討論
    wuming1461
    @wuming1461
    @chiaxin 因為課業的關係,想用Maya API做關於cloth simulation的東西,可以請教一下如何開始呢?我知道cloth sim現在有很多不同的計算方法,但是我不知道我要怎樣寫成Maya的plugin,需要什麼樣的class~
    Chia Xin Lin
    @chiaxin
    @wuming1461 我沒有寫過sim的plugin這部分比較不了解~
    wuming1461
    @wuming1461
    没关系,我再找找看有什么reference~ 谢谢😁😁
    wandth
    @wandth
    物料模拟我觉得大概类似于物体的deformer,我觉得你可以从meshDeformer入手,重载deform函数,
    wuming1461
    @wuming1461
    你好,請問有人用過Atom編輯器嗎?
    Chia Xin Lin
    @chiaxin
    嗨 我沒用過Atom 耶 目前都是用pychamer vscode 還有vim
    wuming1461
    @wuming1461
    謝謝~ 我也是發現vscode更好用,extension也很強大
    以前是用sublime,但是要付費
    Chia Xin Lin
    @chiaxin
    PyChamer可以設定module path 就可以抓到class 與 function name
    滿方便的
    wuming1461
    @wuming1461
    好的,謝謝~ 我過後會試試看